diff --git a/MultiSignal_Confluence_EA.mq5 b/MultiSignal_Confluence_EA.mq5 index 674f52e..d1b157e 100644 --- a/MultiSignal_Confluence_EA.mq5 +++ b/MultiSignal_Confluence_EA.mq5 @@ -5,7 +5,7 @@ //+------------------------------------------------------------------+ #property copyright "Copyright 2025, Abbey Road Tech" #property link "https://www.abbeyroadtech.com" -#property version "1.12" +#property version "1.13" #property strict #include @@ -17,7 +17,9 @@ input double InpMinStrength = 0.90; // Min signal strength (0.0-1.0) - input bool InpRequireAllAgree = true; // All signals must agree input group "=== Risk Management ===" -input double InpLotSize = 0.01; // Lot size +input double InpLotSize = 0.01; // Fixed Lot size (if UseRiskPercent=false) +input bool InpUseRiskPercent = true; // Use risk % for dynamic lot sizing +input double InpRiskPercent = 1.0; // Risk % per trade (1.0 = 1% of account) input int InpStopLoss = 100; // Stop Loss in points input int InpTakeProfit = 200; // Take Profit in points input bool InpUseTrailingStop = true; // Use trailing stop @@ -386,6 +388,40 @@ void CheckSignals(int &buyCount, int &sellCount, string &sources) } } +//+------------------------------------------------------------------+ +//| Calculate dynamic lot size based on risk % | +//+------------------------------------------------------------------+ +double CalculateLotSize(double slPoints) + { + if(!InpUseRiskPercent) return InpLotSize; + + double accountBalance = AccountInfoDouble(ACCOUNT_BALANCE); + double tickSize = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE); + double tickValue = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE); + double lotStep = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP); + double minLot = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN); + double maxLot = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MAX); + + if(tickSize <= 0 || slPoints <= 0) return InpLotSize; + + // Calculate risk amount + double riskAmount = accountBalance * InpRiskPercent / 100.0; + + // Calculate lot size: RiskAmount / (SL_Points * TickValue / TickSize) + double lots = riskAmount / (slPoints * tickValue / tickSize); + + // Normalize to lot step + lots = MathFloor(lots / lotStep) * lotStep; + + // Apply min/max limits + lots = MathMax(minLot, MathMin(maxLot, lots)); + + Print("Risk Lot Calc: Balance=", accountBalance, " Risk%=", InpRiskPercent, + " SL=", slPoints, " Lots=", lots); + + return lots; + } + //+------------------------------------------------------------------+ //| Validate SL/TP Prices | //+------------------------------------------------------------------+ @@ -486,7 +522,7 @@ void OpenBuyPosition(double strength, string sources) return; } - double lotSize = InpLotSize; + double lotSize = CalculateLotSize(InpStopLoss); double sl = ask - InpStopLoss * point; double tp = ask + InpTakeProfit * point; @@ -530,7 +566,7 @@ void OpenSellPosition(double strength, string sources) return; } - double lotSize = InpLotSize; + double lotSize = CalculateLotSize(InpStopLoss); double sl = bid + InpStopLoss * point; double tp = bid - InpTakeProfit * point;