How to only open trade in first x seconds of a new candle ?

 

How to only open trade/give signal in first x seconds of a new candle ?

 

I am currently creating an expert advisor, and I want them to only give a signal or open a trade if it is within the first 30 seconds of the current candle.

How do I do that ?

 My idea was this but not sure if this is correct and if it works in the strategy tester:

if(TimeCurrent() <= Time[0]+PeriodSeconds())
{
}

regards,

salexes 

 
That if statement will always be true. You can't know which tick will be the last tick, until you receive a tick of the new candle. Just wait for a new bar and do it.
 

whroeder1 is quite correct; your statement will always evaluate as true.

But with a small adjustment you could make it do what you want (i.e. restrict to the first 30 seconds of the bar):

if(TimeCurrent() <= Time[0]30)
Reason: