Hey I have issues with my part of code that is trying to compare smma2 postion to dema1 postion on chart.
What I want is:
if dema1 is green and smma2 is above dema1 then smma2_color should be blue
if dema1 is green but smma2 is below dema1 then smma2_color should be orange
if dema1 is red and smma2 is below dema1 then smma2_color should be blue
if dema1 is red but smma2 is above dema1 then smma2_color should be orange
What I have so far, ta.change compares values instead of position (my guess?) so the result is incorrect and I cant figure out what to swap it with:
// DEMA COLOR CHANGE
dema1color = ta.change(dema1)>=0 ? color.green : color.red
dema1ColorFlip = dema1color != nz(dema1color[1])
barcolor(dema1ColorFlip ? dema1color : na)
t1 = plot(dema1, color=dema1color, linewidth=3, title="DEMA 1")
// Set SMMA 2 color based on DEMA 1 color and position
var color smma2_color = na
if (dema1color == color.green) and (ta.change(smma2) > 0)
smma2_color := color.rgb(108, 214, 230, 50) // Blue
else if (dema1color == color.green) and (ta.change(smma2) <= 0)
smma2_color := color.rgb(230, 183, 108, 50) // Orange
else if (dema1color == color.red) and (ta.change(smma2) > 0)
smma2_color := color.rgb(230, 183, 108, 50) // Orange
else if (dema1color == color.red) and (ta.change(smma2) <= 0)
smma2_color := color.rgb(108, 214, 230, 50) // Blue
Michał is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.