Last ...
This commit is contained in:
@@ -743,6 +743,315 @@ class XC121SMCCycleHelper : public XCBase
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Detect XPV Based POI(s) ...
|
||||
*
|
||||
* @param barIndex: Start Bar Index ...
|
||||
* @param minRepetition: minimum Repeate of POI for Validation ...
|
||||
* @param requiredPivots: Number of Min Requirement POI(s) ...
|
||||
* @param pivotHelper: XC121SMCCycleHelper instance Pointer ...
|
||||
* @param orderFlow: XPVPivot instance Array Reference ...
|
||||
* @param orderFlowDirection: ENUM_X_DIRECTION member Reference which represents OrderFlow Direction ...
|
||||
* @param maxAllowedLoopbackBars: Integer, Max Allowed Loopback Bars ...
|
||||
*
|
||||
* @return ( bool )
|
||||
*/
|
||||
bool DetectOrderFlow(
|
||||
int barIndex,
|
||||
XPVPivot &orderFlow[], // OrderFlows ...
|
||||
ENUM_X_DIRECTION &orderFlowDirection, // Order Flow Direction ...
|
||||
int minRepetition = 0,
|
||||
int requiredPivots = 0,
|
||||
int maxAllowedLoopbackBars = 576 //
|
||||
)
|
||||
{
|
||||
//
|
||||
bool result = false;
|
||||
|
||||
//
|
||||
orderFlowDirection = X_DIRECTION_NONE;
|
||||
|
||||
//
|
||||
if (maxAllowedLoopbackBars <= 0)
|
||||
{
|
||||
maxAllowedLoopbackBars = 1000;
|
||||
}
|
||||
|
||||
//
|
||||
if (minRepetition <= 0)
|
||||
{
|
||||
minRepetition = mX121Helper.GetDonChainLength();
|
||||
}
|
||||
|
||||
//
|
||||
if (requiredPivots <= 0)
|
||||
{
|
||||
requiredPivots = 3;
|
||||
}
|
||||
|
||||
//
|
||||
int start = barIndex;
|
||||
int end = start + maxAllowedLoopbackBars;
|
||||
|
||||
//
|
||||
Clean(orderFlow);
|
||||
|
||||
//
|
||||
result = minRepetition > 0 &&
|
||||
requiredPivots > 0;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
string symbol = GetSymbol();
|
||||
ENUM_TIMEFRAMES period = GetPeriod();
|
||||
|
||||
//
|
||||
double peak = 0;
|
||||
XPVPivot peaks[];
|
||||
int peakRepeate = 0;
|
||||
int peakToBarIndex = 0;
|
||||
int peakFromBarIndex = 0;
|
||||
|
||||
//
|
||||
double vale = 0;
|
||||
XPVPivot vales[];
|
||||
int valeRepeate = 0;
|
||||
int valeToBarIndex = 0;
|
||||
int valeFromBarIndex = 0;
|
||||
|
||||
//
|
||||
bool canLookupPeak = true;
|
||||
bool canLookupVale = true;
|
||||
bool canLookup = true;
|
||||
while (canLookup)
|
||||
{
|
||||
//
|
||||
// Check Peak ...
|
||||
double iPeak = mX121Helper.GetPeak(barIndex);
|
||||
if (iPeak != peak)
|
||||
{
|
||||
//
|
||||
if (peak != 0 &&
|
||||
peakRepeate >= minRepetition)
|
||||
{
|
||||
//
|
||||
bool isExists = false;
|
||||
int count = ArraySize(peaks);
|
||||
if (IsValidSize(count))
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XPVPivot iPivot = peaks[i];
|
||||
|
||||
//
|
||||
if (iPivot.upper == iPeak)
|
||||
{
|
||||
//
|
||||
isExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isExists)
|
||||
{
|
||||
//
|
||||
XPVPivot iPivot;
|
||||
|
||||
//
|
||||
iPivot.lower = 0;
|
||||
iPivot.upper = peak;
|
||||
iPivot.symbol = symbol;
|
||||
iPivot.period = period;
|
||||
iPivot.type = XPV_PEAK;
|
||||
iPivot.repetition = peakRepeate;
|
||||
iPivot.to = iTime(
|
||||
symbol,
|
||||
period,
|
||||
peakToBarIndex //
|
||||
);
|
||||
iPivot.from = iTime(
|
||||
symbol,
|
||||
period,
|
||||
peakFromBarIndex //
|
||||
);
|
||||
|
||||
//
|
||||
iPivot.lower = iPivot.CalculateLower();
|
||||
|
||||
//
|
||||
bool isValid = iPivot.IsValid();
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
iPivot,
|
||||
peaks //
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
peak = iPeak;
|
||||
peakRepeate = 0;
|
||||
peakFromBarIndex = 0;
|
||||
peakToBarIndex = barIndex;
|
||||
}
|
||||
else if (iPeak == peak)
|
||||
{
|
||||
//
|
||||
peakRepeate++;
|
||||
peakFromBarIndex = barIndex;
|
||||
}
|
||||
|
||||
//
|
||||
// Check Vale ...
|
||||
double iVale = mX121Helper.GetVale(barIndex);
|
||||
if (iVale != vale)
|
||||
{
|
||||
//
|
||||
if (vale != 0 &&
|
||||
valeRepeate >= minRepetition)
|
||||
{
|
||||
//
|
||||
bool isExists = false;
|
||||
int count = ArraySize(vales);
|
||||
if (IsValidSize(count))
|
||||
{
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XPVPivot iPivot = vales[i];
|
||||
|
||||
//
|
||||
if (iPivot.lower == iVale)
|
||||
{
|
||||
//
|
||||
isExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!isExists)
|
||||
{
|
||||
//
|
||||
XPVPivot iPivot;
|
||||
|
||||
//
|
||||
iPivot.upper = 0;
|
||||
iPivot.lower = vale;
|
||||
iPivot.symbol = symbol;
|
||||
iPivot.period = period;
|
||||
iPivot.type = XPV_VALE;
|
||||
iPivot.repetition = valeRepeate;
|
||||
iPivot.to = iTime(
|
||||
symbol,
|
||||
period,
|
||||
valeToBarIndex //
|
||||
);
|
||||
iPivot.from = iTime(
|
||||
symbol,
|
||||
period,
|
||||
valeFromBarIndex //
|
||||
);
|
||||
|
||||
//
|
||||
iPivot.upper = iPivot.CalculateUpper();
|
||||
|
||||
//
|
||||
bool isValid = iPivot.IsValid();
|
||||
if (isValid)
|
||||
{
|
||||
//
|
||||
AddRef(
|
||||
iPivot,
|
||||
vales //
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
vale = iVale;
|
||||
valeRepeate = 0;
|
||||
valeFromBarIndex = 0;
|
||||
valeToBarIndex = barIndex;
|
||||
}
|
||||
else if (iVale == vale)
|
||||
{
|
||||
//
|
||||
valeRepeate++;
|
||||
valeFromBarIndex = barIndex;
|
||||
}
|
||||
|
||||
//
|
||||
canLookupPeak = ArraySize(peaks) < requiredPivots;
|
||||
canLookupVale = ArraySize(vales) < requiredPivots;
|
||||
canLookup = barIndex < end &&
|
||||
(canLookupPeak ||
|
||||
canLookupVale);
|
||||
if (canLookup)
|
||||
{
|
||||
barIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
result = IsValidSize(ArraySize(peaks)) ||
|
||||
IsValidSize(ArraySize(vales));
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Detect Order Flow ...
|
||||
Copy(
|
||||
peaks,
|
||||
orderFlow,
|
||||
false //
|
||||
);
|
||||
Copy(
|
||||
vales,
|
||||
orderFlow,
|
||||
false //
|
||||
);
|
||||
int count = ArraySize(orderFlow);
|
||||
result = IsValidSize(orderFlow);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Sort Pivots ...
|
||||
SortPivots(orderFlow);
|
||||
|
||||
//
|
||||
// Filter Broken Order Flows ...
|
||||
FilterBrokenPivots(orderFlow);
|
||||
|
||||
//
|
||||
// Detect Order Flow Direction ...
|
||||
result = DetectPivotDirection(
|
||||
orderFlow,
|
||||
orderFlowDirection //
|
||||
);
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
// Change Values Actions ...
|
||||
|
||||
|
||||
Reference in New Issue
Block a user