diff --git a/Classes/x-saherelm.x-trade.class.mq5 b/Classes/x-saherelm.x-trade.class.mq5 index ae894f85..badfc219 100644 --- a/Classes/x-saherelm.x-trade.class.mq5 +++ b/Classes/x-saherelm.x-trade.class.mq5 @@ -654,6 +654,12 @@ class XCTrade : public XCBase // void AddOnModifyPositionEventHandler(TOnModify handler) { + // + if (handler == NULL) + { + return; + } + // Add( handler, @@ -665,6 +671,12 @@ class XCTrade : public XCBase // void AddOnForceClosePositionEventHandler(TOnForceClose handler) { + // + if (handler == NULL) + { + return; + } + // Add( handler, @@ -676,6 +688,12 @@ class XCTrade : public XCBase // void AddOnPartialClosePositionEventHandler(TOnPartialClose handler) { + // + if (handler == NULL) + { + return; + } + // Add( handler, @@ -688,6 +706,12 @@ class XCTrade : public XCBase // Add New Deals Changed Event Handler ... void AddOnTradeStateChangedEventHandler(TOnTradeStateChanged handler) { + // + if (handler == NULL) + { + return; + } + // Add( handler, @@ -700,6 +724,12 @@ class XCTrade : public XCBase // Add New Deals Changed Event Handler ... void AddOnDealsChangedEventHandler(TOnDealsChanged handler) { + // + if (handler == NULL) + { + return; + } + // Add( handler, @@ -712,6 +742,12 @@ class XCTrade : public XCBase // Add New Orders Changed Event Handler ... void AddOnOrdersChangedEventHandler(TOnOrdersChanged handler) { + // + if (handler == NULL) + { + return; + } + // Add( handler, @@ -724,6 +760,12 @@ class XCTrade : public XCBase // Add New Positions Changed Event Handler ... void AddOnPositionsChangedEventHandler(TOnPositionsChanged handler) { + // + if (handler == NULL) + { + return; + } + // Add( handler, @@ -736,6 +778,12 @@ class XCTrade : public XCBase // Add New Stop Loss Event Handler ... void AddOnStopLossEventHandler(TOnStopLoss handler) { + // + if (handler == NULL) + { + return; + } + // Add( handler, @@ -748,6 +796,12 @@ class XCTrade : public XCBase // Add New Stop Loss Event Handler ... void AddOnTakeProfitEventHandler(TOnTakeProfit handler) { + // + if (handler == NULL) + { + return; + } + // Add( handler, diff --git a/Experts/x-saherelm.x-121.smc.ea.mq5 b/Experts/x-saherelm.x-121.smc.ea.mq5 index a49ca626..a4e09093 100644 --- a/Experts/x-saherelm.x-121.smc.ea.mq5 +++ b/Experts/x-saherelm.x-121.smc.ea.mq5 @@ -44,11 +44,13 @@ input string eaSymbols = "EURUSDb,GBPUSDb,USDJPYb,USDCHFb,DowJones30,XAUUSDb"; / // // Volume ... input group "Volume"; +input double eaR2R = 2; // Risk to Reward Ratio input bool eaUseDynamicVolume = false; // Use Dynamic Volume input double eaDynamicVolumeStep = 0.01; // Increase Volume Step input double eaDynamicVolumeBalanceFactor = 200; // Balance Factor for Generate Dynamic Volume input double eaVolume = 0.05; // Static Volume -input double eaRiskPercentPerBalance = 0.25; // Risk Percent Per Balance on Each Trade +input bool eaDynamicRiskManagement = true; // Dynamic Risk Management +input double eaRiskPercentPerBalance = 0.5; // Risk Percent Per Balance on Each Trade // // Signalling ... @@ -72,7 +74,7 @@ input bool eaTerminalAlerts = false; // Terminal Alerts input group "Reports"; input bool eaReportNewMonths = false; // Report New Month input bool eaReportNewWeeks = false; // Report New Weeks -input bool eaReportNewDays = false; // Report New Days +input bool eaReportNewDays = true; // Report New Days input bool eaReportNewHours = false; // Report New Hours // @@ -140,9 +142,11 @@ int OnInit() eaExpert.ReportNewHours(eaReportNewHours); // + eaExpert.R2R(eaR2R); eaExpert.Volume(eaVolume); eaExpert.UseDynamicVolume(eaUseDynamicVolume); eaExpert.DynamicVolumeStep(eaDynamicVolumeStep); + eaExpert.DynamicRiskManagement(eaDynamicRiskManagement); eaExpert.RiskPercentPerBalance(eaRiskPercentPerBalance); eaExpert.DynamicVolumeBalanceFactor(eaDynamicVolumeBalanceFactor); diff --git a/X121SMCEA/Classes/x-121.smc.x-tradehandler.class.mq5 b/X121SMCEA/Classes/x-121.smc.x-tradehandler.class.mq5 index 01dcdf3e..bb571b5a 100644 --- a/X121SMCEA/Classes/x-121.smc.x-tradehandler.class.mq5 +++ b/X121SMCEA/Classes/x-121.smc.x-tradehandler.class.mq5 @@ -58,6 +58,7 @@ struct X121SMCTradeData string conditions; // Signal Conditions // + bool forceTrail; // Force Trail int trailStep; // Trail Step bool partiallyClosed; // Partially Closed or not datetime lastProtectedOn; // Last Protected On @@ -200,6 +201,7 @@ struct X121SMCTradeData // trailStep = 0; + forceTrail = false; lastProtectedOn = NULL; partiallyClosed = false; @@ -1948,8 +1950,11 @@ class XC121SMCTradeHandler : public XCBaseAlert // First Step of Trade Handling ... // Since Must Call when a Signal Executed ... void AddData( - XSignal &signal, // Executed Signal - double commission = 0 // Commission + XSignal &signal, // Executed Signal + double commission = 0, // Commission + // + // Force Protections ... + bool forceTrail = false // Force Trail Stops ... ) { // @@ -1975,6 +1980,27 @@ class XC121SMCTradeHandler : public XCBaseAlert // item.commission = commission; + // + // Checking Trailling Configs ... + double trailStep = TrailStep(); + double trailStartDistance = TrailStartDistance(); + bool enableTrail = + trailStep > 0 && + trailStartDistance > 0; + + // + bool onlyTrailUnprotecteds = OnlyTrailUnprotected(); + bool canCheck = + (onlyTrailUnprotecteds + ? !isSupport && + !isRecovery + : true) && + enableTrail; + if (canCheck) + { + item.forceTrail = forceTrail; + } + // Add(item); @@ -2326,6 +2352,71 @@ class XC121SMCTradeHandler : public XCBaseAlert ); } + /** + * Retrieve Specified Symbols Info ... + * + * @param symbol: String ... + * @param info: X121SMCSymbolPositionInfo instance ... + * + * @return ( bool ) + */ + bool GetSymbolInfo( + string symbol, + X121SMCSymbolPositionInfo &info // + ) + { + // + bool result = false; + + // + info.Clean(); + + // + int symbolIDX = -1; + result = HasSymbol( + symbol, + symbolIDX // + ); + if (!result) + { + return result; + } + + // + info = mSymbolInfos[symbolIDX]; + + // + return result; + } + + /** + * Reset Specified Symbol Info ... + * + * @param symbol: String ... + */ + void ResetSymbolInfo(string symbol) + { + // + if (!IsValid(symbol)) + { + return; + } + + // + int symbolIDX = -1; + bool hasSymbol = HasSymbol( + symbol, + symbolIDX // + ); + if (!hasSymbol) + { + return; + } + + // + mSymbolInfos[symbolIDX].Reset(); + } + // // Position Execute and Sync Functions ... @@ -2430,7 +2521,10 @@ class XC121SMCTradeHandler : public XCBaseAlert bool ExecuteSignal( XSignal &signal, // Signal for Execution ENUM_X_SIGNAL_EXECUTION_RESULT &state, // Execution State - bool ignorePolicies = false // Ignore Execution Policies + bool ignorePolicies = false, // Ignore Execution Policies + // + // Force Protections ... + bool forceTrail = false // Force Trail Position ) { // @@ -2614,7 +2708,8 @@ class XC121SMCTradeHandler : public XCBaseAlert // Add Signal to Trade Handler ... AddData( signal, - commission // + commission, + forceTrail // ); // @@ -3046,7 +3141,7 @@ class XC121SMCTradeHandler : public XCBaseAlert // // Reading Requirements for Trailling Stops ... - bool allowTrail = AllowTrail(); + bool allowTrail = AllowTrail() || mData[iDX].forceTrail; double trailStep = TrailStep(); double trailStartDistance = TrailStartDistance(); bool allowOnlyUnprotecteds = OnlyTrailUnprotected(); diff --git a/X121SMCEA/Experts/x-121.smc.expert.class.mq5 b/X121SMCEA/Experts/x-121.smc.expert.class.mq5 index e7f86f99..d20f5815 100644 --- a/X121SMCEA/Experts/x-121.smc.expert.class.mq5 +++ b/X121SMCEA/Experts/x-121.smc.expert.class.mq5 @@ -53,6 +53,34 @@ class XC121SMCExpert : public XCBaseExpert // // Getter(s) / Setter(s) ... + /** + * Get Risk to Reward Ratio ... + * + * @return ( double ) + */ + double R2R() + { + return mR2R; + } + + /** + * Set Risk to Reward Ratio ... + * + * @param value: Double ... + */ + void R2R(double value) + { + // + if (value < 1) + { + value = 1; + } + + // + mR2R = value; + ReConfigureAllStrategies(); + } + /** * Get Use Dynamic Volume State ... * @@ -154,6 +182,26 @@ class XC121SMCExpert : public XCBaseExpert mRiskPercentPerBalance = value; } + /** + * Get Dynamic Risk Management State ... + * + * @return ( bool ) + */ + bool DynamicRiskManagement() + { + return mDynamicRiskManagement; + } + + /** + * Set Dynamic Risk Management State ... + * + * @param value: Boolean ... + */ + void DynamicRiskManagement(bool value) + { + mDynamicRiskManagement = value; + } + /** * Get Static Volume ... * @@ -265,12 +313,27 @@ class XC121SMCExpert : public XCBaseExpert // datetime currentTime = TimeCurrent(); + // + // Check Signal Protections ... + bool canTrail = false; + ENUM_X_121_SMC_PROVIDERS signalProvider = ParseProvider(signal.provider); + if (IsValid(signalProvider)) + { + // + // Complete this in Force States ... + // canTrail = true; + } + // // Execute Signal Using Trade Handler ... ENUM_X_SIGNAL_EXECUTION_RESULT state; bool isExecuted = mTradeHandler.ExecuteSignal( signal, - state // + state, + false, // ignore Policies ... + // + // Force Protections ... + canTrail // ); // @@ -326,12 +389,19 @@ class XC121SMCExpert : public XCBaseExpert ReportNewHours(false); ReportNewMonths(false); + // + R2R(1); + // // Volume Default Configurations ... Volume(0.01); UseDynamicVolume(false); DynamicVolumeStep(0.01); DynamicVolumeBalanceFactor(200); + + // + RiskPercentPerBalance(0); + DynamicRiskManagement(false); } /** @@ -495,8 +565,8 @@ class XC121SMCExpert : public XCBaseExpert // TODO: Make This Configurable Later ... // - mTradeHandler.DelayBarBetweenTwoSignal(3); mTradeHandler.MaxAllowedSLToPause(0); + mTradeHandler.DelayBarBetweenTwoSignal(3); mTradeHandler.MaxAllowedSLReachedPauseDelay(HoursToSeconds(24)); // @@ -532,7 +602,7 @@ class XC121SMCExpert : public XCBaseExpert mTradeHandler.TrailStep(15); mTradeHandler.TrailStartDistance(30); mTradeHandler.OnlyTrailUnprotected(true); - mTradeHandler.RemoveTPAfterTrailedLevel(4); + mTradeHandler.RemoveTPAfterTrailedLevel(3); // // Partial Close (In Profit) ... @@ -676,6 +746,10 @@ class XC121SMCExpert : public XCBaseExpert */ void HandleStrategiesOnTick() override { + // + // Calling Protection Handler of TradeHandler ... + mTradeHandler.HandleProtection(); + // int count = ArraySize(mStrategies); if (!IsValidSize(count)) @@ -721,6 +795,13 @@ class XC121SMCExpert : public XCBaseExpert // Finish ... mTradeHandler.Finish(deal); + // + bool useDynamicRiskManagement = DynamicRiskManagement(); + if (useDynamicRiskManagement) + { + mTradeHandler.ResetSymbolInfo(deal.symbol); + } + // HandleReportBalance(); } @@ -781,7 +862,7 @@ class XC121SMCExpert : public XCBaseExpert // result = - XCBaseExpertToken + result; + XC121SMCExpertToken + result; // return result; @@ -856,6 +937,23 @@ class XC121SMCExpert : public XCBaseExpert riskInPoints // ); + // + // Check Dynamic Risk Management ... + bool allowDynamicRiskManagement = DynamicRiskManagement(); + if (allowDynamicRiskManagement) + { + // + // Calculate Dynamic Additional Risk Management Volume Multiplier ... + double mAdditionalRiskMultiplier = CalculateAdditionalVolumeMultiplier(signal); + if (mAdditionalRiskMultiplier < 1) + { + mAdditionalRiskMultiplier = 1; + } + + // + volume *= mAdditionalRiskMultiplier; + } + // if (volume > 0) { @@ -898,7 +996,7 @@ class XC121SMCExpert : public XCBaseExpert // Confiugre Signalling ... // - strategy.R2R(2); + strategy.R2R(R2R()); strategy.AllowLong(AllowLong()); strategy.AllowShort(AllowShort()); strategy.MaxAllowedSpread(20); @@ -968,12 +1066,47 @@ class XC121SMCExpert : public XCBaseExpert // // Volume Management ... + double mR2R; // Signallers Risk to Reward Ratio ... bool mUseDynamicVolume; // Use Dynamic Volume ... double mDynamicVolumeStep; // Increase Volume Step ... double mDynamicVolumeBalanceFactor; // Balance Factor for Generate Dynamic Volume ... double mVolume; // Static Volume ... + bool mDynamicRiskManagement; // Dynamic Risk Management ... double mRiskPercentPerBalance; // Risk Percent Per Balance in Each Trade ... + // + double CalculateAdditionalVolumeMultiplier(XSignal &signal) + { + // + double result = 0; + + // + if (!signal.IsValid()) + { + return result; + } + + // + X121SMCSymbolPositionInfo info; + bool hasInfo = mTradeHandler.GetSymbolInfo( + signal.symbol, + info // + ); + if (!hasInfo) + { + return result; + } + + // + if (info.countedSLs >= 2) + { + result = (info.countedSLs / 2) + 1; + } + + // + return result; + } + // }; diff --git a/X121SMCEA/Libraries/x-121.smc.lib.mq5 b/X121SMCEA/Libraries/x-121.smc.lib.mq5 index 2c49e97b..e88a3ac2 100644 --- a/X121SMCEA/Libraries/x-121.smc.lib.mq5 +++ b/X121SMCEA/Libraries/x-121.smc.lib.mq5 @@ -35,6 +35,23 @@ const string X121SMCStrategyToken = "X121SMC"; +const string X121SMCPVToken = "X121SMCPV"; +const string X121SMCBOSToken = "X121SMCBOS"; +const string X121SMCSARToken = "X121SMCSAR"; +const string X121SMCCHOCHToken = "X121SMCCHOCH"; +const string X121SMCPULLBKToken = "X121SMCPULLBK"; + +enum ENUM_X_121_SMC_PROVIDERS +{ + // + X_121_SMC_PROVIDER_NONE, + X_121_SMC_PROVIDER_PV, + X_121_SMC_PROVIDER_BOS, + X_121_SMC_PROVIDER_SAR, + X_121_SMC_PROVIDER_CHOCH, + X_121_SMC_PROVIDER_PULLBK, +}; + enum ENUM_XPV_PIVOTS { XPV_NONE, @@ -1661,4 +1678,121 @@ void DetectPivotPOIs( } } +// +// Provider Extensions ... + +/** + * Validate a Signal Provider ... + * + * @param value: ENUM_X_121_SMC_PROVIDERS member ... + * + * @return ( bool ) + */ +bool IsValid(ENUM_X_121_SMC_PROVIDERS value) +{ + // + bool result = false; + + // + result = value != X_121_SMC_PROVIDER_NONE; + + // + return result; +} + +/** + * Converts a Signal Provider to String ... + * + * @param value: ENUM_X_121_SMC_PROVIDERS member ... + * + * @return ( string ) + */ +string ToString(ENUM_X_121_SMC_PROVIDERS value) +{ + // + string result = NULL; + + // + if (!IsValid(value)) + { + return result; + } + + // + switch (value) + { + // + case X_121_SMC_PROVIDER_PV: + result = X121SMCPVToken; + break; + + // + case X_121_SMC_PROVIDER_BOS: + result = X121SMCBOSToken; + break; + + // + case X_121_SMC_PROVIDER_SAR: + result = X121SMCSARToken; + break; + + // + case X_121_SMC_PROVIDER_CHOCH: + result = X121SMCCHOCHToken; + break; + + // + case X_121_SMC_PROVIDER_PULLBK: + result = X121SMCPULLBKToken; + break; + } + + // + return result; +} + +/** + * Parse Specified String as a Signal Provider ... + * + * @param value: String ... + * + * @return ( ENUM_X_121_SMC_PROVIDERS ) + */ +ENUM_X_121_SMC_PROVIDERS ParseProvider(string value) +{ + // + ENUM_X_121_SMC_PROVIDERS result = X_121_SMC_PROVIDER_NONE; + + // + if (!IsValid(value)) + { + return result; + } + + // + if (Contains(X121SMCPVToken, value)) + { + result = X_121_SMC_PROVIDER_PV; + } + else if (Contains(X121SMCBOSToken, value)) + { + result = X_121_SMC_PROVIDER_BOS; + } + else if (Contains(X121SMCSARToken, value)) + { + result = X_121_SMC_PROVIDER_SAR; + } + else if (Contains(X121SMCCHOCHToken, value)) + { + result = X_121_SMC_PROVIDER_CHOCH; + } + else if (Contains(X121SMCPULLBKToken, value)) + { + result = X_121_SMC_PROVIDER_PULLBK; + } + + // + return result; +} + // \ No newline at end of file diff --git a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 index 8dbc2c16..526f1418 100644 --- a/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 +++ b/X121SMCEA/Strategy/x-121.smc.test.strategy.class.mq5 @@ -30,7 +30,7 @@ #include "../Classes/x-121.smc.base.strategy.class.mq5" // -// Helper(s) ... +// Definitions ... // // XStrategy Class Implementation(s) ... @@ -392,6 +392,13 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy pBar.high > lastPivot.lower) // ; + + // + if (hasBOS) + { + mLastBOSOn = TimeCurrent(); + } + bool hasCHOCH = isOrderFlowBullish ? @@ -412,6 +419,45 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy // ; + // + if (hasCHOCH) + { + // RedrawOrderFlow(); + mLastCHOCHOn = TimeCurrent(); + // ClearDraws(); + } + + // + // Check PSar is Equals to Peak or Vale ... + bool isSAREqualsToPeak = + conditions.xchsarConditions.cSars[0] == conditions.xpvConditions.peaks[1]; + bool isSAREqualsToVale = + conditions.xchsarConditions.cSars[0] == conditions.xpvConditions.vales[1]; + + // + bool hasNewPeak = + conditions.xpvConditions.peaks[0] != conditions.xpvConditions.peaks[1]; + bool hasNewPeakOverLast = + hasNewPeak && + conditions.xpvConditions.peaks[0] > conditions.xpvConditions.peaks[1]; + bool hasNewPeakUnderLast = + hasNewPeak && + conditions.xpvConditions.peaks[0] < conditions.xpvConditions.peaks[1]; + + // + bool hasNewVale = + conditions.xpvConditions.vales[0] != conditions.xpvConditions.vales[1]; + bool hasNewValeOverLast = + hasNewVale && + conditions.xpvConditions.vales[0] > conditions.xpvConditions.vales[1]; + bool hasNewValeUnderLast = + hasNewVale && + conditions.xpvConditions.vales[0] < conditions.xpvConditions.vales[1]; + + // + // START Signalling ... + // + // // BOS Signals ... bool has_BOS_Long = false; @@ -433,172 +479,192 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy bool has_PULLBK_Short = false; // - // Detect BOS Or CHOCH Signals ... - if (hasBOS || hasCHOCH) + // PV Signals ... + bool has_PV_Long = false; + bool has_PV_Short = false; + + // + // BOS Signals ... + // + has_BOS_Long = + // + hasBOS && + isOrderFlowBullish && + isCRMEBullish && + cBar.IsBullish() && + conditions.xchsarConditions.cSars[0] < cBar.low + // + ; + + // + if (has_BOS_Long) { // - // Do on CHOCH ... - if (hasCHOCH) - { - // - has_CHOCH_Long = - // - !isOrderFlowBullish && - cBar.IsBullish() && - (isCBullishMomentumBar || - isCBullishRejectionBar) && - conditions.xchsarConditions.cSars[0] < cBar.low - // - ; - if (has_CHOCH_Long) - { - // - provider = "CHOCH-Long"; - selectedSL = cBar.low; - } - - // - has_CHOCH_Short = - // - isOrderFlowBullish && - cBar.IsBearish() && - (isCBearishMomentumBar || - isCBearishRejectionBar) && - conditions.xchsarConditions.cSars[0] > cBar.high - // - ; - if (has_CHOCH_Short) - { - // - provider = "CHOCH-Short"; - selectedSL = cBar.high; - } - - // - mLastCHOCHOn = TimeCurrent(); - } - - // - // Do on BOS ... - if (hasBOS) - { - // - has_BOS_Long = - // - isOrderFlowBullish && - isCRMEBullish && - cBar.IsBullish() && - conditions.xchsarConditions.cSars[0] < cBar.low - // - ; - - // - if (has_BOS_Long) - { - // - provider = "BOS-Long"; - selectedSL = cBar.low; - } - - // - has_BOS_Short = - // - !isOrderFlowBullish && - isCRMEBearish && - cBar.IsBearish() && - conditions.xchsarConditions.cSars[0] > cBar.high - // - ; - if (has_BOS_Short) - { - // - provider = "BOS-Short"; - selectedSL = cBar.high; - } - - // - mLastBOSOn = TimeCurrent(); - } + selectedSL = cBar.low; + provider = ToString(X_121_SMC_PROVIDER_BOS); } - else + + // + has_BOS_Short = + // + hasBOS && + !isOrderFlowBullish && + isCRMEBearish && + cBar.IsBearish() && + conditions.xchsarConditions.cSars[0] > cBar.high + // + ; + if (has_BOS_Short) { // - // Check PSar is Equals to Peak or Vale ... - bool isSAREqualsToPeak = - conditions.xchsarConditions.cSars[0] == conditions.xpvConditions.peaks[1]; - bool isSAREqualsToVale = - conditions.xchsarConditions.cSars[0] == conditions.xpvConditions.vales[1]; - - // - has_SAR_Long = - // - isSAREqualsToVale && - isOrderFlowBullish && - isPSarInDirectionOfOrderFlow - // - ; - if (has_SAR_Long) - { - // - provider = "SAR_Long"; - selectedSL = conditions.xchsarConditions.cSars[0]; - } - - // - has_SAR_Short = - // - isSAREqualsToPeak && - !isOrderFlowBullish && - isPSarInDirectionOfOrderFlow - // - ; - if (has_SAR_Short) - { - // - provider = "SAR_Short"; - selectedSL = conditions.xchsarConditions.cSars[0]; - } - - // - // Check PULLBK Conditions ... - - // - has_PULLBK_Long = - // - isCRMEBullish && - isPSarInDirectionOfOrderFlow && - (cBar.low < conditions.x3maConditions.fasts[0] && - cBar.GetDown() > conditions.x3maConditions.fasts[0]) && - !(pBar.low < conditions.x3maConditions.fasts[1] && - pBar.GetDown() > conditions.x3maConditions.fasts[1]) - // - ; - if (has_PULLBK_Long) - { - // - provider = "PULLBK-Long"; - selectedSL = cBar.low; - } - - // - has_PULLBK_Short = - // - isCRMEBearish && - isPSarInDirectionOfOrderFlow && - (cBar.high > conditions.x3maConditions.fasts[0] && - cBar.GetUp() < conditions.x3maConditions.fasts[0]) && - !(pBar.high > conditions.x3maConditions.fasts[1] && - pBar.GetUp() < conditions.x3maConditions.fasts[1]) - // - ; - if (has_PULLBK_Short) - { - // - provider = "PULLBK-Short"; - selectedSL = cBar.high; - } + selectedSL = cBar.high; + provider = ToString(X_121_SMC_PROVIDER_BOS); } + // + // CHOCH Signals ... + + // + has_CHOCH_Long = + // + hasCHOCH && + isCRMEBullish && + cBar.IsBullish() && + !isOrderFlowBullish && + conditions.xchsarConditions.cSars[0] < cBar.low + // + ; + if (has_CHOCH_Long) + { + // + selectedSL = cBar.low; + provider = ToString(X_121_SMC_PROVIDER_CHOCH); + } + + // + has_CHOCH_Short = + // + hasCHOCH && + isCRMEBearish && + cBar.IsBearish() && + isOrderFlowBullish && + conditions.xchsarConditions.cSars[0] > cBar.high + // + ; + if (has_CHOCH_Short) + { + // + selectedSL = cBar.high; + provider = ToString(X_121_SMC_PROVIDER_CHOCH); + } + + // + // SAR Signals ... + + // + has_SAR_Long = + // + isSAREqualsToVale && + isOrderFlowBullish && + isPSarInDirectionOfOrderFlow + // + ; + if (has_SAR_Long) + { + // + provider = ToString(X_121_SMC_PROVIDER_SAR); + selectedSL = conditions.xchsarConditions.cSars[0]; + } + + // + has_SAR_Short = + // + isSAREqualsToPeak && + !isOrderFlowBullish && + isPSarInDirectionOfOrderFlow + // + ; + if (has_SAR_Short) + { + // + provider = ToString(X_121_SMC_PROVIDER_SAR); + selectedSL = conditions.xchsarConditions.cSars[0]; + } + + // + // PULLBK Signals ... + + // + has_PULLBK_Long = + // + isCRMEBullish && + isPSarInDirectionOfOrderFlow && + (cBar.low < conditions.x3maConditions.fasts[0] && + cBar.GetDown() > conditions.x3maConditions.fasts[0]) + // + ; + if (has_PULLBK_Long) + { + // + selectedSL = cBar.low; + provider = ToString(X_121_SMC_PROVIDER_PULLBK); + } + + // + has_PULLBK_Short = + // + isCRMEBearish && + isPSarInDirectionOfOrderFlow && + (cBar.high > conditions.x3maConditions.fasts[0] && + cBar.GetUp() < conditions.x3maConditions.fasts[0]) + // + ; + if (has_PULLBK_Short) + { + // + selectedSL = cBar.high; + provider = ToString(X_121_SMC_PROVIDER_PULLBK); + } + + // + // PV Signals ... + + // + has_PV_Long = + // + isCRMEBullish && + isOrderFlowBullish && + !hasNewValeUnderLast && + cBar.low == conditions.xpvConditions.vales[0] + // + ; + if (has_PV_Long) + { + // + selectedSL = cBar.low; + provider = ToString(X_121_SMC_PROVIDER_PV); + } + + // + has_PV_Short = + // + isCRMEBearish && + !isOrderFlowBullish && + !hasNewPeakOverLast && + cBar.high == conditions.xpvConditions.peaks[0] + // + ; + if (has_PV_Short) + { + // + selectedSL = cBar.high; + provider = ToString(X_121_SMC_PROVIDER_PV); + } + + // + // END Signalling ... + // + // // Combine all Signals Conditions ... @@ -610,18 +676,18 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy || // has_CHOCH_Long - // // - // || - // // - // // has_SAR_Long - // // - // || - // // - // has_PULLBK_Long - // // - // || // - // false + || + // + has_SAR_Long + // + || + // + has_PULLBK_Long + // + || + // + has_PV_Long // ; @@ -633,18 +699,18 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy || // has_CHOCH_Short - // // - // || - // // - // // has_SAR_Short - // // - // || - // // - // has_PULLBK_Short - // // - // || // - // false + || + // + has_SAR_Short + // + || + // + has_PULLBK_Short + // + || + // + has_PV_Short // ; @@ -652,6 +718,17 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy result = hasLong || hasShort; + // + // Reset Order Flow ... + if (hasCHOCH && !result) + { + ResetOrderFlow(); + } + else if (hasBOS && !result) + { + UpdateOrderFlow(); + } + // // Rmove Signal Condition ... if (result) @@ -702,11 +779,6 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy ? entry + reward : entry - reward; - // - Print("PRV: ", provider); - RedrawOrderFlow(); - ClearDraws(); - // signal.sl = sl; signal.tp = tp; @@ -717,13 +789,20 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy signal.symbol = _symbol; signal.period = _period; signal.pushers = pushers; - signal.provider = GetTag(); + signal.provider = provider; signal.time = TimeCurrent(); // result = PrepareSignal(signal); if (result) { + // + Print("PRV: ", provider); + RedrawOrderFlow(); + DrawSignal(signal); + ClearDraws(); + + // ResetOrderFlow(); } @@ -1425,10 +1504,9 @@ class XCX121SMCTestStrategy : public XCX121SMCBaseStrategy * When a BOS Happens ... * we have to Update Order Flow ... */ - void UpdateOrderFlowOnBOS() + void UpdateOrderFlow() { - // - Print("UpdateOrderFlowOnBOS"); + ResetOrderFlow(); } /**