PENDING ORDERS THAT EXPIRES IN 5 Miuntes Please hellp

 

Hello friends i'm trying to creat an EA that is based on pending orders and now the problem is I want all pending orders to be cancelled after 5 minutes of being placed or to be cancelled if they are not yet open orders so please help with the expiration

#include <Trade\Trade.mqh>

CTrade trade;


void OnTick()
{

double Balance=AccountInfoDouble(ACCOUNT_BALANCE);

double Equity=AccountInfoDouble(ACCOUNT_EQUITY);

double Ask=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_ASK),_Digits);

double Bid=NormalizeDouble(SymbolInfoDouble(_Symbol,SYMBOL_BID),_Digits);

datetime time=TimeLocal();

string hoursAndMinutes=TimeToString(time,TIME_SECONDS);

if (PositionsTotal()==0 && OrdersTotal()==0)
{
trade.BuyStop(0.10,Ask+1500*_Point,_Symbol,Ask-250*_Point,Ask+3000*_Point,ORDER_TIME_SPECIFIED,01:01:59,0);   

trade.SellStop(0.10,Bid-1500*_Point,_Symbol,Bid+250*_Point,Bid-3000*_Point,ORDER_TIME_SPECIFIED,01:01;59,0);
}

if (Balance!=Equity) CancelOrder();
}
 void CancelOrder()
{

for(int i=OrdersTotal()-1; i>=0; i--)
{

ulong OrderTicket=OrderGetTicket(i);

trade.OrderDelete(OrderTicket);
}
}

            
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
Documentation on MQL5: Constants, Enumerations and Structures / Trade Constants / Order Properties
  • www.mql5.com
Requests to execute trade operations are formalized as orders. Each order has a variety of properties for reading. Information on them can be obtained using functions Position identifier that is set to an order as soon as it is executed. Each executed order results in a deal that opens or modifies an already existing position. The...
 

Help: Datetime Type

Here is an example format:

datetime NY=D'2015.01.01 00:00';     // Time of beginning of year 2015
datetime d1=D'1980.07.19 12:30:27';  // Year Month Day Hours Minutes Seconds
datetime d2=D'19.07.1980 12:30:27';  // Equal to D'1980.07.19 12:30:27';
datetime d3=D'19.07.1980 12';        // Equal to D'1980.07.19 12:00:00'
datetime d4=D'01.01.2004';           // Equal to D'01.01.2004 00:00:00'

You need to do this: determine the current time and write it into a variable (let it be 'time_exp'). Then add five minutes to the variable (5 * 60 seconds) - that is, you need to add the number 300 to the variable 'time_exp'.

Documentation on MQL5: Standard Library / Panels and Dialogs / CDateTime / DateTime
Documentation on MQL5: Standard Library / Panels and Dialogs / CDateTime / DateTime
  • www.mql5.com
Standard Library / Panels and Dialogs / CDateTime / DateTime - Reference on algorithmic/automated trading language for MetaTrader 5
 
 
Malekane.9604: i'm trying to creat an EA that is based on pending orders

There is no need to create pending orders in code.

  1. The pending has the slight advantage, A) you are closer to the top of the queue (filled quicker), B) there's no round trip network delay (filled quicker.)

    Don't worry about it unless you're scalping M1 or trading news.

  2. Humans can't watch the screen 24/7, so they use pending orders; EAs can, so no need for pending orders, have it wait until the market reaches the trigger price and just open an order.