Complete Fair Value Gaps Detetion ...
This commit is contained in:
@@ -223,6 +223,141 @@ class XCBarAnalyser : public XCBase
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect Same Bars ...
|
||||
*
|
||||
* @param bar: XOHCL instance, Start Bar ...
|
||||
* @param dir: ENUM_X_DIRECTION member, Holds Result Direction ...
|
||||
* @param index: Integer, Holds Result Index ...
|
||||
* @param sameBars: Iteger, Required Same Bar ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool HasSameBars(
|
||||
XOHCL &bar,
|
||||
ENUM_X_DIRECTION &dir,
|
||||
int &index,
|
||||
int sameBars = 3 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
dir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
if (sameBars < 1)
|
||||
{
|
||||
sameBars = 1;
|
||||
}
|
||||
|
||||
//
|
||||
result = bar.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
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 hasBullishSameBars =
|
||||
sameBullishBarsFounded >= sameBars;
|
||||
|
||||
//
|
||||
bool hasBearishSameBars =
|
||||
sameBearishBarsFounded >= sameBars;
|
||||
|
||||
//
|
||||
result = hasBullishSameBars ||
|
||||
hasBearishSameBars;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
dir =
|
||||
hasBullishSameBars
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect Consolidation Range ...
|
||||
*
|
||||
@@ -1041,89 +1176,13 @@ class XCBarAnalyser : public XCBase
|
||||
}
|
||||
|
||||
//
|
||||
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;
|
||||
int index = 0;
|
||||
result = HasSameBars(
|
||||
bar,
|
||||
dir,
|
||||
index,
|
||||
sameBars //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
@@ -1142,10 +1201,111 @@ class XCBarAnalyser : public XCBase
|
||||
}
|
||||
|
||||
//
|
||||
dir =
|
||||
hasBullishOB
|
||||
? X_DIRECTION_BULLISH
|
||||
: X_DIRECTION_BEARISH;
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Fair Value Gaps ...
|
||||
|
||||
/**
|
||||
* Detect a Fair Value Gap Based on Given Bar ...
|
||||
*
|
||||
* @param bar: XOHCL instance, Specified Start Bar ...
|
||||
* @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 HasFairValueGap(
|
||||
XOHCL &bar,
|
||||
XOHCL &prevBar,
|
||||
XOHCL &nextBar,
|
||||
ENUM_X_DIRECTION &dir,
|
||||
int sameBars = 3 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
prevBar.Clean();
|
||||
nextBar.Clean();
|
||||
dir = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
if (sameBars < 1)
|
||||
{
|
||||
sameBars = 1;
|
||||
}
|
||||
|
||||
//
|
||||
result = bar.IsValid();
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int index = 0;
|
||||
result = HasSameBars(
|
||||
bar,
|
||||
dir,
|
||||
index,
|
||||
sameBars //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
bool isBullish = IsBullish(dir);
|
||||
|
||||
//
|
||||
int to = bar.Index() + 1;
|
||||
int from = index + 1;
|
||||
for (int i = from; i > to; i--)
|
||||
{
|
||||
//
|
||||
result = prevBar.Init(
|
||||
bar.symbol,
|
||||
bar.period,
|
||||
i //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
result = nextBar.Init(
|
||||
bar.symbol,
|
||||
bar.period,
|
||||
i - 2 //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
//
|
||||
result = isBullish
|
||||
? prevBar.high < nextBar.low
|
||||
: prevBar.low > nextBar.high;
|
||||
if (result)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (!result)
|
||||
{
|
||||
//
|
||||
prevBar.Clean();
|
||||
nextBar.Clean();
|
||||
dir = X_DIRECTION_NONE;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
|
||||
Reference in New Issue
Block a user