extern double Lots = 0.1; extern double MinLot = 0.1; extern double MaxLot = 5.0; extern int LotPrec = 1; extern bool DynamicLot = false; extern double LotStep = 0.1; extern double BalanceStep = 500; double GetLots() { double lots = Lots; if (DynamicLot) { lots = NormalizeDouble(LotStep*AccountBalance()/BalanceStep, LotPrec); } lots = MathMax(lots, MinLot); lots = MathMin(lots, MaxLot); return (lots); }
Don't hard code numbers (lotPrec/MaxLot...). LotPrec assumes lotStep=0.1; can only be adjusted 1.0 0.1 0.01, fails for 0.5 for example.
double lotStep = MarketInfo(Symbol(), MODE_LOTSTEP), //IBFX= 0.01 MaxLot = MarketInfo(Symbol(), MODE_MAXLOT ); //IBFX=50.00 MinLot = MarketInfo(Symbol(), MODE_MINLOT), lots = MathCeil(LotStep*AccountBalance()/BalanceStep/lotStep)*lotStep; } lots = MathMax(lots, MinLot); lots = MathMin(lots, MaxLot);
double LotOptimized() { int Percent =5; // % of free margin double Free =AccountFreeMargin(); // Free margin double One_Lot=MarketInfo(Symbol(),MODE_MARGINREQUIRED); // 1 lot price double Step =MarketInfo(Symbol(),MODE_LOTSTEP); // Size step changed double Lots_New=MathFloor(Free*Percent/100/One_Lot/Step)*Step;Is it ok. 5 percent of balance in each deal. Thx

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
I would like to set the robot to follow the following procedure:
- for each entrance to use a certain percentage, inserted in advance, of the balance as a margin.
For instance:
1000 $ x 5 % = 50 $ margin
Until now, i have develop the following code.