Download MetaTrader 5

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

To add comments, please log in or register
salexes
784
salexes  

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 

whroeder1
15917
whroeder1  
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.
honest_knave
Moderator
2326
honest_knave  

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)
To add comments, please log in or register