Download MetaTrader 5

Dynamic Lots

To add comments, please log in or register
Ndumiso Mavuso
4627
Ndumiso Mavuso  

This formula works very well on micro lots. example if account balance is $20*RiskPer(0.0003) =0.006, when Normilized to 2 decimals = 0.01. So for $20 balance lots will 0.01, $50 balance will be 0.02 and so on.

   if(DynamicLotSize == true)
   {
   double risk=(AccountEquity() * RiskPer);
   
   double lot=NormalizeDouble(risk,2);
   }
   else lot=Lots;

The Problem is when it get to mini and Standard Lots. first $200 * RiskPer = 0.06 and its 2 decimals because of Normalized BUT it must  be rounded to 0.10 and

on Standard Lots, $2000 * RiskPer = 0.60 and should be rounded to 1.00.

Any Idea How I solve this?

Ndumiso Mavuso
4627
Ndumiso Mavuso  

I finally did this:

if(DynamicLotSize == true)
   {
   double risk=(AccountEquity() * RiskPer);
   
   if(AccountEquity()<500)
   {
   double lot=NormalizeDouble(risk,2);
   }
   if (AccountEquity()>=500 && AccountEquity()<2000)
   {
          lot=NormalizeDouble(risk,1);
   }
   if(AccountEquity()>=2000)
   {
          lot=NormalizeDouble(risk,0);
   }
   }
   else lot=Lots;

For anyone who encounter same problem can copy OR if you can improve please do

Marco vd Heijden
Moderator
5524
Marco vd Heijden  
lot=AccountBalance()/X;
Ndumiso Mavuso
4627
Ndumiso Mavuso  
Marco vd Heijden:
Thanks for the reply but that is the same with code here, the RiskPer is the same as /x;
Marco vd Heijden
Moderator
5524
Marco vd Heijden  

is not the same.

Siti Latifah
11740
Siti Latifah  

you need marketinfo

see below..


double lotDigits;

double LotStep=MarketInfo(Symbol(),MODE_LOTSTEP);

if(LotStep==0.01) lotDigits=2;

if(LotStep==0.1) lotDigits=1;


lot=NormalizeDouble(risk,lotDigits);
Ndumiso Mavuso
4627
Ndumiso Mavuso  
Siti Latifah:

you need marketinfo

see below..


double lotDigits;

double LotStep=MarketInfo(Symbol(),MODE_LOTSTEP);

if(LotStep==0.01) lotDigits=2;

if(LotStep==0.1) lotDigits=1;


Thank You Sit Latifah I did not realy understand MODE_LOTSTEP on the Book But thanks to you I do now, However I will still use this code of mine until it gives me problems on my current Project

   if(DynamicLotSize == true)
   {
   double risk=(AccountEquity() * RiskPer);
   
   if(AccountEquity()<500)
   {
   double lot=NormalizeDouble(risk,2);
   }
   if (AccountEquity()>=500 && AccountEquity()<2000)
   {
          lot=NormalizeDouble(risk,1);
   }
   if(AccountEquity()>=2000)
   {
          lot=NormalizeDouble(risk,0);
   }
   if(lot>100)
   {
   lot=100;
   }
   }
   else lot=Lots;
Siti Latifah
11740
Siti Latifah  
Ndumiso Mavuso:

Thank You Sit Latifah I did not realy understand MODE_LOTSTEP on the Book But thanks to you I do now, However I will still use this code of mine until it gives me problems on my current Project

your problem at lotdigits..


see this


double lotDigits;

double LotStep=MarketInfo(Symbol(),MODE_LOTSTEP);

if (LotStep==0.01) lotDigits=2;

if (LotStep==0.1) lotDigits=1;

lot=NormalizeDouble(risk,lotDigits);

Ndumiso Mavuso
4627
Ndumiso Mavuso  
Siti Latifah:

your problem at lotdigits..


see this


double lotDigits;

double LotStep=MarketInfo(Symbol(),MODE_LOTSTEP);

if (LotStep==0.01) lotDigits=2;

if (LotStep==0.1) lotDigits=1;

lot=NormalizeDouble(risk,lotDigits);


   if(DynamicLotSize == true)
   {
   double risk=(AccountEquity() * RiskPer);
   
   double Lotstep=MarketsInfo(Symbol(),MODE_LOTSTEP);
   
   if(Lotstep==0.01)lotD=2;
   if(Lotstep==0.1)lotD=1;
   if(Lotstep==1)lotD=0; //Do not know if this is even needed

   double lot=NormalizeDouble(risk,lotD);
   }
   else lot=Lots;
Siti Latifah
11740
Siti Latifah  
Ndumiso Mavuso:

right
To add comments, please log in or register