Page 1 of 1

Indicators displays red instead of green when going upward

Posted: Mar 26 2010
by duration
Dear All,

This is what I have written:

Code: Select all


if indicator > indicator[1] then plot1(indicator,"indicator",green,default,2);
if indicator < indicator[1] then plot1(indicator,"indicator",red,default,2);
If you look at the screenshot, it is red although the indicator is going up.

Is there anything wrong with what I have written?

Many thanks.[/code][/quote]

Posted: Mar 26 2010
by Bruce DeVault
Line style plots require that you use SetPlotColor[1](1, ColorHere) to set the color as of one bar ago. Histogram style plots do not require this.

What is happening is basically that you're changing the color, but it's taking effect 1 bar late because line style plots look at what the color was at the LEFT handle of the line segment connecting the two bar values to see what the color should be for that segment, and the color change you're making on a given bar is taking effect on the next bar. The SetPlotColor[1] allows you to change the color retroactively for the previous bar, so that the color change is instantaneous, and if the plot style is line, this is the right approach.

Posted: Mar 26 2010
by duration
Dear Bruce,

Thank you very much for your amazing reply, it fixed everything!

Posted: Mar 26 2010
by Bruce DeVault
You are welcome - good luck to you!