Rounding Down Account Equity to Nearest 100

 

Hello,


I am still learning MQL4.


I have written this code as part of my EA.


   double maxLossDollar = (MathRound(AccountEquity()/100) * 100) * maxLossPerc;

   Alert ("maxLossDollar: " + maxLossDollar);


The above code Rounds up to nearest 100 when the balance is between x50.01 to x99.99.

Any guidance to ALWAYS round it down to nearest 100?


So 100.01 to 199.99 is always 100 and so on.

Documentation on MQL5: Math Functions / MathFloor
Documentation on MQL5: Math Functions / MathFloor
  • www.mql5.com
MathFloor - Math Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Devbrat Daga:

Hello,


I am still learning MQL4.


I have written this code as part of my EA.


   double maxLossDollar = (MathRound(AccountEquity()/100) * 100) * maxLossPerc;

   Alert ("maxLossDollar: " + maxLossDollar);


The above code Rounds up to nearest 100 when the balance is between x50.01 to x99.99.

Any guidance to ALWAYS round it down to nearest 100?


So 100.01 to 199.99 is always 100 and so on.

MathMax(MathFloor(AccountEquity() / 100) * 100, 100)
 

Alexandre Borela #:


Thanks a lot Alexandre. This works like a charm. Appreciate the time taken to reply.