Time management a simple question

 
Hello everyone! I need help :)

How to implement this to an advisor.

If ( 5 minutes have passed since the last position was opened )

  Do this 

Else 

  Dont

Thanks for your interest.

 
int OnTick()
{
 //

   if(LastOrderTime()+5*60<=TimeCurrent())
    {
     //Do This
    }
    else
    {
     //Do
    }

 return 0;
}

datetime LastOrderTime()
{
 datetime time;

 for(int i=OrdersTotal()-1; i>=0; i--)
   {
    if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES))continue;
    if(OrderSymbol()==_Symbol && OrderMagicNumber()==MagicNumber)
      {
       time=OrderOpenTime();
       break;
      }
   }

 return time;
}
 
Mehrdad Jeddi:
Many thanks to you!! I will try this
 

Hey Mehrdad. I tried this but didn't work. I got an error.  Which is : 

 'MagicNumber' - undeclared identifier

  
Do you know why and how to fix this. Thanks for your help :)
 
apleasewouldbenice boom:

Hey guys I need help. I get magic number error which is : 

I dont know how to fix this.

Here is my whole code :

Thanks for your interest :) Have a good day.

Before int Ontick you must declare your magic number : 
input int MagicNumber = 11223344; 
Or whatever number you want 
 
apleasewouldbenice boom:

Hey Mehrdad. I tried this but didn't work. I got an error.  Which is : 

Do you know why and how to fix this. Thanks for your help :)

So this is a custom global variable that you would define it in your code for example :

int MagicNumber=12345;

The orders will be detected by their Magic Number,

 
apleasewouldbenice boom:

Do not double post.

I have deleted your other topic and moved the reply to here.

 
Many thanks to Mehrdad Jeddi and Catalin Zachiu :) 
Reason: