Is it possible to dynamically change the color of certain sections of a band based on a given criterion?, e.g. if MACD > 0 then change band color to green (from that point on, until MACD < 0 and then you change the color to red).
Announcement
Collapse
No announcement yet.
Change band color
Collapse
X
-
here's a modified builtinmacd (originally provided by Alex)
you can modify the colors of the instantcolorlines in the efs editor.
Hope this helps.
kzAttached Files
-
Actually, I couldn't make any of the suggestions work with bands. However I found the following solution, based on drawLineRelative() and it works fine:
if (dblMACD >= 0) strBasisColor = "Color.green"; else strBasisColor = "Color.red";
drawLineRelative(-1,0,0,0, PS_SOLID, 2, eval(strBasisColor),fnGetTagID());
addBand(0,PS_SOLID,2,eval(strBasisColor),"0line");
It basically draws a mini line segment for each bar and creates a band as it goes.
I still have to use the addBand() at the end to create an extension of the band to the rightmost edge of the indicator pane.
Comment
-
kz - yes that's what I was trying to do, basically change the color of the horizontal band based on the color of the MACD. My solution seems to work but I was wondering if there was a more elegant one. Also what is the purpose of INSTANTCOLORLINE, it seems to have the same way as a regular LINE, what's the difference?
Comment
-
look at this new version - lines 84-89
you could also look at the signal line if you'd prefer by changing the study lines where appropriate.
the "6" is the width of the band, 0 is the level.
instantcolorline allows the line to change at the peaks and valleys whereas the other normal line changes seems to have a lag on the color change points
if you want them to be a solid color, just change them back
to "PLOTTYPE_LINE"
KirkAttached Files
Comment
Comment