Finish Order Blocks Detection ...
This commit is contained in:
@@ -223,6 +223,97 @@ class XCBarAnalyser : public XCBase
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect Consolidation Range ...
|
||||
*
|
||||
* @param index: Integer, Start Bar Index ...
|
||||
* @param range: Integer, Range of Bars ...
|
||||
* @param maxRange: Consolidation Price Range in Points ...
|
||||
* @param symbol: String, Symbol ...
|
||||
* @param period: ENUM_TIMEFRAMES member, Period ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool IsConsolidating(
|
||||
int index,
|
||||
int range,
|
||||
double maxRange,
|
||||
string symbol = NULL,
|
||||
ENUM_TIMEFRAMES period = NULL //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
if (index < 0)
|
||||
{
|
||||
index = 0;
|
||||
}
|
||||
|
||||
//
|
||||
if (range < 1)
|
||||
{
|
||||
range = 1;
|
||||
}
|
||||
|
||||
//
|
||||
if (maxRange < 1)
|
||||
{
|
||||
maxRange = 1;
|
||||
}
|
||||
|
||||
//
|
||||
// Normalize ...
|
||||
symbol = NormalizeSymbol(symbol);
|
||||
period = NormalizePeriod(period);
|
||||
|
||||
//
|
||||
// Point Value ...
|
||||
double point = GetPoints(symbol);
|
||||
|
||||
//
|
||||
double high = iHigh(
|
||||
symbol,
|
||||
period,
|
||||
index //
|
||||
);
|
||||
double low = iLow(
|
||||
symbol,
|
||||
period,
|
||||
index //
|
||||
);
|
||||
|
||||
//
|
||||
// Detect Range High and Low ...
|
||||
for (int i = 1; i < range; i++)
|
||||
{
|
||||
//
|
||||
double iH = iHigh(
|
||||
symbol,
|
||||
period,
|
||||
index + i //
|
||||
);
|
||||
|
||||
//
|
||||
double iL = iLow(
|
||||
symbol,
|
||||
period,
|
||||
index + i //
|
||||
);
|
||||
|
||||
//
|
||||
high = MathMax(high, iH);
|
||||
low = MathMin(low, iL);
|
||||
}
|
||||
|
||||
//
|
||||
result = (high - low) <= (maxRange * point);
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Commons ...
|
||||
|
||||
@@ -909,6 +1000,157 @@ class XCBarAnalyser : public XCBase
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Order Blocks ...
|
||||
|
||||
/**
|
||||
* Detect an Order Block Based on Given Bar ...
|
||||
*
|
||||
* @param bar: XOHCL instance, Specified Start Bar ...
|
||||
* @param ob: XOHCL instance, Fill it if Order Block Found ...
|
||||
* @param dir: ENUM_X_DIRECTION member, Specified Founded Order Block Direction ...
|
||||
* @param sameBars: Integer, Specified Min Same Bars for Detecting Order Block ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HasOrderBlock(
|
||||
XOHCL &bar,
|
||||
XOHCL &ob,
|
||||
ENUM_X_DIRECTION &dir,
|
||||
int sameBars = 3 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
ob.Clean();
|
||||
dir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
if (sameBars < 1)
|
||||
{
|
||||
sameBars = 1;
|
||||
}
|
||||
|
||||
//
|
||||
result = bar.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int index = bar.Index();
|
||||
bool canContinue = true;
|
||||
int sameBullishBarsFounded = 0;
|
||||
int sameBearishBarsFounded = 0;
|
||||
bool canContinueForBullish = true;
|
||||
bool canContinueForBearish = true;
|
||||
while (canContinue)
|
||||
{
|
||||
//
|
||||
XOHCL iBar;
|
||||
result = iBar.Init(
|
||||
bar.symbol,
|
||||
bar.period,
|
||||
index //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
bool isBullish = iBar.IsBullish();
|
||||
bool isBearish = iBar.IsBearish();
|
||||
result = isBullish ||
|
||||
isBearish;
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
if (isBullish)
|
||||
{
|
||||
//
|
||||
sameBullishBarsFounded++;
|
||||
canContinueForBearish = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
sameBearishBarsFounded++;
|
||||
canContinueForBullish = false;
|
||||
}
|
||||
|
||||
//
|
||||
result = canContinueForBullish ||
|
||||
canContinueForBearish;
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
canContinueForBullish =
|
||||
canContinueForBullish &&
|
||||
sameBullishBarsFounded > 0;
|
||||
|
||||
//
|
||||
canContinueForBearish =
|
||||
canContinueForBearish &&
|
||||
sameBearishBarsFounded > 0;
|
||||
|
||||
//
|
||||
canContinue =
|
||||
canContinueForBullish ||
|
||||
canContinueForBearish;
|
||||
if (canContinue)
|
||||
{
|
||||
index++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
bool hasBullishOB =
|
||||
sameBullishBarsFounded >= sameBars;
|
||||
|
||||
//
|
||||
bool hasBearishOB =
|
||||
sameBearishBarsFounded >= sameBars;
|
||||
|
||||
//
|
||||
result = hasBullishOB ||
|
||||
hasBearishOB;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int obIndex = index;
|
||||
result = ob.Init(
|
||||
bar.symbol,
|
||||
bar.period,
|
||||
obIndex //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
dir =
|
||||
hasBullishOB
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
protected:
|
||||
//
|
||||
|
||||
Reference in New Issue
Block a user