Heeeelp! heeeelp! - page 3

 
Everything works fine if i set a fixed lot size its fine but i want a dynamic lot size. So i thought out the above script but it does'nt work and i dont know the problem. @raptor i want to use $100 of the $1000 balance which i understand is 0.1 lot since my leverage is 1:100 but i want it dynamic so that if the system profits and balance becomes higher say new balance becomes $2000 i want it to now open trades with $200(0.2 lot) respecting the percentage i set i.e. 10%, 20% or any of balance/margin i set. @ onewithzachy ordersend is fine since it works if i set fixed lot size i.e.
double lots=0.1;
but when i try to dynamicise it like below it says wrong lot size. My account is micro and supports minimum 0.01 lot.
extern int LotPercentage=10; // use 10% of balance as lot size

int start()
{

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()*/

...

return 0;

}
Also this returns the same error while its even simpler
double lots;
double Balance=AccountBalance();
if(Balance<=500){lots=0.1;}                // If my account has $500 or less the lot will be 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;}                      // If account balance if over 10000 lot is 2

if(/*opening criteria met*/){
OrderSend(Symbol(),OP_BUY,lots,...)
}
Please read comments i have included in the code to understand better.
 

DO NOT DO THIS WITH REAL MONEY.

DO YOU WANT TO LOSE 10 % or OPEN POSITION WITH 10% ? (answer : the first one !)

double lots;                               // <<== value is zero
double Balance=AccountBalance();

if(Balance<=500){lots=0.1;}                // What the lots if Balance > 500 && <= 1000 ?

if(Balance<1500&&Balance>1000){lots=0.3;}  // read this carefully : if balance bigger than but not equal with 1000
                                           // AND balance also smaller but not equal than 1500.
                                           // Question : what's the lot if balance equal with 1000 and 1500 ?
 

I want to open position with 10% the same way someone can deposit $1000 in their account and open positions with 0.1 lot(10% if leverage is 1:100).

onewithzachy you are right i did modify it to the below and it worked but the strategy test came out poorer i guess its best to use fixed lots.

double Balance=AccountBalance();
if(Balance<=500||(Balance>500&&Balance<1000)){lots=0.1;}
if((Balance<=1500&&Balance>=1000)||(Balance>1500&&Balance<2000)){lots=0.3;}
if((Balance<=2500&&Balance>=2000)||(Balance>2500&&Balance<3000)){lots=0.5;}
if((Balance<=3500&&Balance>=3000)||(Balance>3500&&Balance<4000)){lots=0.7;}
if((Balance<=4500&&Balance>=4000)||(Balance>4500&&Balance<5000)){lots=0.9;}
if((Balance<=5500&&Balance>=5000)||(Balance>5500&&Balance<6000)){lots=1.1;}
if((Balance<=6500&&Balance>=6000)||(Balance>6500&&Balance<7000)){lots=1.3;}
if((Balance<=7500&&Balance>=7000)||(Balance>7500&&Balance<8000)){lots=1.5;}
if((Balance<=8500&&Balance>=8000)||(Balance>8500&&Balance<9000)){lots=1.7;}
if((Balance<=9500&&Balance>=9000)||(Balance>9500&&Balance<10000)){lots=1.9;}
if(Balance>10000){lots=2;} 
 
jameslarry:
Everything works fine if i set a fixed lot size its fine but i want a dynamic lot size. So i thought out the above script but it does'nt work and i dont know the problem. @raptor i want to use $100 of the $1000 balance which i understand is 0.1 lot since my leverage is 1:100 but i want it dynamic so that if the system profits and balance becomes higher say new balance becomes $2000 i want it to now open trades with $200(0.2 lot) respecting the percentage i set i.e. 10%, 20% or any of balance/margin i set. @ onewithzachy ordersend is fine since it works if i set fixed lot size i.e. but when i try to dynamicise it like below it says wrong lot size. My account is micro and supports minimum 0.01 lot. Also this returns the same error while its even simpler Please read comments i have included in the code to understand better.
I think you have a big misunderstanding of how things work . . . Margin requirement and Risk are not the same thing . . . if you create a position size based on a Margin requirement of $100 and your trade loses you can lose very much more, or less, than your $100 . . . Margin requirement changes with leverage . . . Risk does not.
 
No wait it did add some turbo i had tested it wrongly. It would be great if i could calculate it using one formula rather than tons of if statements. Is it possible to derive a formula?
 
ok risky in some situations e.g. in 2012 would have lost with turbo but gained without
 
Which is the safest way?
 
jameslarry:
No wait it did add some turbo i had tested it wrongly. It would be great if i could calculate it using one formula rather than tons of if statements. Is it possible to derive a formula?
Yes, plot your points on a graph and then you can work out a linear equation for it in the form y = mx + c
 
jameslarry:
Which is the safest way?
To do what . . . . you haven't actually explained what you want to do . . despite being asked specific questions . . . if you ignore questions that are asked so you can be helped then you will be ignore very quickly.
Reason: