Reputation: 987
Some of my rules (to detect something) gives false alarms for an hour after Market Open (or simply just not defined well enough anyways, ha-ha). Since I can locate the moment of Market Open, I can address bars relatively to it which is kinda cool. Is there a way to specify offset by time to make it undependent to (sub-hour) timeframe?
For example in my code, MarketOpen
rule is true
if the current the moment of Market Open is still in the current bar (so it addresses the bar of MarketOpen
in any timeframe). In 1H timeframe, it would be simple: not(MarketOpen)
would exclude the first hour, but it should work in sub-hour timeframes, too.
Upvotes: 3
Views: 833
Reputation: 2161
If you want to trade only in specific hours, you can use a session
:
session = input.session("1100-2000")
inSession = not na(time(timeframe.period, session))
long = inSession and yourCondition
In any case, if you want to get the time of 1 hour after the market is open, you can use this:
newDay = ta.change(time("D"))
var float oneHourAfterMarketOpen = na
if newDay
oneHourAfterMarketOpen := time + (60 * 60 * 1000)
canTrade = time > oneHourAfterMarketOpen
bgcolor(canTrade?color.green:color.red)
Upvotes: 3