Count bars for TTM Wave A histogram with 4 colors


Category:
0
0

I need help adding a counter to waveA watchlist code

plot waveA = TTM_Wave().Wave1;
AssignBackgroundColor(if waveA >= 0 then
if waveA > waveA[1] then color.CYAN else color.BLUE
else if waveA < waveA[1] then color.RED else color.YELLOW);

Marked as spam
Posted by (Questions: 3, Answers: 0)
Asked on April 8, 2024 1:44 pm
22 views
0
Private answer

I updated the title of your question because the one you entered was missing important context. Adding a counter to a watchlist column is very generic. And we have dozens of examples showing how to do that anyway. So I have entered a title which fully describes the context of your request and the resulting solution.

First item to mention is that code you provide is for a customized color scheme of the TTM Wave A. On Thinkorswim, the original TTM Wave indicator displays Wave A with a red and yellow color scheme. It's very important to mention that so we don't confuse our audience.

The following solution creates counter variables for each of the four colors included in the example code you provided. I have added the bar count to the display while retaining the background colors from the original:

def waveA = TTM_Wave().Wave1;
def colorCyan = waveA >= 0 and waveA > waveA[1];
def colorBlue = waveA >= 0 and waveA <= waveA[1];
def colorRed = waveA < 0 and waveA < waveA[1];
def colorYellow = waveA < 0 and waveA > waveA[1];
rec countCyan = if !colorCyan[1] and colorCyan then 1 else if colorCyan then countCyan[1] + 1 else 0;
rec countBlue = if !colorBlue[1] and colorBlue then 1 else if colorBlue then countBlue[1] + 1 else 0;
rec countRed = if !colorRed[1] and colorRed then 1 else if colorRed then countRed[1] + 1 else 0;
rec countYellow = if !colorYellow[1] and colorYellow then 1 else if colorYellow then countYellow[1] + 1 else 0;
plot data = Max(countCyan, Max(countBlue, Max(countRed, countYellow)));
data.SetDefaultColor(Color.BLACK);
AssignBackgroundColor(if waveA >= 0 then if waveA > waveA[1] then Color.CYAN else Color.BLUE else if waveA < waveA[1] then Color.RED else Color.YELLOW);

Marked as spam
Posted by (Questions: 37, Answers: 4091)
Answered on April 8, 2024 1:49 pm