if(SellTicket >0){ OrderSelect(SellTicket,SELECT_BY_TICKET); if(StopLoss > 0) double SellStopLoss = OpenPrice +(StopLoss * Point);
- Always check your return codes. What are Function return values ? How do I use them ? - MQL4 forum
- What is the value of OpenPrice?
- Always check your return codes. What are Function return values ? How do I use them ? - MQL4 forum
- What is the value of OpenPrice?
if (Up==true) { BuyTicket=OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,0,"HA Model",16384,0,Green); if(BuyTicket>0) { if(OrderSelect(BuyTicket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice()); SendMail("HA Model", "Buy Order Opened"+Symbol()); } else Print("Error opening BUY order : ",GetLastError()); if(BuyTicket >0) { OrderSelect(BuyTicket,SELECT_BY_TICKET); double OpenPrice = OrderOpenPrice(); if(StopLoss > 0) double BuyStopLoss = OpenPrice -(StopLoss *Point); if(TakeProfit >0) double BuyTakeProfit = OpenPrice +(TakeProfit * Point); if(BuyStopLoss > 0 || BuyTakeProfit > 0) bool TicketMod = OrderModify(BuyTicket,OrderOpenPrice(),BuyStopLoss,BuyTakeProfit,0,Yellow); Print("Error input of Stop Loss & Take Profit : ",GetLastError()); }
Sorry to have left that out. OpenPrice was declared in the Buy order section. This portion of the EA functions properly, which is why I am confused when I get the error message. Thanks for the reference on the return values.
Open price for a Buy is Ask, for a Sell it is Bid, how far has price moved between placing your Buy and your Sell ? Don't use OpenPrice use Ask if you must or use OrderOpenPrice(). Why don't you print OpenPrice when your OrdrModify() fails ? why don't you Print Ask, Bid, etc ? don't you think they are relevant to finding thee cause of your issue ?
I always print values to my journal, but the answer was not obvious until I read the thread on function return values and trapped them. Result was a mod to my code that corrected the problem.
Not sure about your reference to using Ask and Bid. My Order Send uses Ask and Bid as you suggest, and OrderOpenPrice() was used to set the TP and SL. Anyway, the mod to my code was successful.
Thank you both for your time.
WBD
Hello:
This is my first posting on this forum, so please excuse any formatting/procedural errors. I am having difficulty with the Order Modify function. I use an ECN, so I must send the order with 0's in the SL and TP fields and then use the Order Modify function.
The stop loss and take profit values are inserted perfectly with the buy order code, but fail when a sell order is input, resulting in the 4051 error code. This refers to invalid parameters on the take profit field, but I am using the same approach (not the calcs) on my buy order.
There is obviously something pretty basic that I am missing. I would really appreciate some help/insight on the extent of my error.
Thanks very much
wbd
For anyone reading this thread, here is the change I made to make the Stop Loss and Take Profit modification. My problem was based on the value of 0 being returned as the Ticket No. Code replaced in pink and code deleted in yellow.
if(SellTicket >0) { OrderSelect(SellTicket,SELECT_BY_TICKET); double entry_price = OrderOpenPrice(); OrderModify(SellTicket, entry_price, (entry_price + StopLoss*Point), (entry_price - TakeProfit*Point), 0); // if(StopLoss > 0) double SellStopLoss = OpenPrice +(StopLoss * Point); // if(TakeProfit > 0) double SellTakeProfit = OpenPrice -(TakeProfit * Point); // if(SellStopLoss > 0 || SellTakeProfit > 0) // bool TicketMod1 = OrderModify(SellTicket,OrderOpenPrice(),SellStopLoss,SellTakeProfit,0,Blue); // else Print("Error input of Stop Loss & Take Profit : ",GetLastError());
I always print values to my journal, but the answer was not obvious until I read the thread on function return values and trapped them. Result was a mod to my code that corrected the problem.
Not sure about your reference to using Ask and Bid. My Order Send uses Ask and Bid as you suggest, and OrderOpenPrice() was used to set the TP and SL. Anyway, the mod to my code was successful.

- 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:
This is my first posting on this forum, so please excuse any formatting/procedural errors. I am having difficulty with the Order Modify function. I use an ECN, so I must send the order with 0's in the SL and TP fields and then use the Order Modify function.
The stop loss and take profit values are inserted perfectly with the buy order code, but fail when a sell order is input, resulting in the 4051 error code. This refers to invalid parameters on the take profit field, but I am using the same approach (not the calcs) on my buy order.
There is obviously something pretty basic that I am missing. I would really appreciate some help/insight on the extent of my error.
Thanks very much
wbd