diff --git a/Helpers/x-saherelm.x121.helper.mq5 b/Helpers/x-saherelm.x121.helper.mq5 index 133f918b..aecef793 100644 --- a/Helpers/x-saherelm.x121.helper.mq5 +++ b/Helpers/x-saherelm.x121.helper.mq5 @@ -4171,6 +4171,109 @@ class XCX121Helper : public XCBaseHelper fl5Buffer // ); + + // + // XDON ... + + // + // OPEN ... + + // + // Upper ... + CopyBuffer( + mHandler, + X121_DON_OPEN_UPPER_LINE, + 0, + totalBars, + donOpenUpperBuffer + // + ); + + // + // Lower ... + CopyBuffer( + mHandler, + X121_DON_OPEN_LOWER_LINE, + 0, + totalBars, + donOpenLowerBuffer + // + ); + + // + // CLOSE ... + + // + // Upper ... + CopyBuffer( + mHandler, + X121_DON_CLOSE_UPPER_LINE, + 0, + totalBars, + donCloseUpperBuffer + // + ); + + // + // Lower ... + CopyBuffer( + mHandler, + X121_DON_CLOSE_LOWER_LINE, + 0, + totalBars, + donCloseLowerBuffer + // + ); + + // + // HIGH ... + + // + // Upper ... + CopyBuffer( + mHandler, + X121_DON_HIGH_UPPER_LINE, + 0, + totalBars, + donHighUpperBuffer + // + ); + + // + // Lower ... + CopyBuffer( + mHandler, + X121_DON_HIGH_LOWER_LINE, + 0, + totalBars, + donHighLowerBuffer + // + ); + + // + // LOW ... + + // + // Upper ... + CopyBuffer( + mHandler, + X121_DON_LOW_UPPER_LINE, + 0, + totalBars, + donLowUpperBuffer + // + ); + + // + // Lower ... + CopyBuffer( + mHandler, + X121_DON_LOW_LOWER_LINE, + 0, + totalBars, + donLowLowerBuffer + // + ); } }; diff --git a/Libraries/x-saherelm.x-poi.lib.mq5 b/Libraries/x-saherelm.x-poi.lib.mq5 index 2123c9ed..f3f37546 100644 --- a/Libraries/x-saherelm.x-poi.lib.mq5 +++ b/Libraries/x-saherelm.x-poi.lib.mq5 @@ -1323,6 +1323,32 @@ class XCSwing : public XCBasePOI return result; } + /** + * Get Swing Value ... + * + * @return ( double ) + */ + double GetValue() + { + // + double result = 0; + + // + if (!IsValid()) + { + return result; + } + + // + result = + IsSwingHigh() + ? mBar.high + : mBar.low; + + // + return result; + } + // // Overrides ... @@ -4056,11 +4082,11 @@ struct XValueChange /** * Fill Change Bar ... - * + * * @param bar: XOHCL instance Reference, holds Change Bar ... * @param _symbol: String, Specified Symbol ... * @param _period: ENUM_TIMEFRAMES _period member, Specified Period ... - * + * * @return ( bool ) */ bool FillBar( diff --git a/X121SMCEA/Libraries/x-121.smc.lib.mq5 b/X121SMCEA/Libraries/x-121.smc.lib.mq5 index b71adeee..9132b985 100644 --- a/X121SMCEA/Libraries/x-121.smc.lib.mq5 +++ b/X121SMCEA/Libraries/x-121.smc.lib.mq5 @@ -47,6 +47,26 @@ enum ENUM_X_121_SMC_PROVIDERS X_121_SMC_PROVIDER_VWAPC, }; +// +// X121 SL Method ... +enum ENUM_X_121_SMC_SL_TYPES +{ + X_121_SMC_SL_TYPE_NONE, + X_121_SMC_SL_TYPE_LAST_SAR_CHANGED_BAR, + X_121_SMC_SL_TYPE_CURRENT_SAR_BOX, + X_121_SMC_SL_TYPE_LAST_DIRECTIONAL_SAR, + X_121_SMC_SL_TYPE_CURRENT_SAR, + X_121_SMC_SL_TYPE_DON_CLOSE_BOX, + X_121_SMC_SL_TYPE_FIBO_LEVEL_1_5, + X_121_SMC_SL_TYPE_FIBO_LEVEL_3, + X_121_SMC_SL_TYPE_VWAP_FAST, + X_121_SMC_SL_TYPE_VWAP_MID, + X_121_SMC_SL_TYPE_VWAP_SLOW, + X_121_SMC_SL_TYPE_SWING, + X_121_SMC_SL_TYPE_MOMENTUM, + X_121_SMC_SL_TYPE_REJECTION, +}; + // // Pivot Types ... enum ENUM_XPV_PIVOTS diff --git a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 index 2bc150a0..9dfd1808 100644 --- a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 @@ -209,10 +209,11 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy ); // + double slAddition = 0; sl = hasLong - ? selectedSL - pip2 - : selectedSL + pip2; + ? selectedSL - slAddition + : selectedSL + slAddition; // // RISK Reward ... @@ -244,8 +245,8 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy if (result) { // - Print("PRV: ", provider); - DrawSignal(signal); + // Print("PRV: ", provider); + // DrawSignal(signal); } // @@ -505,6 +506,9 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy double bid = GetBid(symbol); datetime cTime = TimeCurrent(); + // + double selectedSL = 0; + // // Here We Select Cycles For Conditions Check ... ENUM_X_CYCLES cycles[5] = { @@ -672,12 +676,17 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy : X_DIRECTION_BEARISH; conditions.provider = providerStr; + // + // Selectiong SL ... + selectedSL = SelectSL( + conditions, + conditions.signalDir, + X_121_SMC_SL_TYPE_SWING // + ); + // // Detect SL and TP ... - conditions.sl = - isBullish - ? pSarChangeBar.low - : pSarChangeBar.high; + conditions.sl = selectedSL; // return result; @@ -1674,6 +1683,209 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy ); } + // + // SL Selector Methods ... + + /** + * Select Specified Type of Stop Loss ... + * + * @param conditions: X121SMCStrategyConditions instance Reference ... + * @param forDir: ENUM_X_DIRECTION member, Signal Direction ... + * @param type: ENUM_X_121_SMC_SL_TYPES member, Specified Required SL Type ... + * + * @return ( double ) + */ + double SelectSL( + X121SMCStrategyConditions &conditions, + ENUM_X_DIRECTION forDir, + ENUM_X_121_SMC_SL_TYPES type // + ) + { + // + double result = 0; + + // + string symbol = GetSymbol(); + ENUM_TIMEFRAMES period = GetPeriod(); + + // + bool isValid = + // + HasDirection(forDir) && + conditions.IsValid() && + type != X_121_SMC_SL_TYPE_NONE + // + ; + if (!isValid) + { + return result; + } + + // + XOHCL zBar; + bool isInited = zBar.Init( + symbol, + period, + 0 // + ); + if (!isInited) + { + return result; + } + + // + bool isBullish = IsBullish(forDir); + + // + if (type == X_121_SMC_SL_TYPE_FIBO_LEVEL_3) + { + result = conditions.triggerConditions.x121Conditions.fl3Buffer[0]; + } + else if (type == X_121_SMC_SL_TYPE_FIBO_LEVEL_1_5) + { + // + result = + isBullish + ? conditions.triggerConditions.x121Conditions.fl1Buffer[0] + : conditions.triggerConditions.x121Conditions.fl5Buffer[0]; + } + else if (type == X_121_SMC_SL_TYPE_DON_CLOSE_BOX) + { + // + result = + isBullish + ? conditions.triggerConditions.x121Conditions.donCloseLowerBuffer[0] + : conditions.triggerConditions.x121Conditions.donCloseUpperBuffer[0]; + } + else if (type == X_121_SMC_SL_TYPE_SWING) + { + // + int swingLowsCount = conditions.triggerConditions.state.CountSwingLows(); + int swingHighsCount = conditions.triggerConditions.state.CountSwingHighs(); + result = + isBullish + ? conditions.triggerConditions.state.swingLows[swingLowsCount - 1].GetValue() + : conditions.triggerConditions.state.swingHighs[swingHighsCount - 1].GetValue(); + } + else if (type == X_121_SMC_SL_TYPE_REJECTION) + { + // + result = + isBullish + ? conditions.triggerConditions.state.bullishRejectionBars[conditions.triggerConditions.state.CountBullishRejectionBars() - 1].Lower() + : conditions.triggerConditions.state.bearishRejectionBars[conditions.triggerConditions.state.CountBearishRejectionBars() - 1].Upper(); + } + else if (type == X_121_SMC_SL_TYPE_MOMENTUM) + { + // + result = + isBullish + ? conditions.triggerConditions.state.bullishMomentumBars[conditions.triggerConditions.state.CountBullishMomentumBars() - 1].Lower() + : conditions.triggerConditions.state.bearishMomentumBars[conditions.triggerConditions.state.CountBearishMomentumBars() - 1].Upper(); + } + else if (type == X_121_SMC_SL_TYPE_VWAP_FAST) + { + result = conditions.triggerConditions.x121Conditions.vwapFastBuffer[0]; + } + else if (type == X_121_SMC_SL_TYPE_VWAP_MID) + { + result = conditions.triggerConditions.x121Conditions.vwapMidBuffer[0]; + } + else if (type == X_121_SMC_SL_TYPE_VWAP_SLOW) + { + result = conditions.triggerConditions.x121Conditions.vwapSlowBuffer[0]; + } + else if (type == X_121_SMC_SL_TYPE_CURRENT_SAR) + { + result = conditions.triggerConditions.x121Conditions.sarBuffer[0]; + } + else if (type == X_121_SMC_SL_TYPE_CURRENT_SAR_BOX || + type == X_121_SMC_SL_TYPE_LAST_SAR_CHANGED_BAR || + type == X_121_SMC_SL_TYPE_LAST_DIRECTIONAL_SAR) + { + // + XOHCL cSarChangeBar; + XOHCL pSarChangeBar; + XValueChange cSarChange; // Current Sar Change (IsDirect) ... + XValueChange pSarChange; // Prev Sar Change (Direct) ... + XValueChange sarChanges[]; + int sarChangesCount = mTriggerCycleHelper + .FillSarChanges(sarChanges); + if (!IsValidSize(sarChangesCount) || sarChangesCount < 2) + { + return result; + } + + // + // + cSarChange = sarChanges[sarChangesCount - 1]; + pSarChange = sarChanges[sarChangesCount - 2]; + + // + bool isFilled = cSarChange.FillBar( + cSarChangeBar, + symbol, + period // + ); + if (!isFilled) + { + return result; + } + + // + isFilled = pSarChange.FillBar( + pSarChangeBar, + symbol, + period // + ); + if (!isFilled) + { + return result; + } + + // + if (type == X_121_SMC_SL_TYPE_LAST_SAR_CHANGED_BAR) + { + // + result = isBullish + ? pSarChangeBar.low + : pSarChangeBar.high; + } + else if (type == X_121_SMC_SL_TYPE_CURRENT_SAR_BOX) + { + // + result = + isBullish + ? zBar.FindLowest( + MathAbs(cSarChangeBar.Index() - 1), + MODE_LOW // + ) + : zBar.FindHighest( + MathAbs(cSarChangeBar.Index() - 1), + MODE_HIGH // + ); + } + else if (type == X_121_SMC_SL_TYPE_LAST_DIRECTIONAL_SAR) + { + // + XOHCL prevBar; + bool isInited = cSarChangeBar.GetPreviousBar(prevBar); + if (!isInited) + { + return result; + } + + // + result = isBullish + ? prevBar.low + : prevBar.high; + } + } + + // + return result; + } + // };