https://www.mql5.com/en/forum/129818
https://www.mql5.com/en/forum/129818
(try or check GetastError())
A) I don't like your new bar check
//trade on new bar if(Volume[0]<10 && Bars>6)
B) I don't like your failure to check return codes from Order... functions
C) I don't like the way that you assume all orders are from your EA. Consider using Magic Numbers
D) I don't like your hard coded 3 in the Order... functions. For a 3/5 digit broker, such a low number could cause problems; make it a variable (maybe extern).
But please don't take these comments personally!
- Those+
if(OrdersTotal()>0) { for(j=0;j<OrdersTotal();j++) { OrderSelect(j,SELECT_BY_POS,MODE_TRADES); if(OrderType()==OP_SELL) { OrderClose(OrderTicket(),OrderLots(),Ask,3,White); } } }
You MUST count down when closing in the presence of multiple order (multiple charts) and always check return codes. Must only close order on that chart, must use magic number. No need for the if(OrderTotal()>0), no order the for() does nothingfor(pos = OrdersTotal()-1; pos >= 0 ; pos--) if ( OrderSelect(pos, SELECT_BY_POS) // Only my orders w/ && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() && OrderType() == OP_SELL){ // and my pair. OrderClose(OrderTicket(),OrderLots(),Ask,3,White); }
- On a 5 digit broker you must adjust TP, SL, AND slippage. On an ECN broker you must send the order, then set TP/SL.
//++++ 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
- Always check return codes
int ticket=OrderSend(...) if (ticket < 0) Alert("OrderSend failed: ",GetLastError());
//trade on new bar if(Volume[0]<10 && Bars>6)
Volume is unreliable and that won't be a new bar for v=2 .. v=9, Always use time.int start(){ static datetime Time0; if (Time0 == Time[0]) return(0); Time0 = Time[0];
- Those+
-
You MUST count down when closing in the presence of multiple order (multiple charts) and always check return codes. Must only close order on that chart, must use magic number. No need for the if(OrderTotal()>0), no order the for() does nothing
- On a 5 digit broker you must adjust TP, SL, AND slippage. On an ECN broker you must send the order, then set TP/SL.
- Always check return codes
-
Volume is unreliable and that won't be a new bar for v=2 .. v=9, Always use time.
I understand many things seeing your examples, thank you.
But can you explain me the meaning of Digits.pips and Slippage.Pips in this code?
//++++ 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
Can you also tell me how to trade in a particular hour and minute of the day?
Thanks in advance.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi all,
I wrote a simple EA on the MA example provide by Metaquote. The problem is that it works fine in backtesting, but when I put it on a char don't open any trade.
I'm sure that all settings, like "Allow trade", or something else is checked. Can someone help me?
Thanks.
The core of the code is: