This commit is contained in:
2024-12-28 23:28:14 +03:30
parent c2cd52bf6b
commit 408422dcfc
20 changed files with 12042 additions and 3459 deletions
@@ -621,11 +621,12 @@ class XCX121SMCBaseStrategy : public XCBaseAlert
int end = -1;
int start = -1;
result = CalculateTicksParams(
start,
start,
end,
minRequiredTicksVerification //
);
if (!result) {
if (!result)
{
return result;
}
@@ -726,6 +727,61 @@ class XCX121SMCBaseStrategy : public XCBaseAlert
//
// Draw Functions ...
/**
* Draw Specified Signal ...
*
* @param signal: XSignal instance ...
*/
void DrawSignal(XSignal &signal)
{
//
if (!signal.IsValid())
{
return;
}
//
// DrawConditions(conditions);
//
string name = signal.GetTag();
RemoveObject(name);
//
XCSignalObject *iObj;
iObj = new XCSignalObject();
//
bool isCreated = iObj.Create(
ChartIdentification(),
name,
SubWindowIdentification(),
signal //
);
if (!isCreated)
{
return;
}
//
iObj.TPWidth(1);
iObj.TPColor(clrGreen);
iObj.TPWidth(STYLE_DOT);
//
iObj.SLWidth(1);
iObj.SLColor(clrRed);
iObj.SLWidth(STYLE_DOT);
//
iObj.EntryWidth(1);
iObj.EntryColor(clrYellow);
iObj.EntryWidth(STYLE_DOT);
//
mDrawnObjects.Add(iObj);
}
/**
* Clear all Drawn Objects ...
*/
@@ -785,562 +841,6 @@ class XCX121SMCBaseStrategy : public XCBaseAlert
}
}
/**
* Draw Specified Signal ...
*
* @param signal: XSignal instance ...
*/
void DrawSignal(XSignal &signal)
{
//
if (!signal.IsValid())
{
return;
}
//
// DrawConditions(conditions);
//
string name = signal.GetTag();
RemoveObject(name);
//
XCSignalObject *iObj;
iObj = new XCSignalObject();
//
bool isCreated = iObj.Create(
ChartIdentification(),
name,
SubWindowIdentification(),
signal //
);
if (!isCreated)
{
return;
}
//
iObj.TPWidth(1);
iObj.TPColor(clrGreen);
iObj.TPWidth(STYLE_DOT);
//
iObj.SLWidth(1);
iObj.SLColor(clrRed);
iObj.SLWidth(STYLE_DOT);
//
iObj.EntryWidth(1);
iObj.EntryColor(clrYellow);
iObj.EntryWidth(STYLE_DOT);
//
mDrawnObjects.Add(iObj);
}
/**
* Draw Specified State on Chart ...
*
* @param state: XPOIState instance ...
*/
void DrawState(
XPOIState &state,
bool forceUpdateTo = false,
bool drawSwingHighs = true,
bool drawSwingLows = true,
bool drawSupportZones = true,
bool drawResistanceZones = true,
bool drawSupplyZones = true,
bool drawDemandZones = true,
bool drawBullishOrderBlocks = true,
bool drawBearishOrderBlocks = true,
bool drawBullishFairValueGaps = true,
bool drawBearishFairValueGaps = true,
bool drawBullishRejectionBars = true,
bool drawBearishRejectionBars = true,
bool drawBullishMomentumBars = true,
bool drawBearishMomentumBars = true,
bool drawTicksZone = true //
)
{
//
int count = 0;
datetime cTime = TimeCurrent();
//
// Swings ...
//
// Swing Highs ...
if (drawSwingHighs)
{
//
count = ArraySize(state.swingHighs);
if (IsValidSize(count))
{
//
for (int i = 0; i < count; i++)
{
//
XCSwing item = state.swingHighs[i];
//
XCSwingHighObject *iObj;
bool isCreated = mPOIDrawer.CreateSwingHigh(
item,
iObj //
);
if (isCreated)
{
AddObjectIfNotExists(iObj);
}
}
}
}
//
// Swing Lows ...
if (drawSwingLows)
{
//
count = ArraySize(state.swingLows);
if (IsValidSize(count))
{
//
for (int i = 0; i < count; i++)
{
//
XCSwing item = state.swingLows[i];
//
XCSwingLowObject *iObj;
bool isCreated = mPOIDrawer.CreateSwingLow(
item,
iObj //
);
if (isCreated)
{
AddObjectIfNotExists(iObj);
}
}
}
}
//
// Support and Resistance Zones ...
//
// Support Zones ...
if (drawSupportZones)
{
//
count = ArraySize(state.supportZones);
if (IsValidSize(count))
{
//
for (int i = 0; i < count; i++)
{
//
XCSupportZone item = state.supportZones[i];
if (forceUpdateTo)
{
item.To(cTime);
}
//
XCSupportZoneObject *iObj;
bool isCreated = mPOIDrawer.CreateSupportZone(
item,
iObj //
);
if (isCreated)
{
AddObjectIfNotExists(iObj);
}
}
}
}
//
// Resistance Zones ...
if (drawResistanceZones)
{
//
count = ArraySize(state.resistanceZones);
if (IsValidSize(count))
{
//
for (int i = 0; i < count; i++)
{
//
XCResistanceZone item = state.resistanceZones[i];
if (forceUpdateTo)
{
item.To(cTime);
}
//
XCResistanceZoneObject *iObj;
bool isCreated = mPOIDrawer.CreateResistanceZone(
item,
iObj //
);
if (isCreated)
{
AddObjectIfNotExists(iObj);
}
}
}
}
//
// Supply and Demand Zones ...
//
// Supply Zones ...
if (drawSupplyZones)
{
//
count = ArraySize(state.supplyZones);
if (IsValidSize(count))
{
//
for (int i = 0; i < count; i++)
{
//
XCSupplyZone item = state.supplyZones[i];
if (forceUpdateTo)
{
item.To(cTime);
}
//
XCSupplyZoneObject *iObj;
bool isCreated = mPOIDrawer.CreateSupplyZone(
item,
iObj //
);
if (isCreated)
{
AddObjectIfNotExists(iObj);
}
}
}
}
//
// Demand Zones ...
if (drawDemandZones)
{
//
count = ArraySize(state.demandZones);
if (IsValidSize(count))
{
//
for (int i = 0; i < count; i++)
{
//
XCDemandZone item = state.demandZones[i];
if (forceUpdateTo)
{
item.To(cTime);
}
//
XCDemandZoneObject *iObj;
bool isCreated = mPOIDrawer.CreateDemandZone(
item,
iObj //
);
if (isCreated)
{
AddObjectIfNotExists(iObj);
}
}
}
}
//
// Order Blocks ...
//
// Bullish Order Blocks ...
if (drawBullishOrderBlocks)
{
//
count = ArraySize(state.bullishOrderBlocks);
if (IsValidSize(count))
{
//
for (int i = 0; i < count; i++)
{
//
XCOrderBlock item = state.bullishOrderBlocks[i];
if (forceUpdateTo)
{
item.To(cTime);
}
//
XCBullishOrderBlockObject *iObj;
bool isCreated = mPOIDrawer.CreateBullishOrderBlock(
item,
iObj //
);
if (isCreated)
{
AddObjectIfNotExists(iObj);
}
}
}
}
//
// Bearish Order Blocks ...
if (drawBearishOrderBlocks)
{
//
count = ArraySize(state.bearishOrderBlocks);
if (IsValidSize(count))
{
//
for (int i = 0; i < count; i++)
{
//
XCOrderBlock item = state.bearishOrderBlocks[i];
if (forceUpdateTo)
{
item.To(cTime);
}
//
XCBearishOrderBlockObject *iObj;
bool isCreated = mPOIDrawer.CreateBearishOrderBlock(
item,
iObj //
);
if (isCreated)
{
AddObjectIfNotExists(iObj);
}
}
}
}
//
// Fair Value Gaps ...
//
// Bullish Fair Value Gaps ...
if (drawBullishFairValueGaps)
{
//
count = ArraySize(state.bullishFairValueGaps);
if (IsValidSize(count))
{
//
for (int i = 0; i < count; i++)
{
//
XCFVG item = state.bullishFairValueGaps[i];
if (forceUpdateTo)
{
item.To(cTime);
}
//
XCBullishFairValueGapObject *iObj;
bool isCreated = mPOIDrawer.CreateBullishFairValueGap(
item,
iObj //
);
if (isCreated)
{
AddObjectIfNotExists(iObj);
}
}
}
}
//
// Bearish Fair Value Gaps ...
if (drawBearishFairValueGaps)
{
//
count = ArraySize(state.bearishFairValueGaps);
if (IsValidSize(count))
{
//
for (int i = 0; i < count; i++)
{
//
XCFVG item = state.bearishFairValueGaps[i];
if (forceUpdateTo)
{
item.To(cTime);
}
//
XCBearishFairValueGapObject *iObj;
bool isCreated = mPOIDrawer.CreateBearishFairValueGap(
item,
iObj //
);
if (isCreated)
{
AddObjectIfNotExists(iObj);
}
}
}
}
//
// Rejection Bars ...
//
// Bullish Rejection Bars ...
if (drawBullishRejectionBars)
{
//
count = ArraySize(state.bullishRejectionBars);
if (IsValidSize(count))
{
//
for (int i = 0; i < count; i++)
{
//
XCRejectionBar item = state.bullishRejectionBars[i];
//
XCBullishRejectionBarObject *iObj;
bool isCreated = mPOIDrawer.CreateBullishRejectionBar(
item,
iObj //
);
if (isCreated)
{
AddObjectIfNotExists(iObj);
}
}
}
}
//
// Bearish Rejection Bars ...
if (drawBearishRejectionBars)
{
//
count = ArraySize(state.bearishRejectionBars);
if (IsValidSize(count))
{
//
for (int i = 0; i < count; i++)
{
//
XCRejectionBar item = state.bearishRejectionBars[i];
//
XCBearishRejectionBarObject *iObj;
bool isCreated = mPOIDrawer.CreateBearishRejectionBar(
item,
iObj //
);
if (isCreated)
{
AddObjectIfNotExists(iObj);
}
}
}
}
//
// Momentum Bars ...
//
// Bullish Momentum Bars ...
if (drawBullishMomentumBars)
{
//
count = ArraySize(state.bullishMomentumBars);
if (IsValidSize(count))
{
//
for (int i = 0; i < count; i++)
{
//
XCMomentumBar item = state.bullishMomentumBars[i];
//
XCBullishMomentumBarObject *iObj;
bool isCreated = mPOIDrawer.CreateBullishMomentumBar(
item,
iObj //
);
if (isCreated)
{
AddObjectIfNotExists(iObj);
}
}
}
}
//
// Bearish Momentum Bars ...
if (drawBearishMomentumBars)
{
//
count = ArraySize(state.bearishMomentumBars);
if (IsValidSize(count))
{
//
for (int i = 0; i < count; i++)
{
//
XCMomentumBar item = state.bearishMomentumBars[i];
//
XCBearishMomentumBarObject *iObj;
bool isCreated = mPOIDrawer.CreateBearishMomentumBar(
item,
iObj //
);
if (isCreated)
{
AddObjectIfNotExists(iObj);
}
}
}
}
//
// Ticks Zone ...
if (drawTicksZone &&
state.ticksZone != NULL)
{
//
XCTicksZone *iZone = state.ticksZone;
//
if (forceUpdateTo)
{
iZone.To(cTime);
}
//
XCTicksZoneObject *iObj;
bool isCreated = mPOIDrawer.CreateTicksZone(
iZone,
iObj //
);
if (isCreated)
{
AddObjectIfNotExists(iObj);
}
}
}
/**
* Add Specified Object to Drawn Objects if not Exists ...
*/
@@ -1377,6 +877,25 @@ class XCX121SMCBaseStrategy : public XCBaseAlert
}
}
/**
* Add Specified Objects to Drawn Objects if not Exists ...
*/
void AddObjectsIfNotExists(XCBaseObject *&objects[])
{
//
int count = ArraySize(objects);
if (!IsValidSize(count))
{
return;
}
//
for (int i = 0; i < count; i++)
{
AddObjectIfNotExists(objects[i]);
}
}
//
// Private ...
private:
@@ -33,6 +33,7 @@
enum ENUM_X_CYCLES
{
X_CYCLE_NONE,
X_CYCLE_TRIGGER,
X_CYCLE_DECISION,
X_CYCLE_ANALYSE,
@@ -41,6 +42,18 @@ enum ENUM_X_CYCLES
X_CYCLE_VISION,
};
string ToString(ENUM_X_CYCLES value)
{
//
string result = EnumToString(value);
//
StringReplace(result, "X_CYCLE_", "");
//
return result;
}
enum ENUM_X_CYCLE_EVENTS
{
SAR_CHANGE_DETECTED,
@@ -50,8 +63,10 @@ enum ENUM_X_CYCLE_EVENTS
VWAP_ORDER_CHANGE_ETECTED,
VWAP_STATE_CHANGE_DETCTED,
CONSOLIDATION_BREAKED_DETECTED,
PIVOT_STARTED,
PIVOT_ENDED,
PEAK_PIVOT_STARTED,
PEAK_PIVOT_ENDED,
VALE_PIVOT_STARTED,
VALE_PIVOT_ENDED,
};
class XC121SMCCycleHelper : public XCBase
@@ -144,6 +159,35 @@ class XC121SMCCycleHelper : public XCBase
mConsolidationLoopback = value;
}
/**
* Get Valid Pivot Points Repetition Length ...
* min => 7
*
* @return ( int )
*/
int ValidPivotRepetition()
{
return mValidPivotRepetition;
}
/**
* Set Valid Pivot Points Repetition Length ...
*
* @param value: Integer ...
* min => 7
*/
void ValidPivotRepetition(int value)
{
//
if (value < 7)
{
value = 7;
}
//
mValidPivotRepetition = value;
}
//
// Actions ...
@@ -191,7 +235,7 @@ class XC121SMCCycleHelper : public XCBase
symbol,
period //
);
mPOIDetector.MaxNumberOfRequiredPOIs(0);
mPOIDetector.MaxNumberOfRequiredPOIs(10);
mPOIDetector.Init();
//
@@ -457,6 +501,12 @@ class XC121SMCCycleHelper : public XCBase
//
if (result)
{
//
if (!IsValidSize(ArraySize(mPivots)))
{
Detect(barIndex);
}
//
Calculate(
barIndex,
@@ -572,315 +622,6 @@ 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;
}
/**
* Detect Cycle Trend Based On Pivots ...
*
@@ -1616,18 +1357,6 @@ class XC121SMCCycleHelper : public XCBase
return result;
}
/**
* Get Current Active Pivot ...
*
* @param pivot: XPVPivot instance reference ...
*/
void GetActivePivot(XPVPivot &pivot)
{
//
mActivePivot.to = TimeCurrent();
pivot = mActivePivot;
}
/**
* Count Calculated Pivots ...
*
@@ -1666,6 +1395,86 @@ class XC121SMCCycleHelper : public XCBase
return result;
}
/**
* Retrieve Last Pivot ...
*
* @param pivot: XPVPivot instance Reference ...
*
* @return ( bool )
*/
bool GetLastPivot(XPVPivot &pivot)
{
//
bool result = false;
//
pivot.Clean();
//
XPVPivot pivots[];
int count = FillPivots(pivots);
if (IsValidSize(count))
{
pivot = pivots[count - 1];
}
//
result = pivot.IsValid();
//
return result;
}
/**
* Retrieve Active Peak Pivot ...
*
* @param pivot: XPVPivot instance Reference ...
*
* @return ( bool )
*/
bool GetActivePeakPivot(XPVPivot &pivot)
{
//
bool result = false;
//
pivot.Clean();
//
pivot = mActivePeakPivot;
//
result = pivot.IsValid();
//
return result;
}
/**
* Retrieve Active Vale Pivot ...
*
* @param pivot: XPVPivot instance Reference ...
*
* @return ( bool )
*/
bool GetActiveValePivot(XPVPivot &pivot)
{
//
bool result = false;
//
pivot.Clean();
//
pivot = mActiveValePivot;
//
result = pivot.IsValid();
//
return result;
}
//
// Virtuals ...
@@ -1675,6 +1484,7 @@ class XC121SMCCycleHelper : public XCBase
virtual void Default()
{
//
ValidPivotRepetition(21);
ConsolidationLoopback(10);
MaxAllowedSavedChanges(50);
}
@@ -2118,7 +1928,7 @@ class XC121SMCCycleHelper : public XCBase
int repetition = 0;
ENUM_TIMEFRAMES period = GetPeriod();
int periodSeconds = PeriodSeconds(period);
int minRepetition = mX121Helper.GetDonChainLength();
int minRepetition = ValidPivotRepetition();
ENUM_XPV_PIVOTS type = isNewPeak
? XPV_PEAK
: XPV_VALE;
@@ -2180,67 +1990,340 @@ class XC121SMCCycleHelper : public XCBase
}
}
// //
// // Calculate Pivots ...
// if (isNewPeak || isNewVale)
// {
// //
// if (!mActivePivot.IsValid())
// {
// //
// mActivePivot.symbol = symbol;
// mActivePivot.period = period;
//
// Calculate XPVPivot ...
int pvValidation = ValidPivotRepetition();
if (IsValidSize(pvValidation))
{
//
// Peak ...
mActivePeakPivot.symbol = symbol;
mActivePeakPivot.period = period;
mActivePeakPivot.type = XPV_PEAK;
// //
// mActivePivot.upper = peak;
// mActivePivot.lower = vale;
//
if (mActivePeakPivot.upper == 0 && peak > 0)
{
//
mActivePeakPivot.upper = peak;
mActivePeakPivot.lower = vale;
mActivePeakPivot.from = changeBar.time;
// //
// mActivePivot.from = cTime;
// mActivePivot.to = cTime;
//
Add(
PEAK_PIVOT_STARTED,
events //
);
}
else if (mActivePeakPivot.upper > 0 && mActivePeakPivot.upper == peak)
{
//
mActivePeakPivot.repetition++;
mActivePeakPivot.to = changeBar.time;
}
else if (mActivePeakPivot.upper > 0 && mActivePeakPivot.upper != peak)
{
//
if (mActivePeakPivot.repetition >= pvValidation)
{
//
AddRef(
mActivePeakPivot,
mPivots //
);
// //
// mActivePivot.type =
// isNewPeak
// ? XPV_VALE
// : XPV_PEAK;
// mActivePivot.repetition++;
//
Add(
PEAK_PIVOT_ENDED,
events //
);
// //
// Add(
// PIVOT_STARTED,
// events //
// );
// }
// else
// {
// //
// mActivePivot.to = cTime;
//
mActivePeakPivot.Clean();
}
else
{
//
mActivePeakPivot.upper = peak;
mActivePeakPivot.lower = vale;
mActivePeakPivot.repetition = 0;
mActivePeakPivot.from = changeBar.time;
// //
// mActivePivot.repetition++;
//
Add(
PEAK_PIVOT_STARTED,
events //
);
}
}
// //
// if (mActivePivot.to > mActivePivot.from)
// {
// FillPivotState(mActivePivot);
// }
//
// Vale ...
mActiveValePivot.symbol = symbol;
mActiveValePivot.period = period;
mActiveValePivot.type = XPV_VALE;
// //
// // Check Ticks Zone is Valid ...
// bool isTicksZoneValid =
// //
// mActivePivot.state.IsValid() &&
// mActivePivot.state.ticksZone != NULL &&
// mActivePivot.state.ticksZone.IsValid()
// //
// ;
// if (isTicksZoneValid) {
// //
// Print("Has Valid Ticks Zone ...");
// }
// }
// }
//
// Peak ...
if (mActiveValePivot.lower == 0 && vale > 0)
{
//
mActiveValePivot.lower = vale;
mActiveValePivot.upper = peak;
mActiveValePivot.from = changeBar.time;
//
Add(
VALE_PIVOT_STARTED,
events //
);
}
else if (mActiveValePivot.lower > 0 && mActiveValePivot.lower == vale)
{
//
mActiveValePivot.repetition++;
mActiveValePivot.to = changeBar.time;
}
else if (mActiveValePivot.lower > 0 && mActiveValePivot.lower != vale)
{
//
if (mActiveValePivot.repetition >= pvValidation)
{
//
AddRef(
mActiveValePivot,
mPivots //
);
//
Add(
VALE_PIVOT_ENDED,
events //
);
//
mActiveValePivot.Clean();
}
else
{
//
mActiveValePivot.lower = vale;
mActiveValePivot.upper = peak;
mActiveValePivot.repetition = 0;
mActiveValePivot.from = changeBar.time;
//
Add(
VALE_PIVOT_STARTED,
events //
);
}
}
}
}
/**
* Detect Requirements ...
*/
void Detect(int barIndex)
{
//
if (isDetecting)
{
return;
}
//
int start = barIndex;
int max = 576;
int validPivotRepetition = ValidPivotRepetition();
//
string symbol = GetSymbol();
ENUM_TIMEFRAMES period = GetPeriod();
//
// Try To Detect Valid Peaks or Vales ...
double peak = 0;
double vale = 0;
int peakRepetition = 0;
int valeRepetition = 0;
//
int from = start;
int index = from;
int count = start + max;
//
bool canContinue = true;
//
// Loop Throug Peaks and Vales ...
while (canContinue)
{
//
datetime toTime = iTime(
symbol,
period,
index //
);
//
double iPeak = mX121Helper.GetPeak(index);
double iVale = mX121Helper.GetVale(index);
//
// Peak ...
if (peak == 0 && iPeak > 0)
{
//
peak = iPeak;
peakRepetition = 0;
}
else if (peak > 0 && iPeak > 0 && peak == iPeak)
{
peakRepetition++;
}
else if (peak > 0 && iPeak > 0 && peak != iPeak)
{
//
if (peakRepetition >= validPivotRepetition)
{
//
datetime fromTime = iTime(
symbol,
period,
index - peakRepetition //
);
//
// Create XPVPivotPoint ...
XPVPivotPoint pivotPoint;
pivotPoint.value = iPeak;
pivotPoint.time = toTime;
pivotPoint.type = XPV_PEAK;
pivotPoint.repetition = peakRepetition;
if (pivotPoint.IsValid())
{
//
AddRef(
pivotPoint,
mPivotPoints //
);
}
//
// Create XPVPivot ...
XPVPivot pivot;
pivot.symbol = symbol;
pivot.period = period;
pivot.from = fromTime;
pivot.to = toTime;
pivot.repetition = peakRepetition;
pivot.type = XPV_PEAK;
pivot.upper = peak;
pivot.lower = iVale;
FillPivotState(pivot);
//
if (pivot.IsValid())
{
//
AddRef(
pivot,
mPivots //
);
}
}
//
peak = iPeak;
peakRepetition = 0;
}
//
// Vale ...
if (vale == 0 && iVale > 0)
{
//
vale = iVale;
valeRepetition = 0;
}
else if (vale > 0 && iVale > 0 && vale == iVale)
{
valeRepetition++;
}
else if (vale > 0 && iVale > 0 && vale != iVale)
{
//
if (valeRepetition >= validPivotRepetition)
{
//
datetime fromTime = iTime(
symbol,
period,
index - valeRepetition //
);
//
// Create XPVPivotPoint ...
XPVPivotPoint pivotPoint;
pivotPoint.value = iVale;
pivotPoint.time = toTime;
pivotPoint.type = XPV_VALE;
pivotPoint.repetition = valeRepetition;
if (pivotPoint.IsValid())
{
//
AddRef(
pivotPoint,
mPivotPoints //
);
}
//
// Create XPVPivot ...
XPVPivot pivot;
pivot.symbol = symbol;
pivot.period = period;
pivot.from = fromTime;
pivot.to = toTime;
pivot.repetition = valeRepetition;
pivot.type = XPV_VALE;
pivot.upper = iPeak;
pivot.lower = vale;
FillPivotState(pivot);
//
if (pivot.IsValid())
{
//
AddRef(
pivot,
mPivots //
);
}
}
//
vale = iVale;
valeRepetition = 0;
}
//
index++;
canContinue = index < count;
}
//
int pivotsCount = ArraySize(mPivots);
if (IsValidSize(mPivots))
{
ArrayReverse(mPivots);
}
//
isDetecting = false;
}
//
@@ -2263,12 +2346,14 @@ class XC121SMCCycleHelper : public XCBase
XConsolidationZone mActioveConsolidationZone; // Holds Actiove Consolidation Zone ...
//
int mValidPivotRepetition; // Valid Pivot Point's Repetition ...
XPVPivotPoint mPivotPoints[]; // Holds Pivots ...
//
XCXPVPivotObject mActivePivotObject;
XPVPivot mActivePivot;
XPVPivot mPivots[];
bool isDetecting;
XPVPivot mActivePeakPivot; // Active Pivots ...
XPVPivot mActiveValePivot; // Active Pivots ...
XPVPivot mPivots[]; // Holds Active Pivot ...
//
// Actions ...
@@ -629,6 +629,16 @@ struct X121SMCTradeData
return signal.tp;
}
/**
* Get Model Target ...
*
* @return ( double )
*/
double Target()
{
return signal.target;
}
/**
* Get Position Spread on Open Time ...
*
@@ -2369,8 +2379,9 @@ class XC121SMCTradeHandler : public XCBaseAlert
//
// Check Deal Reason ...
bool isTP = deal.reason == DEAL_REASON_TP;
bool isSL = deal.reason == DEAL_REASON_SL;
bool isTP = deal.reason == DEAL_REASON_TP ||
(deal.reason == DEAL_REASON_SL && deal.profit > 0);
bool isSL = deal.reason == DEAL_REASON_SL && deal.profit < 0;
//
// Prepare Specified Message Based on Deal Reason ...
@@ -2494,7 +2505,7 @@ class XC121SMCTradeHandler : public XCBaseAlert
//
// Simulate TP/SL based on Closing Profit ...
bool isTP = position.profit > 0;
bool isSL = position.profit < 0;
bool isSL = position.profit <= 0;
//
if (isTP || isSL)
@@ -2890,7 +2901,8 @@ class XC121SMCTradeHandler : public XCBaseAlert
mTrader.GetPositions(
longs,
shorts,
signal.symbol //
signal.symbol,
signal.provider //
);
}
else
@@ -2899,7 +2911,8 @@ class XC121SMCTradeHandler : public XCBaseAlert
mTrader.GetPositions(
longs,
shorts,
NULL // All Symbols ...
NULL, // All Symbols ...
signal.provider //
);
}
@@ -3394,6 +3407,40 @@ class XC121SMCTradeHandler : public XCBaseAlert
}
}
}
//
// Handle RF On Target ...
double target = iData.Target();
bool canRF =
target > 0 &&
target > entry &&
(isLong
? iPosition.sl < target
: iPosition.sl > target) &&
iPosition.price > target + (10 * points);
if (canRF)
{
//
double sl = target;
double tp = iPosition.tp;
string comment = "RF On Target ...";
bool isModified = mTrader.Modify(
iData.ticket,
sl,
tp,
comment //
);
if (isModified)
{
//
string message = ToString(iData.Type()) +
" Position: " +
ToString(iData.ticket) +
" RF On Traget: " + ToString(target) +
" Successfully ...";
Alert(message);
}
}
}
}