3

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.

2
  • Can you elaborate a bit your question ? Can you show us how your code specify offset by bars, so we can propose you how to do the same with time ? Commented Oct 22, 2022 at 11:26
  • Thank you for trying to help this long after. :) It was long ago and I found a workaround in that specific case. How to define this Boolean variable: THING_HappenedTwoHoursAgoOrMore Commented Oct 23, 2022 at 12:14

1 Answer 1

3
+50

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) 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.