Mql5 Lot calculation Bug?

 
         double loss;
         loss = -m_account.OrderProfitCheck(_Symbol, ORDER_TYPE_BUY, 1.0, symb.ask, sl);
         double stepvol = symb.volume_step;
         lot = MathFloor(m_account.Equity() * Percent_loss / loss / 100.0 / stepvol) * stepvol; // Percent loss is 5%

Hello

I'm using the above code to calculate lot sizes.

can someone please explain to me why the percentage change on trade outcomes are not 5% or even equal or almost equal at least?


is there a way to make them exactly the percentage I want? say 5% should be exactly 5% or close?


Is there a limitation?


Thank you 

 
Because the % displayed is from the price not from money.
Beside that I doubt your calculation is correct but it's hard to check without full code and values.
 
Alain Verleyen #:
Because the% displayed is from the price not from money.
Beside that I doubt your calculation is correct but it's hard to check with full code and values.
😂😂😂😂 I feel so stupid

Ok Alain but still, how come the profits & losses are not equal? Yes I'm considering slippages in there too🤔

What's missing on the code there, that you'd like me to add?
 
Take the debugger and check the calculation.
 
Ndumiso Mavuso #:
😂😂😂😂 I feel so stupid

Ok Alain but still, how come the profits & losses are not equal? Yes I'm considering slippages in there too🤔

Why do you want them to be equals when the volume and distance (SL/TP) are different ?

What's missing on the code there, that you'd like me to add?
As I said without full code and values used it's hard to say. What is done within OrderProfitCheck(), what are the values of SL ? of loss ?
 
Carl Schreiber #:
Take the debugger and check the calculation.

Return same value with that done on live trade


 

You can find some useful code here

https://www.mql5.com/en/code/28029

Forex Calculators
Forex Calculators
  • www.mql5.com
Margin Calculator, Point Value Calculator, Position Size Calculator, Profit Calculator and Swap Calculator.