TTM Trend Consecutive bar count


Category:
0
0

Hi Pete,

In a previous post you created a script that colors the watchlist column to match the current color of the TTM Trend.  Are you able to also add the consecutive bar count which will show how many consecutive bars have been painted as red or blue?   Below I have provided a link to the previous post as well as the script you provided. Thank you.

https://www.hahn-tech.com/ans/ttm-trend/

input compBars = 6;
input paintBars = yes;
def upTrend = TTM_Trend(compBars, paintBars).TrendUp;
AssignPriceColor(if upTrend then Color.BLUE else Color.CURRENT);

Marked as spam
Posted by (Questions: 19, Answers: 18)
Asked on August 5, 2020 9:01 pm
269 views
0
Private answer

I think this should do the trick:

input compBars = 6;
input paintBars = yes;
def upTrend = TTM_Trend(compBars, paintBars).TrendUp;
rec countUpTrend = if upTrend and !upTrend[1] then 1 else if upTrend then countUpTrend[1] + 1 else 0;
rec countDownTrend = if !upTrend and upTrend[1] then -1 else if !upTrend then countDownTrend[1] - 1 else 0;
plot data = if countUpTrend > 0 then countUpTrend else countDownTrend;
AssignBackgroundColor(if data > 0 then Color.BLUE else if data < 0 then Color.RED else Color.CURRENT);

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on August 5, 2020 9:48 pm