Calculation of Lotsize

 
input double      mRisk       = 2;              // MM Risk
input int         SL          = 175;            // Stop Loss (Points)

//+------------------------------------------------------------------+
//| Money Management                                                 |
//+------------------------------------------------------------------+
double MM()
  {
//---

   double   Balance   = AccountInfoDouble(ACCOUNT_BALANCE),
            MinLot    = SymbolInfoDouble(_Symbol, SYMBOL_VOLUME_MIN),
            TickValue = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE);

   int      mxLot = (int) MathRound(Balance * mRisk / TickValue / SL);

   double   LotSize = mxLot * MinLot;

   if(LotSize > MinLot) return(LotSize);

//---
   return(MinLot);
  }


My balance is 1950 SGD.

My EA opened some trades on EURGBP today and the lotsize is 0.01 and the next trade is 0.13.

Any idea what happened?

During backtesting, I did not encounter this issue at all.

 
Your topic has been moved to the section: Expert Advisors and Automated Trading — Please consider which section is most appropriate — https://www.mql5.com/en/forum/443428#comment_49114884
 

Consider using OrderCalcProfit instead.

Forum on trading, automated trading systems and testing trading strategies

SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_VALUE) sometimes zero

Fernando Carreiro, 2022.08.23 17:41

You can! These are the steps I take. I supply the function with a lot size equal to the “Max Lot Size” allowed for the symbol in question, then calculate the ratio needed to achieve the fractional risk that I wish to apply, to get the correct volume for the order. I then align that with the “Lot Step” and finally check it against both the maximum and minimum allowed lots for the symbol.

The reason I use the “maximum” lots instead of just “1.0” lots as a reference value is because there is no guarantee that the value of 1.0 is within the minimum and maximum values allowed. Given that using 1.0, or the maximum, gives equivalent results anyway (by using the ratio method), I choose to use the “max lots” as the reference point which also offers the most precision for the calculation.

Something like this ...

// This code will not compile. It is only a example reference

if( OrderCalcProfit( eOrderType, _Symbol, dbLotsMax, dbPriceOpen, dbPriceStopLoss, dbProfit ) )
{
   dbOrderLots = fmin( fmax( round( dbRiskMax * dbLotsMax / ( -dbProfit * dbLotsStep ) )
               * dbLotsStep, dbLotsMin ), dbLotsMax ); 
      
   // the rest of the code ...
};
 
Fernando Carreiro #:

Consider using OrderCalcProfit instead.

Thanks a lot. I managed to figure out and uses OrderCalcProfit instead

Documentation on MQL5: Trade Functions / OrderCalcProfit
Documentation on MQL5: Trade Functions / OrderCalcProfit
  • www.mql5.com
OrderCalcProfit - Trade Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Is there a similar function in MT4?
 
Dua Yong Rew #: Is there a similar function in MT4?

No, it has to be calculated.

Was your original question about MQL4 only, or is it about both MQL4 and MQL5?

 

Hi

I've tried using OrdercalcProfit but it seems that the first order is always giving me 0.01 lotsize

Subsequent trades on other pairs are behaving normally

Eg. Today, my first trade is on EURAUD and is 0.01, other pairs all ok

Fyi. My deposit currency is SGD

Does OrdercalcProfit needs to sync with some SGD pairs first?

Reason: