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 ...
|
||||
|
||||
|
||||
@@ -2666,6 +2666,29 @@ class XC121SMCTradeHandler : public XCBaseAlert
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
if (!youngestPosition.IsValid())
|
||||
{
|
||||
//
|
||||
int symbolIDX = FindLastExecutedSignalItem(signal);
|
||||
if (IsValidIndex(symbolIDX))
|
||||
{
|
||||
//
|
||||
datetime cTime = TimeCurrent();
|
||||
int signalPeriodSeconds = PeriodSeconds(signal.period);
|
||||
datetime lastExecutedTime = mLastExecutedSignals[symbolIDX].time;
|
||||
datetime passedTime = ((datetime)lastExecutedTime +
|
||||
((mDelayBarBetweenTwoSignal * signalPeriodSeconds)));
|
||||
|
||||
//
|
||||
result = cTime >= passedTime;
|
||||
if (!result)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
@@ -2712,6 +2735,9 @@ class XC121SMCTradeHandler : public XCBaseAlert
|
||||
forceTrail //
|
||||
);
|
||||
|
||||
//
|
||||
HandleSignalExecuted(signal);
|
||||
|
||||
//
|
||||
string msg = (signal.type == POSITION_TYPE_BUY ? "Long" : "Short") +
|
||||
" Signal Provided by: " + signal.provider +
|
||||
@@ -3789,7 +3815,8 @@ class XC121SMCTradeHandler : public XCBaseAlert
|
||||
private:
|
||||
//
|
||||
// Props ...
|
||||
double mAdditionalVolume; // Volume Additional
|
||||
double mAdditionalVolume; // Volume Additional
|
||||
XSymbolLastPosition mLastExecutedSignals[]; // Last Executed Signals
|
||||
|
||||
//
|
||||
// Read Only ...
|
||||
@@ -4131,6 +4158,78 @@ class XC121SMCTradeHandler : public XCBaseAlert
|
||||
mCollector.SaveSignal(item);
|
||||
}
|
||||
|
||||
//
|
||||
int FindLastExecutedSignalItem(XSignal &signal)
|
||||
{
|
||||
//
|
||||
int result = -1;
|
||||
|
||||
//
|
||||
if (!signal.IsValid())
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
int count = ArraySize(mLastExecutedSignals);
|
||||
if (!IsValidSize(count))
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
//
|
||||
XSymbolLastPosition iLast = mLastExecutedSignals[i];
|
||||
if (iLast.symbol == signal.symbol &&
|
||||
iLast.provider == signal.provider)
|
||||
{
|
||||
//
|
||||
result = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
return result;
|
||||
}
|
||||
|
||||
//
|
||||
void HandleSignalExecuted(XSignal &signal)
|
||||
{
|
||||
//
|
||||
if (!signal.IsValid())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//
|
||||
datetime cTime = TimeCurrent();
|
||||
int symbolIDX = FindLastExecutedSignalItem(signal);
|
||||
bool hasItem = IsValidIndex(symbolIDX);
|
||||
if (hasItem)
|
||||
{
|
||||
mLastExecutedSignals[symbolIDX].time = cTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
//
|
||||
XSymbolLastPosition item;
|
||||
|
||||
//
|
||||
item.time = cTime;
|
||||
item.symbol = signal.symbol;
|
||||
item.provider = signal.provider;
|
||||
|
||||
//
|
||||
AddRef(
|
||||
item,
|
||||
mLastExecutedSignals //
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user