1331 lines
25 KiB
Plaintext
1331 lines
25 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 Class Library
|
|
// --------------------------------------
|
|
// Name: XPOI
|
|
// Description: Bar Analysing ...
|
|
//
|
|
// Maintainer:
|
|
// ------------
|
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
//
|
|
//////////////////////////////////////////////////////
|
|
//
|
|
// Global Properties ...
|
|
#property library
|
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
#property link "https://www.saherelm.ir"
|
|
#property version "1.00"
|
|
#property strict
|
|
|
|
//
|
|
// Imports ...
|
|
#include "../Classes/x-saherelm.base.class.mq5"
|
|
#include "../Libraries/x-saherelm.x-poi.lib.mq5"
|
|
|
|
//
|
|
// Definitions ...
|
|
|
|
//
|
|
// Implementations ...
|
|
class XCBarAnalyser : public XCBase
|
|
{
|
|
//
|
|
public:
|
|
//
|
|
|
|
//
|
|
// Constructor(s) ...
|
|
void XCBarAnalyser()
|
|
{
|
|
}
|
|
|
|
//
|
|
// Deconstructor ...
|
|
void ~XCBarAnalyser()
|
|
{
|
|
}
|
|
|
|
//
|
|
// Getter(s) / Setter(s) ...
|
|
|
|
//
|
|
// Providers ...
|
|
|
|
//
|
|
// Actions ...
|
|
|
|
/**
|
|
* Calculate Loopback Data for Specific Bar ...
|
|
*
|
|
* @param index: Integer, Bar Current Index ...
|
|
* @param start: Integer, Start of Loopback ...
|
|
* @param end: Integer, End of Loopback ...
|
|
* @param count: Integer, Number of Calculating Bars ...
|
|
* @param bar: XOHCL instance, Specified Bar ...
|
|
* @param loopback: Integer, Loopback Length ...
|
|
* @return ( bool )
|
|
*/
|
|
bool CalculateLoopBackData(
|
|
int &index,
|
|
int &start,
|
|
int &end,
|
|
int &count,
|
|
XOHCL &bar,
|
|
int loopback = 1 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (loopback < 1)
|
|
{
|
|
loopback = 1;
|
|
}
|
|
|
|
//
|
|
index = -1;
|
|
start = -1;
|
|
end = -1;
|
|
count = -1;
|
|
|
|
//
|
|
result = bar.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
index = bar.Index();
|
|
start = index + 1;
|
|
end = start + loopback;
|
|
count = end - start;
|
|
result = count >= 1;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Retrieve Loopback HH & LL Data ...
|
|
*
|
|
* @param hhIDX: Integer, HH Index ...
|
|
* @param hh: Double, HH Value ...
|
|
* @param llIDX: Integer, LL Index ...
|
|
* @param ll: Double, LL Value ...
|
|
* @param bar: XOHCL instance ...
|
|
* @param loopback: Integer, Loopback Length ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool CalculateLoopbackHLData(
|
|
int &hhIDX,
|
|
double &hh,
|
|
int &llIDX,
|
|
double &ll,
|
|
XOHCL &bar,
|
|
int loopback //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (loopback < 1)
|
|
{
|
|
loopback = 1;
|
|
}
|
|
|
|
//
|
|
int index = -1;
|
|
int start = -1;
|
|
int end = -1;
|
|
int count = -1;
|
|
result = CalculateLoopBackData(
|
|
index,
|
|
start,
|
|
end,
|
|
count,
|
|
bar,
|
|
loopback //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
hhIDX = iHighest(
|
|
bar.symbol,
|
|
bar.period,
|
|
MODE_HIGH,
|
|
count,
|
|
start //
|
|
);
|
|
result = IsValidIndex(hhIDX);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
llIDX = iLowest(
|
|
bar.symbol,
|
|
bar.period,
|
|
MODE_LOW,
|
|
count,
|
|
start //
|
|
);
|
|
result = IsValidIndex(llIDX);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
hh = iHigh(
|
|
bar.symbol,
|
|
bar.period,
|
|
hhIDX //
|
|
);
|
|
ll = iLow(
|
|
bar.symbol,
|
|
bar.period,
|
|
llIDX //
|
|
);
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Calculate Bar Range ...
|
|
*
|
|
* @param bar: XOHCL instance ...
|
|
*
|
|
* @return ( double )
|
|
*/
|
|
double GetBarRangePercent(XOHCL &bar)
|
|
{
|
|
//
|
|
double result = 0;
|
|
|
|
//
|
|
result = bar.GetRange() / 100;
|
|
|
|
//
|
|
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 ...
|
|
*
|
|
* @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 ...
|
|
|
|
/**
|
|
* Check Specified Bar's Range is Extended or not ...
|
|
*
|
|
* @param bar: XOHCL instance, Specified Bar ...
|
|
* @param loopback: Integer, Loopback Length ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool HasExtendedRange(
|
|
XOHCL &bar,
|
|
int loopback = 3 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (loopback < 3)
|
|
{
|
|
loopback = 3;
|
|
}
|
|
|
|
//
|
|
result = bar.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int index = bar.Index();
|
|
int start = index + 1;
|
|
int end = start + loopback;
|
|
int count = end - start;
|
|
result = count >= 1;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double sum = 0;
|
|
XOHCL iBar = bar;
|
|
for (int i = start; i < end; i++)
|
|
{
|
|
//
|
|
bool isRetrieved = iBar.GetPreviousBar(iBar);
|
|
if (!isRetrieved)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
sum += iBar.GetRange();
|
|
}
|
|
|
|
//
|
|
result = sum > 0;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double avg = sum / count;
|
|
|
|
//
|
|
result = bar.GetRange() >= avg;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Check Specified Bar's Body is Extended or not ...
|
|
*
|
|
* @param bar: XOHCL instance, Specified Bar ...
|
|
* @param loopback: Integer, Loopback Length ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool HasExtendedBody(
|
|
XOHCL &bar,
|
|
int loopback = 3 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (loopback < 3)
|
|
{
|
|
loopback = 3;
|
|
}
|
|
|
|
//
|
|
result = bar.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int index = bar.Index();
|
|
int start = index + 1;
|
|
int end = start + loopback;
|
|
int count = end - start;
|
|
result = count >= 1;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double sum = 0;
|
|
XOHCL iBar = bar;
|
|
for (int i = start; i < end; i++)
|
|
{
|
|
//
|
|
bool isRetrieved = iBar.GetPreviousBar(iBar);
|
|
if (!isRetrieved)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
//
|
|
sum += iBar.GetBody();
|
|
}
|
|
|
|
//
|
|
result = sum > 0;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
double avg = sum / count;
|
|
|
|
//
|
|
result = bar.GetBody() >= avg;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Check Specified Bar's Body and Range is Extended or not ...
|
|
*
|
|
* @param bar: XOHCL instance, Specified Bar ...
|
|
* @param loopback: Integer, Loopback Length ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool IsExtended(
|
|
XOHCL &bar,
|
|
int loopback = 3 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
bool hasExtendedBody = HasExtendedBody(bar, loopback);
|
|
bool hasExtendedRange = HasExtendedRange(bar, loopback);
|
|
result = hasExtendedBody &&
|
|
hasExtendedRange;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Check Specified Bar is Swing High or not ...
|
|
*
|
|
* @param bar: XOHCL instnce ...
|
|
* @param range: Integer, Specified Range ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool IsSwingHigh(
|
|
XOHCL &bar,
|
|
int range = 2 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (range < 1)
|
|
{
|
|
range = 1;
|
|
}
|
|
|
|
//
|
|
result = bar.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int index = bar.Index();
|
|
result = range > 0 &&
|
|
index >= range;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
string symbol = bar.symbol;
|
|
ENUM_TIMEFRAMES period = bar.period;
|
|
|
|
//
|
|
for (int i = 1; i <= range; i++)
|
|
{
|
|
//
|
|
// Prev Bar ...
|
|
XOHCL iPrevBar;
|
|
result = iPrevBar.Init(
|
|
symbol,
|
|
period,
|
|
index + i //
|
|
);
|
|
if (!result)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
// Next Bar ...
|
|
XOHCL iNextBar;
|
|
result = iNextBar.Init(
|
|
symbol,
|
|
period,
|
|
index - i //
|
|
);
|
|
if (!result)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
result = bar.high >= iPrevBar.high &&
|
|
bar.high >= iNextBar.high;
|
|
if (!result)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Check Specified Bar is Swing Low or not ...
|
|
*
|
|
* @param bar: XOHCL instnce ...
|
|
* @param range: Integer, Specified Range ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool IsSwingLow(
|
|
XOHCL &bar,
|
|
int range = 2 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (range < 1)
|
|
{
|
|
range = 1;
|
|
}
|
|
|
|
//
|
|
result = bar.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int index = bar.Index();
|
|
result = range > 0 &&
|
|
index >= range;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
string symbol = bar.symbol;
|
|
ENUM_TIMEFRAMES period = bar.period;
|
|
|
|
//
|
|
for (int i = 1; i <= range; i++)
|
|
{
|
|
//
|
|
// Prev Bar ...
|
|
XOHCL iPrevBar;
|
|
result = iPrevBar.Init(
|
|
symbol,
|
|
period,
|
|
index + i //
|
|
);
|
|
if (!result)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
// Next Bar ...
|
|
XOHCL iNextBar;
|
|
result = iNextBar.Init(
|
|
symbol,
|
|
period,
|
|
index - i //
|
|
);
|
|
if (!result)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
result = bar.low <= iPrevBar.low &&
|
|
bar.low <= iNextBar.low;
|
|
if (!result)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Check a Bar is Momentum Bar or not ...
|
|
*
|
|
* @param bar: XOHCL instance ...
|
|
* @param dir: ENUM_X_DIRECTION member ...
|
|
* @param extend: Integer ...
|
|
* @param bodyPercent: Double ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool IsMomentumBar(
|
|
XOHCL &bar,
|
|
ENUM_X_DIRECTION &dir,
|
|
int extend = 1,
|
|
double bodyPercent = 70 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (extend < 0)
|
|
{
|
|
extend = 0;
|
|
}
|
|
|
|
//
|
|
if (bodyPercent < 50)
|
|
{
|
|
bodyPercent = 50;
|
|
}
|
|
|
|
//
|
|
dir = X_DIRECTION_NONE;
|
|
|
|
//
|
|
result = bar.IsValid() &&
|
|
bar.Index() > 0;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
if (extend > 0)
|
|
{
|
|
//
|
|
result = IsExtended(
|
|
bar,
|
|
extend //
|
|
);
|
|
|
|
//
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
}
|
|
|
|
//
|
|
double body = bar.GetBody();
|
|
double rp = GetBarRangePercent(bar);
|
|
|
|
//
|
|
result = body >= rp * bodyPercent;
|
|
|
|
//
|
|
if (result)
|
|
{
|
|
//
|
|
dir =
|
|
bar.IsBullish()
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Check a Bar is Rejection Bar or not ...
|
|
*
|
|
* @param bar: XOHCL instance ...
|
|
* @param dir: ENUM_X_DIRECTION member ...
|
|
* @param extend: Integer ...
|
|
* @param bodyPercent: Double ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool IsRejectionBar(
|
|
XOHCL &bar,
|
|
ENUM_X_DIRECTION &dir,
|
|
int extend = 1,
|
|
double shadowPercent = 60 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (extend < 0)
|
|
{
|
|
extend = 0;
|
|
}
|
|
|
|
//
|
|
if (shadowPercent < 50)
|
|
{
|
|
shadowPercent = 50;
|
|
}
|
|
|
|
//
|
|
dir = X_DIRECTION_NONE;
|
|
|
|
//
|
|
result = bar.IsValid() &&
|
|
bar.Index() > 0;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
if (extend > 0)
|
|
{
|
|
//
|
|
result = IsExtended(
|
|
bar,
|
|
extend //
|
|
);
|
|
|
|
//
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
}
|
|
|
|
//
|
|
double body = bar.GetBody();
|
|
double range = bar.GetRange();
|
|
double shadows = bar.GetShadows();
|
|
double lowShadow = bar.GetLowShadow();
|
|
double highShadow = bar.GetHighShadow();
|
|
double rp = GetBarRangePercent(bar);
|
|
|
|
//
|
|
result = shadows >= rp * shadowPercent;
|
|
|
|
//
|
|
if (result)
|
|
{
|
|
//
|
|
dir =
|
|
lowShadow > highShadow
|
|
? X_DIRECTION_BULLISH
|
|
: X_DIRECTION_BEARISH;
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
//
|
|
// Support and Resistance Zones ...
|
|
|
|
/**
|
|
* Check a Bar is Support Bar or not ...
|
|
*
|
|
* @param bar: XOHCL instance ...
|
|
* @param range: Integer, Specified Verifiation Range ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool IsSupport(
|
|
XOHCL &bar,
|
|
int range = 21 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (range < 2)
|
|
{
|
|
range = 2;
|
|
}
|
|
|
|
//
|
|
result = bar.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int index = bar.Index();
|
|
result = range > 0 &&
|
|
index >= range;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
string symbol = bar.symbol;
|
|
ENUM_TIMEFRAMES period = bar.period;
|
|
|
|
//
|
|
for (int i = 1; i <= range; i++)
|
|
{
|
|
//
|
|
int prevIDX = index + i;
|
|
int nextIDX = index - 1;
|
|
|
|
//
|
|
// Prev Bar ...
|
|
XOHCL iPrevBar;
|
|
result = iPrevBar.Init(
|
|
symbol,
|
|
period,
|
|
prevIDX //
|
|
);
|
|
if (!result)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
// Next Bar ...
|
|
XOHCL iNextBar;
|
|
result = iNextBar.Init(
|
|
symbol,
|
|
period,
|
|
nextIDX //
|
|
);
|
|
if (!result)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
result = bar.low <= iPrevBar.low &&
|
|
bar.low <= iNextBar.low;
|
|
if (!result)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Check a Bar is Resistance Bar or not ...
|
|
*
|
|
* @param bar: XOHCL instance ...
|
|
* @param range: Integer, Specified Verifiation Range ...
|
|
*
|
|
* @return ( bool )
|
|
*/
|
|
bool IsResistance(
|
|
XOHCL &bar,
|
|
int range = 21 //
|
|
)
|
|
{
|
|
//
|
|
bool result = false;
|
|
|
|
//
|
|
if (range < 2)
|
|
{
|
|
range = 2;
|
|
}
|
|
|
|
//
|
|
result = bar.IsValid();
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int index = bar.Index();
|
|
result = range > 0 &&
|
|
index >= range;
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
string symbol = bar.symbol;
|
|
ENUM_TIMEFRAMES period = bar.period;
|
|
|
|
//
|
|
for (int i = 1; i <= range; i++)
|
|
{
|
|
//
|
|
int prevIDX = index + i;
|
|
int nextIDX = index - 1;
|
|
|
|
//
|
|
// Prev Bar ...
|
|
XOHCL iPrevBar;
|
|
result = iPrevBar.Init(
|
|
symbol,
|
|
period,
|
|
prevIDX //
|
|
);
|
|
if (!result)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
// Next Bar ...
|
|
XOHCL iNextBar;
|
|
result = iNextBar.Init(
|
|
symbol,
|
|
period,
|
|
nextIDX //
|
|
);
|
|
if (!result)
|
|
{
|
|
break;
|
|
}
|
|
|
|
//
|
|
result = bar.high >= iPrevBar.high &&
|
|
bar.high >= iNextBar.high;
|
|
if (!result)
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
|
|
//
|
|
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 = 0;
|
|
result = HasSameBars(
|
|
bar,
|
|
dir,
|
|
index,
|
|
sameBars //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
int obIndex = index;
|
|
result = ob.Init(
|
|
bar.symbol,
|
|
bar.period,
|
|
obIndex //
|
|
);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
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;
|
|
}
|
|
|
|
//
|
|
protected:
|
|
//
|
|
|
|
//
|
|
private:
|
|
//
|
|
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
// Actions ...
|
|
|
|
//
|
|
};
|
|
|
|
// |