Cant close pending orders by time.

 
  int orders =0;
   for(int i= OrdersTotal()-1; i>=0; i--)
     {
      ulong orderTicket = OrderGetTicket(i);
      if(OrderSelect(orderTicket))
        {
         if(OrderGetString(ORDER_SYMBOL)== _Symbol && OrderGetInteger(ORDER_MAGIC) == eaMagic)
           {
            if(OrderGetInteger(ORDER_TIME_SETUP) < TimeCurrent() - 30 * PeriodSeconds(PERIOD_MN1))
              {
               trade.OrderDelete(orderTicket);
              }
            orders = orders + 1;
           }
        }
     }

Hey, guys please help me out with this.

 
aviyadav321:

Hey, guys please help me out with this.

What are you aiming to calculate with this? 30 mins back?

            if(OrderGetInteger(ORDER_TIME_SETUP) < TimeCurrent() - 30 * PeriodSeconds(PERIOD_MN1))
 

Du you know what PERIOD_MN1 means and how long 30 * PeriodSeconds(PERIOD_MN1) will be?

Use the debugger to find out: https://www.mql5.com/en/articles/654 or read the reference: place the cursor on PeriodSeconds and press F1

Debugging MQL5 Programs
Debugging MQL5 Programs
  • www.mql5.com
This article is intended primarily for the programmers who have already learned the language but have not fully mastered the program development yet. It reveals some debugging techniques and presents a combined experience of the author and many other programmers.
 
Don't double post! I deleted the other one.
 
Carl Schreiber #:

Du you know what PERIOD_MN1 means and how long 30 * PeriodSeconds(PERIOD_MN1) will be?

Use the debugger to find out: https://www.mql5.com/en/articles/654 or read the reference: place the cursor on PeriodSeconds and press F1

Good point - I misread that as PERIOD_M1

 
please add expiration time for order send sir
 
Dwi Sudarsono #: please add expiration time for order send sir

Some brokers do not support expiration time.

 
I have a question.

What's the calculation order here?

if(OrderGetInteger(ORDER_TIME_SETUP) < TimeCurrent() - 30 * PeriodSeconds(PERIOD_MN1))

Isn't this first addition then multiply the result of addition?

Or is the result the same as this:
if(OrderGetInteger(ORDER_TIME_SETUP) < TimeCurrent() - (30 * PeriodSeconds(PERIOD_MN1)))



 
Dominik Christian Egert #:
I have a question.

What's the calculation order here?
if(OrderGetInteger(ORDER_TIME_SETUP) < TimeCurrent() - 30 * PeriodSeconds(PERIOD_MN1))


Isn't this first addition then multiply the result of addition?

Or is the result the same as this:

if(OrderGetInteger(ORDER_TIME_SETUP) < TimeCurrent() - (30 * PeriodSeconds(PERIOD_MN1)))


The 2nd one

 
You should be able to read your code out loud and have it make sense. Thus, I would rewrite your test to if(duration >= 30 x)
if(TimeCurrent() - OrderGetInteger(ORDER_TIME_SETUP) >= (30 * PeriodSeconds(PERIOD_MN1)))
Reason: