MultiSignal Confluence EA v1.13 - Add dynamic lot sizing
New Features: - InpUseRiskPercent: Enable risk-based lot sizing - InpRiskPercent: Risk % per trade (default 1.0%) - CalculateLotSize(): Dynamic lot calculation based on: * Account balance * Risk percentage * Stop loss distance * Symbol tick value/size Lot size formula: Risk$ / (SL_Points * TickValue/TickSize) Automatically adjusts lot size as account grows/shrinks. Falls back to fixed InpLotSize if UseRiskPercent=false.
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
#property copyright "Copyright 2025, Abbey Road Tech"
|
#property copyright "Copyright 2025, Abbey Road Tech"
|
||||||
#property link "https://www.abbeyroadtech.com"
|
#property link "https://www.abbeyroadtech.com"
|
||||||
#property version "1.12"
|
#property version "1.13"
|
||||||
#property strict
|
#property strict
|
||||||
|
|
||||||
#include <Trade\Trade.mqh>
|
#include <Trade\Trade.mqh>
|
||||||
@@ -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 bool InpRequireAllAgree = true; // All signals must agree
|
||||||
|
|
||||||
input group "=== Risk Management ==="
|
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 InpStopLoss = 100; // Stop Loss in points
|
||||||
input int InpTakeProfit = 200; // Take Profit in points
|
input int InpTakeProfit = 200; // Take Profit in points
|
||||||
input bool InpUseTrailingStop = true; // Use trailing stop
|
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 |
|
//| Validate SL/TP Prices |
|
||||||
//+------------------------------------------------------------------+
|
//+------------------------------------------------------------------+
|
||||||
@@ -486,7 +522,7 @@ void OpenBuyPosition(double strength, string sources)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double lotSize = InpLotSize;
|
double lotSize = CalculateLotSize(InpStopLoss);
|
||||||
double sl = ask - InpStopLoss * point;
|
double sl = ask - InpStopLoss * point;
|
||||||
double tp = ask + InpTakeProfit * point;
|
double tp = ask + InpTakeProfit * point;
|
||||||
|
|
||||||
@@ -530,7 +566,7 @@ void OpenSellPosition(double strength, string sources)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double lotSize = InpLotSize;
|
double lotSize = CalculateLotSize(InpStopLoss);
|
||||||
double sl = bid + InpStopLoss * point;
|
double sl = bid + InpStopLoss * point;
|
||||||
double tp = bid - InpTakeProfit * point;
|
double tp = bid - InpTakeProfit * point;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user