Download MetaTrader 5

Problem in managing orders

To add comments, please log in or register
Amirfarhangy
12
Amirfarhangy  

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

whroeder1
17093
whroeder1  
Amirfarhangy: Can someone help me where I am wrong here?
There are no mind readers here. We can't see your broken code.
Amirfarhangy
12
Amirfarhangy  
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&lt;=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&lt;=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());
        }
        }
whroeder1
17093
whroeder1  
Amirfarhangy: I found even after triggering the orders they still keep the old pending order types (
  1. 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.
  2. What does your log say?
  3. Ticket numbers are int. Make them that and remove those casts.
To add comments, please log in or register