This commit is contained in:
2024-12-29 05:42:27 +03:30
parent 408422dcfc
commit ecdba76c3f
12 changed files with 2310 additions and 104 deletions
@@ -773,13 +773,18 @@ class XCX121SMCBaseStrategy : public XCBaseAlert
iObj.SLColor(clrRed);
iObj.SLWidth(STYLE_DOT);
//
iObj.TargetWidth(1);
iObj.TargetColor(clrLightBlue);
iObj.TargetWidth(STYLE_DOT);
//
iObj.EntryWidth(1);
iObj.EntryColor(clrYellow);
iObj.EntryWidth(STYLE_DOT);
//
mDrawnObjects.Add(iObj);
// mDrawnObjects.Add(iObj);
}
/**
@@ -622,6 +622,605 @@ class XC121SMCCycleHelper : public XCBase
return result;
}
/**
* Validate Specified Pivot's State ...
*
* @param pivot: XPVPivot instance Reference ...
* @param barIndex: Integer ...
*/
void ValidatePivotState(
XPVPivot &pivot,
int barIndex = 0 //
)
{
//
if (!pivot.IsValid() ||
!pivot.state.IsValid() ||
!pivot.state.HasChild())
{
return;
}
//
double upperr = pivot.upper;
double lower = pivot.lower;
//
XOHCL cBar;
bool isInited = cBar.Init(
pivot.symbol,
pivot.period,
barIndex //
);
if (!isInited)
{
return;
}
//
int count = 0;
//
double ask = GetAsk(pivot.symbol);
double bid = GetBid(pivot.symbol);
//
double pivotMid = pivot.CalculateMid();
//
// Try to Validate States ...
//
bool isPriceInPremium =
//
ask > pivotMid &&
bid > pivotMid &&
cBar.low > pivotMid
//
;
//
bool isPriceInDiscount =
//
ask < pivotMid &&
bid < pivotMid &&
cBar.high < pivotMid
//
;
//
// Swings ...
XCSwing *tmpSwings[];
//
// Swing Highs ...
Clean(tmpSwings);
count = pivot.state.CountSwingHighs();
if (IsValidSize(count))
{
//
if (isPriceInPremium)
{
//
for (int i = 0; i < count; i++)
{
//
XCSwing *iSwing = pivot.state.swingHighs[i];
//
bool isValid =
//
iSwing.GetTime() >= pivot.from &&
iSwing.GetTime() <= pivot.to &&
iSwing.GetValue() > pivotMid
//
;
if (isValid)
{
//
Add(
iSwing,
tmpSwings //
);
}
}
//
Copy(
tmpSwings,
pivot.state.swingHighs //
);
}
}
//
// Swing Lows ...
Clean(tmpSwings);
count = pivot.state.CountSwingLows();
if (IsValidSize(count))
{
//
if (isPriceInDiscount)
{
//
for (int i = 0; i < count; i++)
{
//
XCSwing *iSwing = pivot.state.swingLows[i];
//
bool isValid =
//
iSwing.GetTime() >= pivot.from &&
iSwing.GetTime() <= pivot.to &&
iSwing.GetValue() < pivotMid
//
;
if (isValid)
{
//
Add(
iSwing,
tmpSwings //
);
}
}
//
Copy(
tmpSwings,
pivot.state.swingLows //
);
}
}
//
Clean(tmpSwings);
//
// Rejection Bars ...
XCRejectionBar *tmpRejections[];
//
// Bullish ...
Clean(tmpRejections);
count = pivot.state.CountBullishRejectionBars();
if (IsValidSize(count))
{
//
if (isPriceInDiscount)
{
//
for (int i = 0; i < count; i++)
{
//
XCRejectionBar *iRejection = pivot.state.bullishRejectionBars[i];
//
XOHCL iBar;
bool isFilled = iRejection.FillBar(iBar);
if (!isFilled)
{
continue;
}
//
bool isValid =
//
iRejection.BarTime() >= pivot.from &&
iBar.high < pivotMid
//
;
if (isValid)
{
//
Add(
iRejection,
tmpRejections //
);
}
}
//
Copy(
tmpRejections,
pivot.state.bullishRejectionBars //
);
}
}
//
// Bearish ...
Clean(tmpRejections);
count = pivot.state.CountBearishRejectionBars();
if (IsValidSize(count))
{
//
if (isPriceInPremium)
{
//
for (int i = 0; i < count; i++)
{
//
XCRejectionBar *iRejection = pivot.state.bearishRejectionBars[i];
//
XOHCL iBar;
bool isFilled = iRejection.FillBar(iBar);
if (!isFilled)
{
continue;
}
//
bool isValid =
//
iRejection.BarTime() >= pivot.from &&
iBar.low > pivotMid
//
;
if (isValid)
{
//
Add(
iRejection,
tmpRejections //
);
}
}
//
Copy(
tmpRejections,
pivot.state.bearishRejectionBars //
);
}
}
//
Clean(tmpRejections);
//
// Support Zone ...
XCSupportZone *tmpSupports[];
count = pivot.state.CountSupportZones();
if (IsValidSize(count))
{
//
if (isPriceInDiscount)
{
//
for (int i = 0; i < count; i++)
{
//
XCSupportZone *iZone = pivot.state.supportZones[i];
//
bool isValid =
//
iZone.Upper() < pivotMid
//
;
if (isValid)
{
//
Add(
iZone,
tmpSupports //
);
}
}
//
Copy(
tmpSupports,
pivot.state.supportZones //
);
}
}
//
Clean(tmpSupports);
//
// Resistance Zone ...
XCResistanceZone *tmpResistances[];
count = pivot.state.CountResistanceZones();
if (IsValidSize(count))
{
//
if (isPriceInPremium)
{
//
for (int i = 0; i < count; i++)
{
//
XCResistanceZone *iZone = pivot.state.resistanceZones[i];
//
bool isValid =
//
iZone.Lower() > pivotMid
//
;
if (isValid)
{
//
Add(
iZone,
tmpResistances //
);
}
}
//
Copy(
tmpResistances,
pivot.state.resistanceZones //
);
}
}
//
Clean(tmpResistances);
//
// Supply Zones ...
XCSupplyZone *tmpSupplies[];
count = pivot.state.CountSupplyZones();
if (IsValidSize(count))
{
//
if (isPriceInPremium)
{
//
for (int i = 0; i < count; i++)
{
//
XCSupplyZone *iZone = pivot.state.supplyZones[i];
//
bool isValid =
//
iZone.Lower() > pivotMid
//
;
if (isValid)
{
//
Add(
iZone,
tmpSupplies //
);
}
}
//
Copy(
tmpSupplies,
pivot.state.supplyZones //
);
}
}
//
Clean(tmpSupplies);
//
// Demand Zones ...
XCDemandZone *tmpDemands[];
count = pivot.state.CountDemandZones();
if (IsValidSize(count))
{
//
if (isPriceInDiscount)
{
//
for (int i = 0; i < count; i++)
{
//
XCDemandZone *iZone = pivot.state.demandZones[i];
//
bool isValid =
//
iZone.Upper() < pivotMid
//
;
if (isValid)
{
//
Add(
iZone,
tmpDemands //
);
}
}
//
Copy(
tmpDemands,
pivot.state.demandZones //
);
}
}
//
Clean(tmpDemands);
//
// Order Blocks ...
XCOrderBlock *tmpOrderBlocks[];
//
// Bullish ...
Clean(tmpOrderBlocks);
count = pivot.state.CountBullishOrderBlocks();
if (IsValidSize(count))
{
//
if (isPriceInDiscount)
{
//
for (int i = 0; i < count; i++)
{
//
XCOrderBlock *iZone = pivot.state.bullishOrderBlocks[i];
//
bool isValid =
//
iZone.Upper() < pivotMid
//
;
if (isValid)
{
//
Add(
iZone,
tmpOrderBlocks //
);
}
}
//
Copy(
tmpOrderBlocks,
pivot.state.bullishOrderBlocks //
);
}
}
//
// Bearish ...
Clean(tmpOrderBlocks);
count = pivot.state.CountBearishOrderBlocks();
if (IsValidSize(count))
{
//
if (isPriceInPremium)
{
//
for (int i = 0; i < count; i++)
{
//
XCOrderBlock *iZone = pivot.state.bearishOrderBlocks[i];
//
bool isValid =
//
iZone.Lower() > pivotMid
//
;
if (isValid)
{
//
Add(
iZone,
tmpOrderBlocks //
);
}
}
//
Copy(
tmpOrderBlocks,
pivot.state.bearishOrderBlocks //
);
}
}
//
Clean(tmpOrderBlocks);
//
// Fair Value Gaps ...
XCFVG *tmpFVGs[];
//
// Bullish ...
Clean(tmpFVGs);
count = pivot.state.CountBullishFairValueGaps();
if (IsValidSize(count))
{
//
if (isPriceInDiscount)
{
//
for (int i = 0; i < count; i++)
{
//
XCFVG *iZone = pivot.state.bullishFairValueGaps[i];
//
bool isValid =
//
iZone.Upper() < pivotMid
//
;
if (isValid)
{
//
Add(
iZone,
tmpFVGs //
);
}
}
//
Copy(
tmpFVGs,
pivot.state.bullishFairValueGaps //
);
}
}
//
// Bearish ...
Clean(tmpFVGs);
count = pivot.state.CountBearishFairValueGaps();
if (IsValidSize(count))
{
//
if (isPriceInPremium)
{
//
for (int i = 0; i < count; i++)
{
//
XCFVG *iZone = pivot.state.bearishFairValueGaps[i];
//
bool isValid =
//
iZone.Lower() > pivotMid
//
;
if (isValid)
{
//
Add(
iZone,
tmpFVGs //
);
}
}
//
Copy(
tmpFVGs,
pivot.state.bearishFairValueGaps //
);
}
}
//
Clean(tmpFVGs);
//
}
/**
* Detect Cycle Trend Based On Pivots ...
*
@@ -1173,7 +1772,7 @@ class XC121SMCCycleHelper : public XCBase
*
* @return ( int )
*/
int FillPivotPointss(XPVPivotPoint &pivots[])
int FillPivotPoints(XPVPivotPoint &pivots[])
{
//
int result = 0;
@@ -2020,6 +2619,14 @@ class XC121SMCCycleHelper : public XCBase
//
mActivePeakPivot.repetition++;
mActivePeakPivot.to = changeBar.time;
//
if (mActivePeakPivot.IsValid())
{
//
FillPivotState(mActivePeakPivot);
ValidatePivotState(mActivePeakPivot, barIndex);
}
}
else if (mActivePeakPivot.upper > 0 && mActivePeakPivot.upper != peak)
{
@@ -2083,6 +2690,14 @@ class XC121SMCCycleHelper : public XCBase
//
mActiveValePivot.repetition++;
mActiveValePivot.to = changeBar.time;
//
if (mActiveValePivot.IsValid())
{
//
FillPivotState(mActiveValePivot);
ValidatePivotState(mActiveValePivot, barIndex);
}
}
else if (mActiveValePivot.lower > 0 && mActiveValePivot.lower != vale)
{
@@ -47,6 +47,7 @@ struct X121SMCTradeData
double commission; // Commission
string conditions; // Signal Conditions
double maxDrawdown; // Max Position Drawdown
bool isTargeted; // Check Targetted Before Or Not
//
// Constructor ...
@@ -110,6 +111,9 @@ struct X121SMCTradeData
startTime = NULL;
conditions = NULL;
//
isTargeted = false;
//
signal.Clean();
}
@@ -2901,7 +2905,7 @@ class XC121SMCTradeHandler : public XCBaseAlert
mTrader.GetPositions(
longs,
shorts,
signal.symbol,
signal.symbol,
signal.provider //
);
}
@@ -3099,6 +3103,13 @@ class XC121SMCTradeHandler : public XCBaseAlert
);
if (!result)
{
//
AlertSignalExecutionFailed(
signal,
state //
);
//
return result;
}
}
@@ -3141,17 +3152,11 @@ class XC121SMCTradeHandler : public XCBaseAlert
//
if (!result)
{
//
// Alert Signal Execution Failed ...
string msg = "Failed To Execute " +
(signal.type == POSITION_TYPE_BUY ? "Long" : "Short") +
" Signal Provided by: " + signal.provider +
(signal.pushers > 1 ? " Pushers: " + ToString(signal.pushers) : "") +
" on: " + signal.symbol +
" in: " + ToString(signal.period) +
" due Reason: " + ToString(state) + " ...";
Alert(msg);
AlertSignalExecutionFailed(
signal,
state //
);
}
//
@@ -3411,13 +3416,20 @@ class XC121SMCTradeHandler : public XCBaseAlert
//
// Handle RF On Target ...
double target = iData.Target();
double targetDelta = isLong
? target + (15 * points)
: target - (15 * points);
bool canRF =
target > 0 &&
target > entry &&
!iData.isTargeted &&
(isLong ? target > entry
: target < entry) &&
(isLong
? iPosition.sl < target
: iPosition.sl > target) &&
iPosition.price > target + (10 * points);
(isLong
? iPosition.price > targetDelta
: iPosition.price < targetDelta);
if (canRF)
{
//
@@ -3432,6 +3444,9 @@ class XC121SMCTradeHandler : public XCBaseAlert
);
if (isModified)
{
//
mData[i].isTargeted = true;
//
string message = ToString(iData.Type()) +
" Position: " +
@@ -3529,7 +3544,22 @@ class XC121SMCTradeHandler : public XCBaseAlert
XSymbolLastPosition mLastExecutedSignals[]; // Last Executed Signals
//
// Hedge Related Functions ...
void AlertSignalExecutionFailed(
XSignal &signal,
ENUM_X_SIGNAL_EXECUTION_RESULT state //
)
{
//
// Alert Signal Execution Failed ...
string msg = "Failed To Execute " +
(signal.type == POSITION_TYPE_BUY ? "Long" : "Short") +
" Signal Provided by: " + signal.provider +
(signal.pushers > 1 ? " Pushers: " + ToString(signal.pushers) : "") +
" on: " + signal.symbol +
" in: " + ToString(signal.period) +
" due Reason: " + ToString(state) + " ...";
Alert(msg);
}
//
// Private ...