Just one little thing
if(Trade>0){ err=0; GetLastError(); RefreshRates(); if(StopLoss!=0){sl = nd(Ask+StopLoss*Point*mno);}else{sl=0;} if(TakeProfit!=0){tp =nd(Bid-TakeProfit*Point*mno);}else{tp=0;} err = OrderSend(Symbol(), OP_SELL, TradingLot, nd(Bid), slp*mno, /*sl*/0, /*tp*/0, comm, MagicNumber, 0, GetOrdCl(OP_SELL) ); if(err!=-1)if(OrderSelect(err,SELECT_BY_TICKET)) OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,GetOrdCl(OP_SELL)); if(err>0){ Alert("Opened order ",GetNameOP(OP_SELL)); }else{ Fun_Error(GetLastError()); } } } } } } }
tonyjms2005:
Roger is correct, one other thing to consider, what will you do if the OrderSend works OK but the OrderModify fails ?
Hi
I have an EA but my broker has decided that now the EA's cannot create an order with stops simultaniously, you must enter then market, then modify the order with the correct stops.
Here is some of my code, you can see I have added the OrderModify code but when testing this the EA just seems to enter the market and no stops are placed:
if(err!=-1)if(OrderSelect(err,SELECT_BY_TICKET)) OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,GetOrdCl(OP_SELL)); if(err>0){ Alert("Opened order ",GetNameOP(OP_SELL)); }else{ Fun_Error(GetLastError()); }Close but if order didn't open, shouldn't be calling orderModify. Always test return codes.
if(err < 0) Fun_Error(GetLastError()); else if(!OrderSelect(err,SELECT_BY_TICKET)) { Fun_Error(GetLastError()); else if(!OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,GetOrdCl(OP_SELL))) Fun_Error(GetLastError()); else Alert("Opened order ",GetNameOP(OP_SELL));
Hi
Thanks, i cant believe I missed that.
Thanks again
Antony
WHRoeder:
Close but if order didn't open, shouldn't be calling orderModify. Always test return codes.
Close but if order didn't open, shouldn't be calling orderModify. Always test return codes.
If OrderSend failed err = -1 "Returns number of the ticket assigned to the order by the trade server or -1 if it fails" . . . so OrderModify won't be called . . or am I missing something ?
if(err!=-1)if(OrderSelect(err,SELECT_BY_TICKET)) OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,GetOrdCl(OP_SELL)); or . . . . if(err != -1) { if(OrderSelect(err,SELECT_BY_TICKET)) { OrderModify(OrderTicket(),OrderOpenPrice(),sl,tp,0,GetOrdCl(OP_SELL)); } }
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
Hi
I have an EA but my broker has decided that now the EA's cannot create an order with stops simultaniously, you must enter then market, then modify the order with the correct stops.
Here is some of my code, you can see I have added the OrderModify code but when testing this the EA just seems to enter the market and no stops are placed:
Thanks
Antony