Fix lot size calculation and help me understand your fix

MQL5 Asesoramiento

Tarea técnica

I have a function in my EA that returns the lot size based on a provided entry and sl level.  The risk percentage of equity is also provided.  Sometimes the EA allocates too much risk and some times too little.  I can provide examples of each.  

Please help me to get the function to

1. allocate risk correctly no matter the instrument and or symbol including stock cfds, currencies, futures, commodities.

2. show an error indicating that the minimal lot size exceeds my risk allocation if necessary.


The code should:

1. prioritise readability

2. contain clear comments.


Please be willing to answer any questions I have to understand the code.


CSymbolInfo m_symbol;
CMoneyFixedRisk m_money;
CTrade my_trade;

risk_percent = 2;

double GetTradeVolume(string symbol)
  {
   double return_value = 0;
   ENUM_TIMEFRAMES timeframe = (ENUM_TIMEFRAMES)GlobalVariableGet("g" + symbol + "_timeframe");
   double entry = GlobalVariableGet("g" + symbol + "_entry_level");
   double sl = GlobalVariableGet("g" + symbol + "_sl");
   
   m_symbol.Name(symbol);
   m_money.Init(GetPointer(m_symbol), timeframe, (double)SymbolInfoDouble(symbol, SYMBOL_POINT));
   m_money.Percent(risk_percent);
   
   if(isLong)
      return_value =  m_money.CheckOpenLong(entry, sl);
   if(isShort)
      return_value =  m_money.CheckOpenShort(entry, sl);

   return_value = NormalizeDouble(return_value, 2);
   
   return return_value;
  }


Han respondido

1
Desarrollador 1
Evaluación
(155)
Proyectos
224
33%
Arbitraje
27
26% / 26%
Caducado
23
10%
Libre
2
Desarrollador 2
Evaluación
(376)
Proyectos
398
31%
Arbitraje
62
19% / 69%
Caducado
50
13%
Trabaja
3
Desarrollador 3
Evaluación
(15)
Proyectos
16
19%
Arbitraje
2
0% / 50%
Caducado
1
6%
Libre
Solicitudes similares
The basic indicator and the only indicator to be used is PRICE PERCENT RANGE and the indicator files are attached. A picture to visualize what is required is also attached. Job: Indicator : 1. Add Buy alert and Buy arrow function,if the price%R value touches or goes below value 9.5 or the user specified,after candle close. 2. Add Sell alert and Sell arrow function,if the price%R value touches or goes below value 90.5

Información sobre el proyecto

Presupuesto
30+ USD
Para el ejecutor
27 USD
Plazo límite de ejecución
a 2 día(s)