ASE Home Page Products Download Purchase Support About ASE
ChartDirector Support
Forum HomeForum Home   SearchSearch

Message ListMessage List     Post MessagePost Message

  Draw MA(15) over Volume?
Posted by Chuck Van Dien on Jun-04-2025 22:07
Hello Peter,

I’m using Chart Director in VB.NET. I have Volumes populating at the bottom of the chart. Is there a simple way to generate a Moving Average over the past 15 bars and display it as a line over my Volume bars with a specific color? A VB.NET example of this with an example of how I return the MA for a specific bar would be very helpful.

Thank you!
Chuck

  Re: Draw MA(15) over Volume?
Posted by Peter Kwan on Jun-05-2025 13:33
Hi Chuck Van Die,

I will write an example for you within today.

Best Regards
Peter Kwan

  Re: Draw MA(15) over Volume?
Posted by Peter Kwan on Jun-05-2025 18:40
Hi Chuck Van Die,

I start with the Finance Chart (2) sample code:

https://www.advsofteng.com/doc/cdnet.htm#finance2.htm

In the sample, there is a addVolBars line:

c.addVolBars(75, &H99FF99, &HFF9999, &H808080)

I added the following code to compute the moving average and add it as a LineLayer:

' Create an ArrayMath object to do the computation
Dim volMath As ArrayMath = New ArrayMath(volData)

'Determine the scaling factor. For large values, the volume will use K or M as the unit.
Dim unitFactor As Double = 1
Dim maxVol As Double = volMath.max
If maxVol > 1000000 Then
unitFactor = 1000000
ElseIf maxVol > 1000 Then
unitFactor = 1000
End If

'Apply the scale factor and compute the 15 period moving average
Dim volMovAvg() As Double = volMath.div(unitFactor).movAvg(15).result()

'Add the moving average as a LineLayer, using the same axis as the volumn bars, and
'move it in front of the bars
Dim volMovAvgLayer As LineLayer = mainChart.addLineLayer(volMovAvg, &H880088)
volMovAvgLayer.setUseYAxis2()
volMovAvgLayer.moveFront()


Best Regards
Peter Kwan