Download MetaTrader 5

calculating lots

To add comments, please log in or register
Are you accustomed to using the standard library? MQL5 has one!
theDUDE
43
theDUDE 2015.12.29 00:06 
//+------------------------------------------------------------------+
//| volume                                                           |
//+------------------------------------------------------------------+
double volume()
  {
   Lots=AccountInfoDouble(ACCOUNT_MARGIN_FREE)/8000;
   Lots=MathMin(15,MathMax(0.1,Lots));
   Lots=NormalizeDouble(Lots,2);
   return(Lots);

  }

 

 

I'm just trying to figure out what exactly is happening in the above code segment. 

Why is the free margin divided by 8000?

Is line two calculating the maximum amount of "0.1" lots to a maximum of 15?

Why is my lot size 0.1? 

 

Marco vd Heijden
Moderator
4701
Marco vd Heijden 2015.12.29 08:51  

It first calculates a percentage of ACCOUNT_MARGIN_FREE by dividing it with 8000.

Then it calculates min and max value to keep it between the bandwidth.

Then it normalizes to a 2 digit double and returns the result.

It's one of the ways to get to a dynamic lot size, if the account grows, lotsize is going to increase, and if it shrinks, lotsize will also lower.

Like an automatic gearbox.

theDUDE
43
theDUDE 2015.12.31 03:47  
Another thing I was wondering is how leverage is calculated. Is this something the EA does, or does the broker set the leverage? When I run a back-test my profit level stays the same no matter what I set the leverage to.
Alain Verleyen
Moderator
30737
Alain Verleyen 2016.01.01 20:59  
theDUDE:
Another thing I was wondering is how leverage is calculated. Is this something the EA does, or does the broker set the leverage? When I run a back-test my profit level stays the same no matter what I set the leverage to.

Leverage is set by the broker. You can eventually request them to change it.

See also here.

To add comments, please log in or register