I need to know what would be the precise form to work in the situations where a strategy trades during a specific time range along the whole trading session, covering from the evening of the present calendar day to the next calendar day, i.e. the key point here is we are talking about 2 different calendar days even being in the same session.
For example, when you need a strategy works only during a delimited time range in the same calendar day, let’s say from 8:00 am to 1:00 pm, you can specify that as:
if (ToTime(Time[0]) >= 080000 && ToTime(Time[0]) <= 130000)
{
// do something
}
And in this way, you clearly delimit and enclosure the trading time range without doubts.
But what about when a strategy has the trading time, for example, from 10:00 pm to 7:00 am? i.e., when the strategy works during the same trading session but that is a time range that covers time of 2 calendar days (from this night to the next morning).
I tried with different if-statements like the next:
// This takes trades, but it is like if the strategy doesn’t see a continuous time range
// and instead of that it sees a kind of a segmented time range.
if (ToTime(Time[0]) >= 220000 && ToTime(Time[0]) <= 235959) || (ToTime(Time[0]) >= 000000 && ToTime(Time[0]) <= 070000)
{
// do something
}
// This doesn’t take any trades.
if (ToTime(Time[0]) >= 220000 && ToTime(Time[0]) <= 235959) && (ToTime(Time[0]) >= 000000 && ToTime(Time[0]) <= 070000)
{
// do something
}
I also tried with the next one, and it seems to work (I only tried it with backtests), but it works with 2 issues. The first issue is I don’t feel it enclosures a time range because it uses ‘||’ instead of ‘&&’ that is what you would use if you were working during the same calendar day as the first if-statement example at the beginning of this post. The second and most important issue is I tested using the London time in NinjaTrader 8 (changing the time zone into the NT8 platform, restarting NT8,… ) to see what would be the strategy behavior and its performance if you were using a trading time range that is entirely between hours into the same calendar day, and the problem is that with the next if-statement the strategy doesn’t have the exact same performance in the Strategy Analyzer (backtest) in comparison to when using the London time, and with this if-statement the backtest summary shows the strategy takes some extra Total # of trades that of course produces lightly different Total net profit and lightly different other metrics. All this of course testing the strategy with the exact same settings and only converting the time range from US E.T. to London time.
if (ToTime(Time[0]) >= 220000 || ToTime(Time[0]) <= 070000)
{
// do something
}
I tried to find other posts that covers this kind of situations, but I couldn’t find anything that talks about this kind of time situations.
I would like to know what would be the way to work this topic with accuracy in a way that the NT8 platform produces the exact same results as if you were working with a time range in the same calendar day.
Thank you
Comment