lotsi = MathCeil(AccountBalance()*risk / 10000) / 10;
Must use lotstepdouble lotStep = MarketInfo(Symbol(), MODE_LOTSTEP); //IBFX= 0.01 lotsi=MathCeil(lotsi/lotStep)*lotStep;
for(cnt = 0; cnt < OrdersTotal(); cnt++) { OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES); //---- if(OrderSymbol() == Symbol()) OpenOrders++; }
Always count down when modifying/deleting/closing in the presence of multiple orders (multiple charts.) Always test return codes.for(pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() ){ // and my pair. OpenOrders++; }
if(Symbol() == "EURUSD") PipValue = EURUSDPipValue;
Don't hard code values.double PointValuePerLot() { // Value in account currency of a Point of Symbol. /* In tester I had a sale: open=1.35883 close=1.35736 (0.00147) * gain$=97.32/6.62 lots/147 points=$0.10/point or $1.00/pip. * IBFX demo/mini EURUSD TICKVALUE=0.1 MAXLOT=50 LOTSIZE=10,000 * IBFX demo/standard EURUSD TICKVALUE=1.0 MAXLOT=50 LOTSIZE=100,000 * $1.00/point or $10.00/pip. * * https://forum.mql4.com/33975 CB: MODE_TICKSIZE will usually return the * same value as MODE_POINT (or Point for the current symbol), however, an * example of where to use MODE_TICKSIZE would be as part of a ratio with * MODE_TICKVALUE when performing money management calculations which need * to take account of the pair and the account currency. The reason I use * this ratio is that although TV and TS may constantly be returned as * something like 7.00 and 0.00001 respectively, I've seen this * (intermittently) change to 14.00 and 0.00002 respectively (just example * tick values to illustrate). */ return( MarketInfo(Symbol(), MODE_TICKVALUE) / MarketInfo(Symbol(), MODE_TICKSIZE) ); // Not Point. }
if(mode == OP_BUY) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), slippage, Blue); //---- if(mode == OP_SELL) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), slippage, Red);
The calls are the same so you don't need the if's. EAs must adjust to 5 digit brokers (TP, SL, AND slippage)//++++ These are adjusted for 5 digit brokers. double pips2points, // slippage 3 pips 3=points 30=points pips2dbl; // Stoploss 15 pips 0.0015 0.00150 int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips) int init(){ if (Digits == 5 || Digits == 3){ // Adjust for five (5) digit brokers. pips2dbl = Point*10; pips2points = 10; Digits.pips = 1; } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; } // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
if(OpenOrders >= MaxTrades) ContinueOpening = False; else ContinueOpening = True;
Simplify code where possiblebool ContinueOpening = OpenOrders < MaxTrades;
if(OrderClosePrice() < OrderOpenPrice()) Profit = Profit - (OrderOpenPrice() - OrderClosePrice())*OrderLots() / Point; //---- if(OrderClosePrice() > OrderOpenPrice()) Profit = Profit + (OrderClosePrice() - OrderOpenPrice())*OrderLots() / Point;
SimplifyProfit+=OrderProfit();
mylotsi = NormalizeDouble(mylotsi*1.5, 1); else mylotsi = NormalizeDouble(mylotsi*2, 1);
These assume lot step = 0.1; fail for 0.2double lotStep = MarketInfo(Symbol(), MODE_LOTSTEP); //IBFX= 0.01 mylotsi=MathCeil(mylotsi/lotStep)*lotStep;
if(mylotsi > 100) mylotsi = 100;
Don't hard code values.double maxLot = MarketInfo(Symbol(), MODE_MAXLOT ); //IBFX=50.00 if (mylotsi > maxLot) mylotsi = maxLot;
OrderSend(Symbol(), OP_BUY, mylotsi, BuyPrice, slippage, sl, tp, NULL, 0, 0, Blue);
Five digit adjustments already mentioned. On ECN brokers you must open the order and THEN set the tp/sl
I hope the member fully appreciates the effort involved & the quality of WHRoeders reply...
-BB-
Thank You very much, will try it!!!
-
Must use lotstep
-
Always count down when modifying/deleting/closing in the presence of multiple orders (multiple charts.) Always test return codes.
-
Don't hard code values.
-
The calls are the same so you don't need the if's. EAs must adjust to 5 digit brokers (TP, SL, AND slippage)
-
Simplify code where possible
-
Simplify
-
These assume lot step = 0.1; fail for 0.2
-
Don't hard code values.
-
Five digit adjustments already mentioned. On ECN brokers you must open the order and THEN set the tp/sl
So I've made changes and I've tried to comply the code, but there are 8 warnings and 8 failure. I've tried to make correction by myself, but I've got more failure and warnings then before. I've atached the new version of the code with the chages you adviced, can u correct one more time, please?!!!
I hope the member fully appreciates the effort involved & the quality of WHRoeders reply...
-BB-
Seriously! That was at least an hour of work. Way to support the community, WHRoeder.
else // then is mini if(mm != 0) double lotStep = MarketInfo(Symbol(), MODE_LOTSTEP); //IBFX= 0.01 lotsi=MathCeil(lotsi/lotStep)*lotStep; else lotsi = Lots;
Is it me or are we missing curly braces in this bit of code? Try this:
else // then is mini if(mm != 0) { double lotStep = MarketInfo(Symbol(), MODE_LOTSTEP); //IBFX= 0.01 lotsi=MathCeil(lotsi/lotStep)*lotStep; } else lotsi = Lots;
MarketInfo(Symbol(), MODE_TICKSIZE) ); // Not Point.
What's the difference for example on eurusd?

- 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 I need a helpt to adopt this code (see below) to a micro account, that means 1 Lot = 10 Dollars and with 5 digits after point, The EA starts the initial trade with 0.01 Lot.
The Point is that after the firts trade, it doesnt want to open the second one, if the first one is in MINUS. The failure masage is "invalide lots amount for OderSend function"
Can anybody help me?