Dynamic Lots

 

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?

 

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

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

is not the same.

 

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);
 
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;
 
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);

 
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;
 
Ndumiso Mavuso:

right
Reason: