Hello Everyone,
I have been experiencing intermittent issues with my OrderModify code and I have not been able to figure out what is causing it to fail. Typically the EA opens and order and then modifies it. But lately, the EA opens and order and never modifies the SL and TP. Hopefully the issue is blatantly obvious, but I have yet to find the issue. It is important to note that the function does succeed during a session but not always. If you have any input please feel free to comment:
if(BuySell == "Buy") { SL = OrderOpenPrice()-SL*Point; TP = OrderOpenPrice()+TP*Point; } if(BuySell == "Sell"){ SL = OrderOpenPrice()+SL*Point; TP = OrderOpenPrice()-TP*Point; }
- Always test your return codes and report the error from GetLastError so you find out why it is failing
- EA's must adjust for 4/5 digit brokers. tp, sl, AND slippage.
It might be helpful to know what error you get in your log when the OrderModify() fails.
There is no errors displayed in the log. Thus my confusion.
- Always test your return codes and report the error from GetLastError so you find out why it is failing
- EA's must adjust for 4/5 digit brokers. tp, sl, AND slippage.
I am testing the return codes and am reporting the errors. As far as TP, SL and Slippage are concerned, I am currently addressing that issue, but that doesn't change the fact that the OrderModfiy() is successful intermittently. Thus I can conclude that is not the issue at hand.
FreezeLevel ?
Pardon my ignorance, but what is a freezelevel?
Pardon my ignorance, but what is a freezelevel?
Nevermind, I just read into the freezelevel information (https://book.mql4.com/appendix/limits).
My TP is static at 150 pips and SL at 30 pips. So I can safe with confidence that I should be well beyond the freezelevel.
if(ModifyOpenOrder(ticket,BuySell) < 0) // // // int ModifyOpenOrder(int ticket,string BuySell) { // Function Returns 1 for success, -1 for failure OrderSelect(ticket,SELECT_BY_TICKET); // Set SL and TP according to Buy or Sell signs if(BuySell == "Buy") { SL = OrderOpenPrice()-SL*Point; TP = OrderOpenPrice()+TP*Point; } if(BuySell == "Sell"){ SL = OrderOpenPrice()+SL*Point; TP = OrderOpenPrice()-TP*Point; } if(OrderModify(ticket, OrderOpenPrice(),SL,TP,0,Blue) == true) return(1); else return(-1); }
What is the stringvalue you are giving BuySell
I don't see you set it to "Buy" or to "Sell" but you call the function with
ModifyOpenOrder(ticket,BuySell)Then it is needed BuySell is a string with some kind of value....
What is the stringvalue you are giving BuySell
I don't see you set it to "Buy" or to "Sell" but you call the function with
Then it is needed BuySell is a string with some kind of value...."Buy" and "Sell" is being passed into the parent operator. As stated before, the OrderSend() is opening the order successfully (thus "Buy" and "Sell" are being passed in correctly), but the modify does not always commit.
There is no errors displayed in the log. Thus my confusion.
"Buy" and "Sell" is being passed into the parent operator. As stated before, the OrderSend() is opening the order successfully (thus "Buy" and "Sell" are being passed in correctly), but the modify does not always commit.
// Open orders using BuySell as criterion for OrderType int ticket=OrderSend(Symbol(),intBuySell,LotSize(),BidAsk,3,0,0,"EA Order",Magic.Number,0,ColorCode); //Open execution cannot include TP and SL, modify after execution if(ticket<0) { Print("OrderSend failed with error #",GetLastError()); }else // Order was successful, Add SL and TP { if(ModifyOpenOrder(ticket,BuySell) < 0) Print("OrderModify failed with error #",GetLastError()); }explain where did you do that after orderopening ??
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- 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 Everyone,
I have been experiencing intermittent issues with my OrderModify code and I have not been able to figure out what is causing it to fail. Typically the EA opens and order and then modifies it. But lately, the EA opens and order and never modifies the SL and TP. Hopefully the issue is blatantly obvious, but I have yet to find the issue. It is important to note that the function does succeed during a session but not always. If you have any input please feel free to comment: