Time management a simple question

To add comments, please log in or register
apleasewouldbenice boom
59
apleasewouldbenice boom  
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.

Mehrdad Jeddi
28882
Mehrdad Jeddi  
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;
}
apleasewouldbenice boom
59
apleasewouldbenice boom  
Mehrdad Jeddi:
Many thanks to you!! I will try this
apleasewouldbenice boom
59
apleasewouldbenice boom  

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 :)
Mehrdad Jeddi
28882
Mehrdad Jeddi  
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,

Catalin Zachiu
17942
Catalin Zachiu  
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 
Keith Watford
Moderator
18437
Keith Watford  
apleasewouldbenice boom:

Do not double post.

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

apleasewouldbenice boom
59
apleasewouldbenice boom  
Many thanks to Mehrdad Jeddi and Catalin Zachiu :) 
To add comments, please log in or register