Counting Bars Within Specific Timeframes


Category:
0
0

Hey everyone!

 

I am using a custom watchlist column for options. The custom column timeframe is set to the 1-minute aggregation. I am trying to write a script that returns “1” in the following scenarios:

 

If the market has been open for 30 minutes and there have been at least 20 bars so far today. return 1

If the market has been open for 60 minutes and there have been at least 45 bars so far today. return 1

If the market has been open for 120 minutes and there have been at least 60 bars so far today. return 1

 

Any ideas?

 

 

Marked as spam
Posted by (Questions: 5, Answers: 1)
Asked on November 2, 2020 12:23 pm
120 views
0
Private answer

About all I can provide in the brief amount of time I permit for free solutions in the Q&A Forum is some code that counts the number of bars since the open:

def newDay = GetDay() <> GetDay()[1];
rec countBars = if newDay then 1 else countBars[1] + 1;
plot data = countBars;

In order to account for the number of bars that should be there by a specific time of day requires quite a bit more complexity than I can deliver in 15 minutes. Then we have to do that same computation for three separate time spans. Then convert that to whatever time frame you have set for the watchlist column. Yes I know you said you are using 1 min time frame but the best solution should be able to adapt to whatever time frame the user selected. We must consider the rest of our viewers who would come across this post and try to apply this solution in their own way.

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on November 2, 2020 7:13 pm
0
Thank you
( at November 4, 2020 6:49 am)