Download MetaTrader 5
To add comments, please log in or register
They are already making profit from their signals. Publish your signal and join them!
Dannoo007
195
Dannoo007 2014.02.24 21:48 

Hello forum,

I am trying to write this simple "code" to link lot size to Account Balance, for example, if balance is between 1500 - 2499 = lotzise 0.2, 2500 - 3499 = lotzise 0.3, etc

So far I got this (see below) - within Start ( ), with the straightforward logic of simply "rounding" the proportion, also with the option to "override" it. Still, it returns lotsize = 0.

I'm obviously missing something...

 double lotsize;
         
   if (LotSizeOverrideON == false) {
      lotsize == NormalizeDouble ((AccountBalance()/10000),1);
      }
    	
   if (LotSizeOverrideON == true) lotsize = LotSizeOverride;

Many thanks in advance!

D.

Xennon
84
Xennon 2014.02.24 22:04  
Dannoo007:

Hello forum,

I am trying to write this simple "code" to link lot size to Account Balance, for example, if balance is between 1500 - 2499 = lotzise 0.2, 2500 - 3499 = lotzise 0.3, etc

So far I got this (see below) - within Start ( ), with the straightforward logic of simply "rounding" the proportion, also with the option to "override" it. Still, it returns lotsize = 0.

I'm obviously missing something...

Many thanks in advance!

D.

This line has double = (comparing not assigning)

lotsize == NormalizeDouble ((AccountBalance()/10000),1);

//Try
lotsize = NormalizeDouble ((AccountBalance()/10000),1);
Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.02.24 22:16  
xennon:

This line has double = (comparing not assigning)

That won't work correctly either, the position size (lotsize) has to be a multiple of MODE_LOTSTEP, greater than or equal to MODE_MINLOT and smaller than or equal to MODE_MAXLOT
Keith Watford
Moderator
7983
Keith Watford 2014.02.24 22:52  
Dannoo007:

Hello forum,

I am trying to write this simple "code" to link lot size to Account Balance, for example, if balance is between 1500 - 2499 = lotzise 0.2, 2500 - 3499 = lotzise 0.3, etc

So far I got this (see below) - within Start ( ), with the straightforward logic of simply "rounding" the proportion, also with the option to "override" it. Still, it returns lotsize = 0.

I'm obviously missing something...

Many thanks in advance!

D.


 double lotsize;
         
   if (LotSizeOverrideON == false) {
      lotsize == NormalizeDouble ((AccountBalance()/10000),1);
      }

If your account balance is 1,500 your code will return 0.1

This will meet your requirements

double ab =AccountBalance();
double lotsize;
if(ab >= 1500 && ab < 2500) lotsize = 0.2;
qjol
3243
qjol 2014.02.25 00:03  
B.T.W i think using AccountBalance() is wrong u have to use AccountEquity() instead
Alain Verleyen
Moderator
28651
Alain Verleyen 2014.02.25 00:13  
Dannoo007:

Hello forum,

I am trying to write this simple "code" to link lot size to Account Balance, for example, if balance is between 1500 - 2499 = lotzise 0.2, 2500 - 3499 = lotzise 0.3, etc

So far I got this (see below) - within Start ( ), with the straightforward logic of simply "rounding" the proportion, also with the option to "override" it. Still, it returns lotsize = 0.

I'm obviously missing something...

Many thanks in advance!

D.

lots=0.2+MathFloor((balance-1500)/1000)/10;
Don't forgot to follow RaptorUK advice though.
Dannoo007
195
Dannoo007 2014.02.25 11:53  

Hey all!

Thanks a lot everyone, angevoyageur's version is spot on! MathFloor function is key, I thought NormalizeDouble "rounds" the numbers, it looks like it only deletes digits actually..

GumRai, I also did that but I was looking at something.. more "elegant" : ) Qjol: Correct, only that using Balance is a bit more prudent though...Also good to know now the difference between "assigning" and "comparing" ... [blush]

Cheers!

D.

/
To add comments, please log in or register