Download MetaTrader 5

How to change a code to set up a start lots?

To add comments, please log in or register
Slawomir Dziegielewski
369
Slawomir Dziegielewski  
double getLots(double lt) 
  (
   double marginrequired = MarketInfo(Symbol(), MODE_MARGINREQUIRED);
   double freemargin = AccountFreeMargin();
   if(freemargin > (marginrequired * lt)) 
     {
    
       return(lt);
     } 
   double result = freemargin / marginrequired;
   result = MathFloor(result * 10) / 10;
   return(result);
  }

How to change this code to make a possibility to set up in parameters to change a starting lots size?
Marco vd Heijden
Moderator
6152
Marco vd Heijden  
Slawomir Dziegielewski:
double getLots(double lt) 
  (
   double marginrequired = MarketInfo(Symbol(), MODE_MARGINREQUIRED);
   double freemargin = AccountFreeMargin();
   if(freemargin > (marginrequired * lt)) 
     {
    
       return(lt);
     } 
   double result = freemargin / marginrequired;
   result = MathFloor(result * 10) / 10;
   return(result);
  }

How to change this code to make a possibility to set up in parameters to change a starting lots size?
bool runonce=0;// Flag
sinput double startlots=0.01;// Starting Lotsize
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
double getLots(double lt)
  {
   if(runonce==0)
     {
      result = startlots;
      runonce=1;
      return(result);
     }
   else if(runonce==1)
     {
      double marginrequired=MarketInfo(Symbol(),MODE_MARGINREQUIRED);
      double freemargin=AccountFreeMargin();
      if(freemargin>(marginrequired*lt))
        {

         return(lt);
        }
      double result=freemargin/marginrequired;
      result=MathFloor(result*10)/10;
      return(result);
     }
  }
//+------------------------------------------------------------------+

I take it literally.

Slawomir Dziegielewski
369
Slawomir Dziegielewski  
Marco vd Heijden:
I take it literally.

Thank you at start,

 

I get a error: 'startlots' - declaration without type

Slawomir Dziegielewski
369
Slawomir Dziegielewski  
Slawomir Dziegielewski:

Thank you at start,

 

I get a error: 'startlots' - declaration without type

but when put double I get a error:

'result' - undeclared identifier

Marco vd Heijden
Moderator
6152
Marco vd Heijden  
Slawomir Dziegielewski:

but when put double I get a error:

'result' - undeclared identifier

bool runonce=0;// Flag
sinput double startlots=0.01;// Starting Lotsize
//+------------------------------------------------------------------+

//+------------------------------------------------------------------+
double getLots(double lt)
  {
   if(runonce==0)
     {
      double result = startlots;
      runonce=1;
      return(result);
     }
   else if(runonce==1)
     {
      double marginrequired=MarketInfo(Symbol(),MODE_MARGINREQUIRED);
      double freemargin=AccountFreeMargin();
      if(freemargin>(marginrequired*lt))
        {

         return(lt);
        }
      double result=freemargin/marginrequired;
      result=MathFloor(result*10)/10;
      return(result);
     }
  }
//+------------------------------------------------------------------+
Osama Shaban
1584
Osama Shaban  

If you always want to use same lot size then do the following ...

input StartLots = 0.01;

 then, 

double getLots(double lt) 
  (
   double marginrequired = MarketInfo(Symbol(), MODE_MARGINREQUIRED);
   double freemargin = AccountFreeMargin();
   if(freemargin > (marginrequired * lt)) 
     {
    
       return(StartLots);
     } 
   double result = freemargin / marginrequired;
   result = MathFloor(result * 10) / 10;
   return(StartLots);
  }

 In this code, you always enforce the getLots( ) function to return same StartLots value !!!.

I believe it will work !. 

Slawomir Dziegielewski
369
Slawomir Dziegielewski  
Osama Shaban:

If you always want to use same lot size then do the following ...

 then, 

 In this code, you always enforce the getLots( ) function to return same StartLots value !!!.

I believe it will work !. 

Yes it work fine! 

 

Great thank you guys!

Good Luck Guys! 

To add comments, please log in or register