lot size linked to Account Balance

 

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.

 
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);
 
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
 
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;
 
B.T.W i think using AccountBalance() is wrong u have to use AccountEquity() instead
 
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.
 

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.

Reason: