# lot size linked to Account Balance

195

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

D.

86

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...

D.

This line has double = (comparing not assigning)

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

//Try
lotsize = NormalizeDouble ((AccountBalance()/10000),1);
```
Moderator
18019

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
Moderator
10369

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...

D.

``` double lotsize;

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

```double ab =AccountBalance();
double lotsize;
if(ab >= 1500 && ab < 2500) lotsize = 0.2;```
3243

B.T.W i think using AccountBalance() is wrong u have to use AccountEquity() instead
Moderator
32008

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...

D.

```lots=0.2+MathFloor((balance-1500)/1000)/10;
```
195

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.