|
Finance chart Moving average with different colors for positive and negative slopes. |
| Posted by Ian Botley on Sep-18-2007 22:31 |
|
Peter,
I would like to paint a moving average on a finance chart that is green when the slope of the average is positive and red when the slope is negative. Is there a simple way to do this?
Thanks,
Ian |
Re: Finance chart Moving average with different colors for positive and negative slopes. |
| Posted by Peter Kwan on Sep-19-2007 03:07 |
|
Hi Ian,
You would need to compute the moving average data series (the mathematics utility ArrayMath.movAvg may help), then split the data series into multiple data series for the positive and negative segments, then plot the data series as different line layers (use XYChart.addLineLayer to add a line layer to the chart) using different colors.
Hope this can help.
Regards
Peter Kwan |
Re: Finance chart Moving average with different colors for positive and negative slopes. |
| Posted by Ian Botley on Sep-19-2007 06:46 |
|
Peter,
Thanks again for the quick response. I thought that was probably the way to do it. Maybe an idea for a possible future enhancement.
Ian |
Re: Finance chart Moving average with different colors for positive and negative slopes. |
| Posted by Peter Kwan on Sep-19-2007 17:36 |
|
Hi Ian,
Thanks a lot for your suggestion. We will consider this feature in future versions of ChartDirector.
Regards
Peter Kwan |
Re: Finance chart Moving average with different colors for positive and negative slopes. |
| Posted by David on Jan-09-2026 10:46 |
|
I have recently thought about this as a possibility on Finance charts.
The problem I see is when there is a sideways market and the MA (or whatever indicator) moves from +ve to -ve and back on consecutive periods. In this instance there is just one segment of the color for -ve slope and there isn't the possibility to have a NoValue element between the ends of the +ve slope segements to stop the line color for +ve slope. The order of the LineLayers doesn't help.
Is the way to address this to have a new LineLayer for each +ve and -ve slope section with all prior and subsequent points having NoValue and therefore not painted.
My question: Do you see this as a valid approach and is there a limit to the number of LineLayers that can be used?
Or do I create a line for an XYChart with x,y pairs and insert a NoValue at a n.5 on the Xaxis.
Thanks in advance
David |
Re: Finance chart Moving average with different colors for positive and negative slopes. |
| Posted by Peter Kwan on Jan-10-2026 03:33 |
|
Hi David.
May be you can use 4 line layers.
Layer 1 is for +ve slopes.
Layer 2 is for -ve slopes.
Layer 3 is for +ve slopes.
Layer 4 is for -ve slopes.
Note that two +ve slope segments must have a non-positive slope segment separating them (otherwise it is just one segment, not two segments). So you can add the first +ve slope segment to Layer 1, the non-positive slope segment to Layer 2, and the second +ve slope segment to Layer 3, and so on.
Now there should be enough space in Layer 1 to add the NoValue points, and similarly for all other layers.
Best Regards
Peter Kwan |
|