diff --git a/Classes/x-saherelm.xtrade.class.mq5 b/Classes/x-saherelm.xtrade.class.mq5 index c95a78b5..0021f658 100644 --- a/Classes/x-saherelm.xtrade.class.mq5 +++ b/Classes/x-saherelm.xtrade.class.mq5 @@ -3285,6 +3285,51 @@ public: return result; } + // + // Prepare Dynamic Volume ... + double GetDynamicVolume( + string _symbol, + double _balanceFactor, + double _volumeStep // + ) + { + // + double result = 0; + + // + // Validate Inputs ... + if (!IsValid(_symbol) || + _volumeStep <= 0 || + _balanceFactor <= 0) + { + return result; + } + + // + // Retrieve Account Balance ... + double balance = mAccount.GetBalance(); + + // + double bStep = balance / _balanceFactor; + bStep = MathFloor(bStep); + if (bStep == 0) + { + bStep = 1; + } + + // + result = bStep * _volumeStep; + + // + result = NormalizeVolume( + result, + _symbol // + ); + + // + return result; + } + // // Protected ... protected: @@ -4939,6 +4984,39 @@ public: GetMaxDrawdown(); } + // + void UpdateSignal(XSignal &signal) + { + // + if (!signal.IsValid()) + { + return; + } + + // + int count = Count(); + if (!IsValidSize(count)) + { + return; + } + + // + for (int i = 0; i < count; i++) + { + // + bool isOwn = mData[i].IsOwn( + signal.symbol, + signal.provider, + signal.period, + ToPositionType(signal.type) // + ); + if (isOwn) + { + mData[i].Fill(signal); + } + } + } + // // Do all Protections ... void HandleProtection() @@ -5810,7 +5888,7 @@ protected: bool mSaveConditions; // Save SL Conditions // - XSymbolSessionParser mSymbolSession; // Check Symbol Session + XSymbolSessionParser mSymbolSession; // Check Symbol Session // bool mAllowLong; // Allow Long/Buy Trade Type diff --git a/Experts/x-saherelm.xch.strategy.ea.mq5 b/Experts/x-saherelm.xch.strategy.ea.mq5 index 6eb02188..76276867 100644 --- a/Experts/x-saherelm.xch.strategy.ea.mq5 +++ b/Experts/x-saherelm.xch.strategy.ea.mq5 @@ -49,9 +49,12 @@ input bool eaUseMaxAllowedTradesPerSymbol = true; / input string eaSymbols = "EURUSDb,GBPUSDb,USDJPYb,USDCHFb,XAUUSDb,DowJones30"; // Trading Symbols // -// Trades ... -input group "Trades"; -input double eaVolume = 0.3; // Static Volume +// Risk Management ... +input group "Risk Management"; + +// +// Risk Management > Risk / Reward Calculation ... +input group "Risk/Reward"; input double eaR2R = 1.5; // Risk to Reward Ratio for Dynamic TP SL input bool eaUseFixedTPSLPoints = true; // Use Fixed TP SL in Points input bool eaIgnoreTP = false; // Ignore TP @@ -60,8 +63,12 @@ input double eaTPPoint = 200; // Static TP Point input double eaSLPoint = 500; // Static SL Point // -// Risk Management ... -input group "Risk Management"; +// Risk Management > Volume Calculation ... +input group "Volume"; +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.3; // Static Volume // // Risk Management > Trade Management ... @@ -646,6 +653,30 @@ void OnSignalRecieved( return; } + // + // Prepare Signal Dynamic Volume + // if Provided ... + if (eaUseDynamicVolume && + eaDynamicVolumeStep > 0 && + eaDynamicVolumeBalanceFactor > 0) + { + // + double dVolume = eaTrader.GetDynamicVolume( + signal.symbol, + eaDynamicVolumeBalanceFactor, + eaDynamicVolumeStep // + ); + + // + if (dVolume > 0) + { + signal.volume = dVolume; + } + + // + eaTradeHandler.UpdateSignal(signal); + } + // // Since Signal Filtering done based on // Strategy and it's not related to Public