Test report errors on my EA code

 

Hello. When I want to load an EA in mql market, during verification it gives me some errors that give me a headache.

The first time it gave me Risk lot calculation, then I modified the code and another error appears with trade opened 0.2 lot. 

// === Risk lot calculator ===
double CalculateRiskLot(double sl, double entry)
{
    // Calculate risk per trade (RiskPercent)
    double riskPerTrade = AccountInfoDouble(ACCOUNT_BALANCE) * RiskPercent / 100.0;

    // Calculate distance in pips between entry price and StopLoss
    double slPips = MathAbs(entry - sl) / (_Point * 10); // Convert to pips

    // Pip value (for EURUSD usually 10 for 1 standard lot)
    double pipValue = 10.0;

    // Calculate raw lot size
    double rawLot = riskPerTrade / (slPips * pipValue);

    // Get minimum lot and lot step for current symbol
    double minLot = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
    double lotStep = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);

    // Make sure lot size is not smaller than minimum lot
    double finalLot = MathMax(minLot, rawLot);

    // Round lot size to 2 decimals
    finalLot = NormalizeDouble(finalLot, 2);

    // Adjust lot size according to step size
    finalLot = MathFloor(finalLot / lotStep) * lotStep;

    Print("RiskLotCalc | Risk: ", riskPerTrade,
          " | SL pips: ", slPips,
          " | rawLot: ", rawLot,
          " | finalLot: ", finalLot);

    return finalLot;
}
Files:
 

Your issue is likely due to:


Incorrect pip value assumption — pipValue = 10.0 is hardcoded and only valid for some symbols like EURUSD.
Wrong pip conversion — dividing by (_Point * 10) is not reliable across all instruments (e.g. gold, indices).


This causes wrong lot sizes (like 0.2 lots) during Market verification.


Fix:
Use dynamic pip value and correct pip calculation:

double CalculateRiskLot(double sl, double entry)
{
   double tickValue = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE);
   double tickSize  = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);
   double contractSize = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_CONTRACT_SIZE);

   double risk = AccountInfoDouble(ACCOUNT_BALANCE) * RiskPercent / 100.0;
   double slDistance = MathAbs(entry - sl);

   double pipValue = (tickValue / tickSize) * _Point;
   double lotValue = risk / (slDistance * pipValue);

   double minLot = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN);
   double stepLot = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_STEP);

   double lot = MathMax(minLot, lotValue);
   lot = MathFloor(lot / stepLot) * stepLot;
   lot = NormalizeDouble(lot, 2);

   return lot;
}

This handles different symbol types correctly and avoids Market rejection.