Calculate lot for expert advisor

 

Hello,

I'm struggling with something stupid here, don't know what I'm doing wrong.  

I want to trade one lot for every 10000 I have in my account.  So if I have 15000 in my account, the lot  traded should be 15000/10000, and that is 1.5 lots.

This worked in MQL4, but in MQL5 it won't work.  I even normailzed the double to zero decimal places, but it still won't work.  If I don't give it a solid interger value the order won't go through.  Any idea why this won't work ?

Thanks

double ab = AccountInfoDouble(ACCOUNT_BALANCE);

lot_size = ab / 10000;
 
Saidar:

Hello,

I'm struggling with something stupid here, don't know what I'm doing wrong.  

I want to trade one lot for every 10000 I have in my account.  So if I have 15000 in my account, the lot  traded should be 15000/10000, and that is 1.5 lots.

This worked in MQL4, but in MQL5 it won't work.  I even normailzed the double to zero decimal places, but it still won't work.  If I don't give it a solid interger value the order won't go through.  Any idea why this won't work ?

Thanks

 

Why do you want to give it a "solid integer value" if the result (e.g. 1.5) is of double type?
 
You should declare lot_size in double type. Like this:


void OnStart()
  {
   double ab=AccountInfoDouble(ACCOUNT_BALANCE);
   double lot_size=ab/10000;

   Print("lot_size=",lot_size);
  }
See Typecasting
 
Hey, thanks for the help.  I know I must declare the lot size variable as double, I just showed you an example of how I coded it, it was not the exact code.  The fact is it won't work, even the code you now gave me won't work.  At least not in the strategy tester