Amirfarhangy: Can someone help me where I am wrong here?
| There are no mind readers here. We can't see your broken code. |
double Deposit; extern double Risk=0.01; extern double Buy_fractal; extern double Sell_fractal; // Stoploss and take profit (if we want to define take profit) for Sell and Buy (input double) extern double Buy_sl,Buy_tp,Sell_sl,Sell_tp; // eDo not start before: extern datetime News_time; datetime Now=TimeCurrent(); // Closed order counting variable int Closed_count=0; // Other Variables to keep Psar indicator double Psar_step= 0.05; double Psar_max = 0.2; double Buy_SLpoints,Sell_SLpoints,Point_value,MM_risk; // Time of news (in Grinwich) // Lottage of trade double Buy_lot=0,Sell_lot=0,Buy_ticket=0,Sell_ticket=0,ticket=0; // Buy/Sell counting variables added int Trade_count=0; bool Buy_Select,Sell_Select,Buy_Del,Sell_Del,Order_Select; bool Buy_Mod,Sell_Mod; static datetime Time0; int count,type,magic,Sell_order=0,Buy_order=0; int firsttime=0; int order_type,All_orders,Buy_type,Sell_type; if(firsttime==0) //first time set the order { Buy_ticket=OrderSend(Symbol(),OP_BUYSTOP,Buy_lot,Buy_fractal+Ask-Bid+3*Point*10,2,Buy_sl,0,"my Buy order",0,0,clrGreen); Alert(string(Symbol())+"OrderSend Error: ",GetLastError()); Sell_ticket=OrderSend(Symbol(),OP_SELLSTOP,Sell_lot,Sell_fractal-3*Point*10,2,Sell_sl+Ask-Bid,0,"my <a href="https://www.mql5.com/en/docs/constants/tradingconstants/enum_book_type" title="MQL5 documentation: Trade Orders in Depth Of Market" class="linkator"><span class="mark">Sell order</span></a>",0,0,clrGreen); Alert(string(Symbol())+"OrderSend Error: ",GetLastError()); if(Buy_ticket==0 || Sell_ticket==0) { Alert("failed to set orders"); } firsttime=1; } if(OrderSelect(int(Buy_ticket),SELECT_BY_TICKET)==true) Buy_type=OrderType(); //Alert(" Buy Type: 0=Buy, 4=Buy stop: "+string(Buy_type));//=============== Sell_Select=OrderSelect(int(Sell_ticket),SELECT_BY_TICKET); Sell_type=OrderType(); //Alert(" Sell Type: 1=Sell, 5=Sell stop: "+string(Sell_type));//============== if(Buy_type<=2) // Buy activated { if(OrderSelect(int(Sell_ticket),SELECT_BY_TICKET)==true) { Sell_Del=OrderDelete(int(Sell_ticket),clrRed); Alert("On "+string(Symbol())+" Buy is activated"); if(Sell_Del==false) { Alert("OrderDelete returned the error of ",GetLastError()); } else Alert("OrderSelect returned the error of ",GetLastError()); } } if(Sell_type<=2)// Sell Activated { if(OrderSelect(int(Buy_ticket),SELECT_BY_TICKET)==true) { Buy_Del=OrderDelete(int(Buy_ticket),clrRed); Alert("On "+string(Symbol())+" Sell is activated"); if(Buy_Del==false) { Alert("OrderDelete returned the error of ",GetLastError()); } else Alert("OrderSelect returned the error of ",GetLastError()); } }
Amirfarhangy: I found even after triggering the orders they still keep the old pending order types (
- You didn't post your actual code, so we have no idea if those ticket numbers are declared globally or which funtion the code is in.
- What does your log say?
- Ticket numbers are int. Make them that and remove those casts.

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,
in my expert I have two pending orders (a buy stop and a sell stop) and I want to delete one when the other one get activated.
I used the order type so when the buy type changed from 4 (buystop) to 0 (buy) then the sell order to be deleted by order delete function.
HOWEVER
I found even after triggering the orders they still keep the old pending order types (4 and 5 for Buy and Sell respectively).
Can someone help me where I am wrong here?
Many Thanks.
Amir