# Heeeelp! heeeelp!

117

Hi still on the lot issue, ive tried a script here that i thought of but strategy testing it gives an error wrong lot size. I dont know wether history data doesnt support some functions or what. The script is for EURUSD only. What am i doing wrong or is it a strategy tester problem?

```extern int LotPercentage=10; // use 10% of balance as lot size

double LotInBalance=(LotPercentage/100)*AccountBalance(); // find the amount that is 10% of balance lets assume its \$1000
double LotUnits=LotBalance*AccountLeverage(); // multiply this 10% balance(\$100) by leverage to get lot units
double lots=NormalizeDouble((LotUnits/100000),2); // expected to return 0.1
/* divide this lot units by 100,000(standard lot size units) and normalize to 2 decimal places to get something like 0.1 if account balance is say \$1000 for use in ordersend()*/

```
2271

jameslarry:

Hi still on the lot issue, ive tried a script here that i thought of but strategy testing it gives an error wrong lot size. I dont know wether history data doesnt support some functions or what. The script is for EURUSD only. What am i doing wrong or is it a strategy tester problem?

```extern int LotPercentage=10; // use 10% of balance as lot size

double LotInBalance=(LotPercentage/100)*AccountBalance(); // find the amount that is 10% of balance lets assume its \$1000
double LotUnits=LotBalance*AccountLeverage(); // multiply this 10% balance(\$100) by leverage to get lot units
double lots=NormalizeDouble((LotUnits/100000),2); // expected to return 0.1
/* divide this lot units by 100,000(standard lot size units) and normalize to 2 decimal places to get something like 0.1 if account balance is say \$1000*/```

You don't need help, you're already got one (https://www.mql5.com/en/forum/140034) !. Yet you screw up !

117

Hi the code i got there brings a "zero divide" error and the other is big and untested just want something simple like the script i have. Can you check my script and tell me where im going wrong? If balance is \$1000 and leverage is 1:100 i want it to trade with 0.1 lot just that simple but its proving a headache. Once i calculate (10/100)*AccountBalance() to get \$100 how do i get it to 0.1 for OrderSend sake. Also i dont want a script that manages stop loss for me just the lots part.
Moderator
18018

jameslarry:
Hi the code i got there brings a "zero divide" error and the other is big and untested
So test it . . . you want other people to write your code for you and test it too ??
117

Yes im just asking what im doing wrong in my code. Im also testing the code onewitch gave me but it seems to do something with SL which i dont want the script to do
Moderator
18018

jameslarry:
Yes im just asking what im doing wrong in my code. Im also testing the code but it seems to do something with SL which i dont want the script to do
At what point in a losing trade do you want to experience your chosen max loss ?
Moderator
18018

117

Hi i also tried this but it gave the same error as above maybe AccountBalance() and AccountFreeMargin() dont work on strategy tester here is the code because im starting with a balance of \$3000 in the test but it keeps giving error 4051 invalid lots amount. And if i may ask if i have \$3000 would the value of AccountBalance() be 3000 or something else. Sorry if im bugging.
```double Balance=AccountBalance();
if(Balance<=500){lots=0.1;}
if(Balance<1500&&Balance>1000){lots=0.3;}
if(Balance<2500&&Balance>2000){lots=0.5;}
if(Balance<3500&&Balance>3000){lots=0.7;}
if(Balance<4500&&Balance>4000){lots=0.9;}
if(Balance<5500&&Balance>5000){lots=1.1;}
if(Balance<6500&&Balance>6000){lots=1.3;}
if(Balance<7500&&Balance>7000){lots=1.5;}
if(Balance<8500&&Balance>8000){lots=1.7;}
if(Balance<9500&&Balance>9000){lots=1.9;}
if(Balance>10000){lots=2;}
```
2271

jameslarry:
Hi i also tried this but it gave the same error as above maybe AccountBalance() and AccountFreeMargin() dont work on strategy tester here is the code because im starting with a balance of \$3000 in the test but it keeps giving error 4051 invalid lots amount. And if i may ask if i have \$3000 would the value of AccountBalance() be 3000 or something else. Sorry if im bugging.

Oh dear,

You get that error, because ...you did not calculate the cost to open that amount of lot. Read your other thread https://www.mql5.com/en/forum/140034 and https://www.mql5.com/en/forum/140034/page2#649957

117

how do i correct it and what does AccountBalance() return is it its value in \$ or other units.
2271

jameslarry:
how do i correct it and what does AccountBalance() return is it its value in \$ or other units.

It return in your Account currency. I gave you attachment in here https://www.mql5.com/en/forum/140034

How do you correct it use the lot calculation correctly like this one https://www.mql5.com/en/forum/140034

12345