Even if I don't share your approach, I think this might make more sense ?
double step = 100; // the 100 is the step you want to go double mulu = AccountBalance() / step; double muls = AccountBalance() % step; if (mulu >= 1 && muls == 0) { double lots = mulu * 0.05; }
This is not tested yet:
100 / 100 = 1
100 % 100 = 0
cash = 100 ; lots = 1 * 0.05 = 0.05;
101 / 100 = 1.01
101 % 100 = 1
cash = 101 ; lot's = 1 * 0.05 = 0.05; because muls != 0;
...
200 / 100 = 2
200 % 100 = 0
cash = 200 ; lots = 2 * 0.05 = 0.10;
201 / 100 = 2.01
201 % 100 = 1
cash = 201 ; lot's = 2 * 0.05 = 0.10; because muls != 0;
... and so on. Everything below 100 will be ignored. There you can set a default lot's size if you wish.
Edit: There's still a problem in case you earn more money e.g. from 102 USD -> 322 USD in one step. In this case no lot's being added because the muls doesn't reach the clear 0. But at least this mechanism can give you a hint in howto calculate this stuff on the go, rather than if/else'ing the hell out of it.
double lots=MathFloor(AccountBalance()/100)*0.05;You may also need to make provision for minimum and maximum lot size
I made it this way, with MM.
extern double Risk_P=5; extern double Max_Lots=7; double Lots; extern int StopLoss = 20; double GetLots() { Lots=NormalizeDouble( (AccountBalance()*(Risk_P/(1000*StopLoss))),2 ); if(Lots<0.01) Lots=0.01; if(Lots>Max_Lots) Lots=Max_Lots; return (Lots); }

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello!
Is there any better/smarter way to increase/decrease lot size every 100$ by 0.05lot?
For now I have this, but I don't like it. Any better way?
Thank you!