Finish Order Blocks Detection ...
This commit is contained in:
@@ -377,6 +377,36 @@ class XCPOIDetector : public XCBaseAlert
|
||||
mSupplyAndDemandRange = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Order Blocks ...
|
||||
|
||||
/**
|
||||
* Get Order Blocks Detection Bars ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int OrderBlocksSameBars()
|
||||
{
|
||||
return mOrderBlocksSameBars;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Order Blocks Detection Bars ...
|
||||
*
|
||||
* @param value: Argument 1
|
||||
*/
|
||||
void OrderBlocksSameBars(int value)
|
||||
{
|
||||
//
|
||||
if (value < 0)
|
||||
{
|
||||
value = 0;
|
||||
}
|
||||
|
||||
//
|
||||
mOrderBlocksSameBars = value;
|
||||
}
|
||||
|
||||
//
|
||||
// Actions ...
|
||||
|
||||
@@ -768,6 +798,68 @@ class XCPOIDetector : public XCBaseAlert
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Order Blocks ...
|
||||
int obSameBars = OrderBlocksSameBars();
|
||||
if (obSameBars > 0)
|
||||
{
|
||||
//
|
||||
// Bullish Order Block ...
|
||||
isDetected = DetectBullishOrderBlock(cBar);
|
||||
if (isDetected)
|
||||
{
|
||||
//
|
||||
ENUM_XPOI_EVENTS event = X_BULLISH_ORDERBLOCK_DETECTED;
|
||||
XCOrderBlock *param;
|
||||
bool hasItem = GetLastItem(
|
||||
param,
|
||||
mBullishOrderBlocks //
|
||||
);
|
||||
if (hasItem)
|
||||
{
|
||||
//
|
||||
NotifyEventListeners(
|
||||
event,
|
||||
param //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
Add(
|
||||
event,
|
||||
state //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
// Bearish Order Block ...
|
||||
isDetected = DetectBearishOrderBlock(cBar);
|
||||
if (isDetected)
|
||||
{
|
||||
//
|
||||
ENUM_XPOI_EVENTS event = X_BEARISH_ORDERBLOCK_DETECTED;
|
||||
XCOrderBlock *param;
|
||||
bool hasItem = GetLastItem(
|
||||
param,
|
||||
mBearishOrderBlocks //
|
||||
);
|
||||
if (hasItem)
|
||||
{
|
||||
//
|
||||
NotifyEventListeners(
|
||||
event,
|
||||
param //
|
||||
);
|
||||
}
|
||||
|
||||
//
|
||||
Add(
|
||||
event,
|
||||
state //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
ValidatePOIs(cBar);
|
||||
|
||||
@@ -863,6 +955,10 @@ class XCPOIDetector : public XCBaseAlert
|
||||
//
|
||||
Clean(mSupplyZones);
|
||||
Clean(mDemandZones);
|
||||
|
||||
//
|
||||
Clean(mBullishOrderBlocks);
|
||||
Clean(mBearishOrderBlocks);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -911,6 +1007,9 @@ class XCPOIDetector : public XCBaseAlert
|
||||
|
||||
//
|
||||
SupplyAndDemandRange(144);
|
||||
|
||||
//
|
||||
OrderBlocksSameBars(3);
|
||||
}
|
||||
|
||||
//
|
||||
@@ -983,6 +1082,10 @@ class XCPOIDetector : public XCBaseAlert
|
||||
int supplyZonesCount = 0;
|
||||
int demandZonesCount = 0;
|
||||
|
||||
//
|
||||
int bullishOrderBlocksCount = 0;
|
||||
int bearishOrderBlocksCount = 0;
|
||||
|
||||
//
|
||||
bool canContinue = true;
|
||||
|
||||
@@ -1067,6 +1170,28 @@ class XCPOIDetector : public XCBaseAlert
|
||||
ArrayReverse(mDemandZones);
|
||||
}
|
||||
|
||||
//
|
||||
// Oder Blocks ...
|
||||
int obSameBars = OrderBlocksSameBars();
|
||||
if (obSameBars > 0)
|
||||
{
|
||||
//
|
||||
// Bullish Order Blocks ...
|
||||
bullishOrderBlocksCount = DetectRequiredBullishOrderBlocks(barIndex);
|
||||
if (bullishOrderBlocksCount == requiredPOIs)
|
||||
{
|
||||
ArrayReverse(mBullishOrderBlocks);
|
||||
}
|
||||
|
||||
//
|
||||
// Bearish Order Blocks ...
|
||||
bearishOrderBlocksCount = DetectRequiredBearishOrderBlocks(barIndex);
|
||||
if (bearishOrderBlocksCount == requiredPOIs)
|
||||
{
|
||||
ArrayReverse(mBearishOrderBlocks);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
canContinue =
|
||||
//
|
||||
@@ -1118,6 +1243,16 @@ class XCPOIDetector : public XCBaseAlert
|
||||
// Demand Zones ...
|
||||
demandZonesCount < requiredPOIs
|
||||
//
|
||||
||
|
||||
//
|
||||
// Bullish Order Blocks ...
|
||||
bullishOrderBlocksCount < requiredPOIs
|
||||
//
|
||||
||
|
||||
//
|
||||
// Bearish Order Blocks ...
|
||||
bearishOrderBlocksCount < requiredPOIs
|
||||
//
|
||||
;
|
||||
if (canContinue)
|
||||
{
|
||||
@@ -2986,12 +3121,321 @@ class XCPOIDetector : public XCBaseAlert
|
||||
|
||||
//
|
||||
// Order Blocks ...
|
||||
int mOrderBlocksSameBars; // Order Blocks Detection Bars ...
|
||||
|
||||
//
|
||||
// Bullish OB ...
|
||||
XCOrderBlock *mBullishOrderBlocks[];
|
||||
|
||||
/**
|
||||
* Detect Bullish Order Block ...
|
||||
*
|
||||
* @param bar: XOHCL instance ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool DetectBullishOrderBlock(XOHCL &bar)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = bar.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int sameBars = OrderBlocksSameBars();
|
||||
if (sameBars < 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL obBar;
|
||||
ENUM_X_DIRECTION dir;
|
||||
result = mBarAnalyser
|
||||
.HasOrderBlock(
|
||||
bar,
|
||||
obBar,
|
||||
dir,
|
||||
sameBars //
|
||||
);
|
||||
result =
|
||||
result &&
|
||||
dir == X_DIRECTION_BULLISH;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
XCOrderBlock *ob;
|
||||
ob = new XCOrderBlock();
|
||||
result = ob.Init(
|
||||
obBar,
|
||||
dir //
|
||||
);
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
datetime cTime = TimeCurrent();
|
||||
ob.To(cTime);
|
||||
|
||||
//
|
||||
Add(
|
||||
ob,
|
||||
mBullishOrderBlocks //
|
||||
);
|
||||
|
||||
// //
|
||||
// XCBullishOrderBlockObject *iObj;
|
||||
// bool isCreated = mDrawer.CreateBullishOrderBlock(
|
||||
// ob,
|
||||
// iObj //
|
||||
// );
|
||||
// if (isCreated)
|
||||
// {
|
||||
// AddObjectIfNotExists(iObj);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect Required Bullish Order Blocks ...
|
||||
*
|
||||
* @param barIndex: Integer Start bar index ...
|
||||
* 0 is Default ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int DetectRequiredBullishOrderBlocks(int barIndex)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
int required = MaxNumberOfRequiredPOIs();
|
||||
if (required <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int count = ArraySize(mBullishOrderBlocks);
|
||||
if (count >= required)
|
||||
{
|
||||
//
|
||||
result = count;
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int sameBars = OrderBlocksSameBars();
|
||||
if (sameBars < 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string symbol = GetSymbol();
|
||||
ENUM_TIMEFRAMES period = GetPeriod();
|
||||
|
||||
//
|
||||
XOHCL bar;
|
||||
bool isInited = bar.Init(
|
||||
symbol,
|
||||
period,
|
||||
barIndex //
|
||||
);
|
||||
if (!isInited)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
DetectBullishOrderBlock(bar);
|
||||
|
||||
//
|
||||
result = ArraySize(mBullishOrderBlocks);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Bearish OB ...
|
||||
XCOrderBlock *mBearishOrderBlocks[];
|
||||
|
||||
/**
|
||||
* Detect Bearish Order Block ...
|
||||
*
|
||||
* @param bar: XOHCL instance ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool DetectBearishOrderBlock(XOHCL &bar)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
result = bar.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int sameBars = OrderBlocksSameBars();
|
||||
if (sameBars < 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
XOHCL obBar;
|
||||
ENUM_X_DIRECTION dir;
|
||||
result = mBarAnalyser
|
||||
.HasOrderBlock(
|
||||
bar,
|
||||
obBar,
|
||||
dir,
|
||||
sameBars //
|
||||
);
|
||||
result =
|
||||
result &&
|
||||
dir == X_DIRECTION_BEARISH;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
XCOrderBlock *ob;
|
||||
ob = new XCOrderBlock();
|
||||
result = ob.Init(
|
||||
obBar,
|
||||
dir //
|
||||
);
|
||||
|
||||
//
|
||||
if (result)
|
||||
{
|
||||
//
|
||||
datetime cTime = TimeCurrent();
|
||||
ob.To(cTime);
|
||||
|
||||
//
|
||||
Add(
|
||||
ob,
|
||||
mBearishOrderBlocks //
|
||||
);
|
||||
|
||||
// //
|
||||
// XCBearishOrderBlockObject *iObj;
|
||||
// bool isCreated = mDrawer.CreateBearishOrderBlock(
|
||||
// ob,
|
||||
// iObj //
|
||||
// );
|
||||
// if (isCreated)
|
||||
// {
|
||||
// AddObjectIfNotExists(iObj);
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect Required Bearish Order Blocks ...
|
||||
*
|
||||
* @param barIndex: Integer Start bar index ...
|
||||
* 0 is Default ...
|
||||
*
|
||||
* @return ( int )
|
||||
*/
|
||||
int DetectRequiredBearishOrderBlocks(int barIndex)
|
||||
{
|
||||
//
|
||||
int result = 0;
|
||||
|
||||
//
|
||||
if (barIndex < 0)
|
||||
{
|
||||
barIndex = 0;
|
||||
}
|
||||
|
||||
//
|
||||
int required = MaxNumberOfRequiredPOIs();
|
||||
if (required <= 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int count = ArraySize(mBearishOrderBlocks);
|
||||
if (count >= required)
|
||||
{
|
||||
//
|
||||
result = count;
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int sameBars = OrderBlocksSameBars();
|
||||
if (sameBars < 0)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string symbol = GetSymbol();
|
||||
ENUM_TIMEFRAMES period = GetPeriod();
|
||||
|
||||
//
|
||||
XOHCL bar;
|
||||
bool isInited = bar.Init(
|
||||
symbol,
|
||||
period,
|
||||
barIndex //
|
||||
);
|
||||
if (!isInited)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
DetectBearishOrderBlock(bar);
|
||||
|
||||
//
|
||||
result = ArraySize(mBearishOrderBlocks);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Fair Value Gaps ...
|
||||
|
||||
Reference in New Issue
Block a user