Download MetaTrader 5

How to expire (remove) an order at the end of the day (or daily candle)

To add comments, please log in or register
wiptheman
378
wiptheman 2015.11.04 18:37 

Hi All,

 I'm trying to have an order removed at the end of the day (or end of the daily candle) when conditions are not met.

Below is my code to add the order. I tried using  "ORDER_TIME_DAY " and "ORDER_TIME_SPECIFIED_DAY " to have the order out by the end of the day without success.

 Can anyone help ?

 

Thank you 

 

   if(Buy_Condition_1 && Buy_Condition_2 && Buy_Condition_3)
     {
         ZeroMemory(mrequest);
         mrequest.action=TRADE_ACTION_PENDING;                                      // pending order
         mrequest.price = NormalizeDouble(mrate[previous].high,_Digits);            // latest Bid price
         mrequest.sl = NormalizeDouble(mrate[previous].low, _Digits);               // Stop loss
         mrequest.tp = NormalizeDouble(latest_price.bid + TKP*_Point,_Digits);      // Take Profit
         mrequest.symbol = _Symbol;                                                 // currency pair
         mrequest.volume = Lot;                                                     // number of lots to trade
         mrequest.magic = EA_Magic;                                                 // Order Magic Number
         mrequest.type= ORDER_TYPE_BUY_STOP;                                        // Sell Order                          
         mrequest.type_filling = ORDER_FILLING_IOC;                                 // Order execution type
         //mrequest.type_time= ORDER_TIME_DAY;                                      // Good till current trade day order;
         mrequest.type_time = ORDER_TIME_SPECIFIED_DAY;                             // Good till specific day
         mrequest.stoplimit=NormalizeDouble(mrate[previous].high,_Digits);          // Stop Limit

         TimeToStruct(mrate[current].time, mdate);
         mdate.hour = 23;
         mdate.min = 59;
         mdate.sec = 59;
         mrequest.expiration = StructToTime(mdate);                                      // Specific day
To add comments, please log in or register