You need to check the ticket before you check for an error . . . even if the Order is OK there may be an error from somewhere else in the code . . .
If the Order fails the ticket will be -1 . . . from the documentation "Returns number of the ticket assigned to the order by the trade server or -1 if it fails."
So . . . if (sell_ticket == -1) then check for the error
Read, understand and follow this: Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
You need to check the ticket before you check for an error . . . even if the Order is OK there may be an error from somewhere else in the code . . .
If the Order fails the ticket will be -1 . . . from the documentation "Returns number of the ticket assigned to the order by the trade server or -1 if it fails."
So . . . if (sell_ticket == -1) then check for the error
Read, understand and follow this: Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial
fine. But order is not placed as the ask/bid is very close to the open price. How can I do that in such a situation?
fine. But order is not placed as the ask/bid is very close to the open price. How can I do that in such a situation?
You can place a Market order AT Ask/Bid
By doing that, actual process will not be done.
So I have to place at exact sell_price/buy_price as per my calculation.
Is there any other method?
By doing that, actual process will not be done.
So I have to place at exact sell_price/buy_price as per my calculation.
Is there any other method?
if(Bid<sell_price) sell_type = 3; if(Bid>sell_price) sell_type = 5; if(Bid==sell_price) sell_type = 1; int sell_ticket = OrderSend(Symbol(), sell_type, 1.0, sell_price, 1, sell_SL, stgt, "Success #", 0, close_time, CLR_NONE);
- Don't hard code numbers 1, 3, 5. Use OP_SELL, OP_SELLLIMIT so you/we can understand the code.
- You can't open a pending order closer to market than stop level. Show the rest of the code.
- Doubles rarely compare equal.
- EA's must adjust tp, sl, AND slippage for 4/5 digit brokers
- On ECN brokers you must open first and THEN set stops.
- Always test return codes so you find out WHY
- You must refresh your variable after a sleep as sell_price and Bid will be wrong (op_sell)
//++++ These are adjusted for 5 digit brokers. int pips2points; // slippage 3 pips 3=points 30=points double pips2dbl; // Stoploss 15 pips 0.015 0.0150 int Digits.pips; // DoubleToStr(dbl/pips2dbl, Digits.pips) int init(){ OptParameters(); if (Digits % 2 == 1){ // DE30=1/JPY=3/EURUSD=5 https://www.mql5.com/en/forum/135345 pips2dbl = Point*10; pips2points = 10; Digits.pips = 1; } else { pips2dbl = Point; pips2points = 1; Digits.pips = 0; } // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl //---- These are adjusted for 5 digit brokers. /* On ECN brokers you must open first and THEN set stops int ticket = OrderSend(..., 0,0,...) if (ticket < 0) Alert("OrderSend failed: ", GetLastError()); else if (!OrderSelect(ticket, SELECT_BY_TICKET)) Alert("OrderSelect failed: ", GetLastError()); else if (!OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0) Alert("OrderModify failed: ", GetLastError()); */
- Don't hard code numbers 1, 3, 5. Use OP_SELL, OP_SELLLIMIT so you/we can understand the code.
- You can't open a pending order closer to market than stop level. Show the rest of the code.
- Doubles rarely compare equal.
- EA's must adjust tp, sl, AND slippage for 4/5 digit brokers
- On ECN brokers you must open first and THEN set stops.
- Always test return codes so you find out WHY
- You must refresh your variable after a sleep as sell_price and Bid will be wrong (op_sell)
Thanks friend. Please tell me how to update(refresh) the Bid/Ask in the middle of the start function.
Thanks friend. Please tell me how to update(refresh) the Bid/Ask in the middle of the start function.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Dear All,
I am here again for your help. I tried different methods to succeed Error #130. I couldnt place orders when the price is near to Ask or Bid.
Here is one of my technique. Can any one suggest alternate method or changes to be made that will workout.
Thanks in advance.
At last i am getting again the same error even after the Sleep.