Count green bars only current day


Category:
0
0

Hi Pete,

I have a customized column that counts the number of green 30-minute bars for the day. Is there a way to rewrite the code so that it automatically takes only today into effect instead of using the lookback?

Thanks again!

input lookback = 13;

def green = close > close[1];
def ct = sum(green, lookback);
plot count = if isNaN(ct) then 0 else ct;
count.assignValueColor(if count >= .5 * lookback then color.green else color.red);

Marked as spam
Posted by (Questions: 20, Answers: 27)
Asked on February 1, 2020 8:19 pm
273 views
0
Private answer

I should mention that a green bar on the chart is defined as the close being greater than the open. It's all determined within the same bar. Your code does not behave this way but instead compares the close of the current bar to the close of the previous bar. It is still possible for a bar to close higher than the previous close and be colored red on the chart.

So for my solution I have adjusted the names of the variables to make it more clear as to exactly what is being measured and displayed.

def newDay = GetDay() <> GetDay()[1];
def higherClose = close > close[1];
rec countHigherCloseBars = if newDay then higherClose else if higherClose then countHigherCloseBars[1] + 1 else countHigherCloseBars[1];
rec countAllBars = if newDay then 1 else countAllBars[1] + 1;
plot count = countHigherCloseBars;
count.AssignValueColor(if count >= 0.5 * countAllBars then Color.GREEN else Color.RED);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on February 2, 2020 9:44 am
0
Thanks again Pete! I don't understand why I'm having such a hard time figuring out ThinkScript! I'm so GLAD you're kind enough to volunteer your time!
( at February 2, 2020 2:29 pm)
0
Hi Pete, I adjusted plot count = countHigherCloseBars/13 * 100; to get a percentage. Is there a way to scan for a percentage either above or below X pct? Thanks!
( at December 8, 2022 11:05 pm)
0
Since this post is in the Watch Lists topic of the forum it would not be appropriate to discuss a scan or provide a scan based solution. I suggest you post a new question in the stock scanners topic and include a link to this question as a reference. Keep in mind that solutions provided in this forum are meant to serve the broadest possible audience. So you cannot get the percentage value by dividing by 13 or it will not work for any other time frame. And some of our viewers may not want to wait until the end of day to run their scans. So the solution must include a counter to keep track of how many bars have been completed in the current session at the time the scan is run.
( at December 9, 2022 11:02 am)