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

Message ListMessage List     Post MessagePost Message

  Price Volume
Posted by Norbert on Oct-27-2013 21:01
Attachments:
Hello,

I have a Access-DB with a Chart like the first picture.


I did it with this code :
Sub ShowChart()
Dim cd As New ChartDirector.API
    Dim Dbtable
    Dim VolTable
    Dim timeStamps()
    Dim HighData()
    Dim LowData()
    Dim OpenData()
    Dim CloseData()
    Dim volData()
    Dim MP_Price_Data()
    Dim MP_Vol_Data()
    Dim c As FinanceChart
    Dim a
    Dim Height
    Dim TEst()
    Dim i
    Dim result
    Dim MainChart As XYChart
    Dim CountPrices
Dim strsql
    Dim noOfDays As Long


    If Me.DATUM_AB > Me.DATUM_BIS Then
        a = Me.DATUM_BIS
        Me.DATUM_BIS = Me.DATUM_AB
        Me.DATUM_AB = a
    End If
    strsql = "SELeCT COUNT(*) AS Anzahl from Kurse where WP_ID = " & N(Me.WP_ID) & " AND Periodenlaenge = " & h(Me.Periode)
    strsql = strsql & " and Datum >= " & ADO_Datumswert(Me.DATUM_AB) & " and Datum <= " & ADO_Datumswert(Me.DATUM_BIS)
    Set rst = New ADODB.recordset
    rst.Open strsql, Con, adOpenDynamic, adLockOptimistic
    noOfDays = rst!Anzahl
    rst.Close

If noOfDays > 0 Then
    ' To compute moving averages starting from the first day, we need to get extra
    ' data points before the first day
    Dim extraDays As Long
    extraDays = 0


    strsql = "Select Periodenstart ,High,Low,OPen,Close,Volumen,datum from kurse where wp_ID = " & N(WP_ID) & " and Periodenlaenge = " & h(Me.Periode)
    strsql = strsql & " and Datum >= " & ADO_Datumswert(Me.DATUM_AB) & " and Datum <= " & ADO_Datumswert(Me.DATUM_BIS)
    strsql = strsql & "  order by Datum,Periodenstart"
    rst.Open strsql, Con, adOpenKeyset, adLockOptimistic

    Set Dbtable = cd.Dbtable(rst, , noOfDays)

     rst.Close
    Set rst = Nothing
    timeStamps = Dbtable.getCol(0)
    HighData = Dbtable.getCol(1)
    LowData = Dbtable.getCol(2)
    OpenData = Dbtable.getCol(3)
    CloseData = Dbtable.getCol(4)
    volData = Dbtable.getCol(5)
    ' Create a FinanceChart object
    Set c = cd.FinanceChart(1500)
    ' Add a title to the chart
    Call c.addTitle(Me.WP)
    ' Set the data into the finance chart object
    Call c.setData(timeStamps, HighData, LowData, OpenData, CloseData, volData, extraDays)
    ' Add the main chart with 480 pixels in height
    Set MainChart = c.addMainChart(480)
If Me.Periode = "TAG" Then Call c.addVolBars(100, &H99FF99, &HFF9999, &H808080)
' SOME LINES OF CODE FOR INDICATORS
'..........


    Set ChartViewer1.Picture = c.makePicture()
End If
End Sub

######################################################

No I tried to implement a layer for a Price-Volume-Profile.

I read this : http://www.chartdir.com/forum/download_thread.php?bn=chartdir_support&pattern=&thread=1350452853

I wrote some lines of code like this :

'#################################################
    Set rst = New ADODB.recordset
    strsql = "Select count(distinct Kurs) As Anzahl from Marketprofile where WP_ID = " & N(Me.WP_ID) & " and Datum >= " & ADO_Datumswert(Me.DATUM_AB) & " and Datum <= " & ADO_Datumswert(Me.DATUM_BIS)
    rst.Open strsql, Con
    CountPrices = rst!Anzahl
    rst.Close
    If CountPrices > 0 Then
        strsql = "Select Kurs,Sum(Volumen) as Volume from Marketprofile where WP_ID = " & N(Me.WP_ID) & " and Datum >= " & ADO_Datumswert(Me.DATUM_AB) & " and Datum <= " & ADO_Datumswert(Me.DATUM_BIS) & " group by Kurs "
        rst.Open strsql, Con
        ' Get Price and Volume from DB
        Set VolTable = cd.Dbtable(rst, , CountPrices)
        rst.Close
        MP_Price_Data = VolTable.getCol(0)
        MP_Vol_Data = VolTable.getCol(1)
        Dim Mp_Chart
        Dim Transparent
        Transparent = &HFF00000
        Dim MainPlotArea As Object, BarLayer As Object
        Dim Breite, Hoehe


        Set MainPlotArea = MainChart.getPlotArea
        Dim Left_X, Right_X, UP_Y, Down_Y
        Left_X = MainPlotArea.getLeftX()
        Right_X = MainPlotArea.getRightX()
        UP_Y = MainPlotArea.getTopY()
        Down_Y = MainPlotArea.getBottomY()
        Dim TouchBar
        TouchBar = 1.7E-100
        Dim Layer
        Dim PVChart
        Set PVChart = cd.XYChart(MainChart.getWidth(), MainChart.getHeight())
        Call PVChart.setPlotArea(0, 0, PVChart.getWidth(), PVChart.getHeight(), Transparent, -1, Transparent, Transparent)

        ' Add the bar Layer
        Call PVChart.swapXY
        Set Layer = PVChart.addBarLayer(MP_Vol_Data, &HFFDDDD)
        Call Layer.setBorderColor(&HDDDDDD)
        Call Layer.setXData(MP_Price_Data())
'        Call Layer.setBarGap(TouchBar)
        'The x-axis of the pvChart is the same as the y-axis of the main price chart
        Call PVChart.xAxis().syncAxis(MainChart.yAxis())
        Call PVChart.yAxis().setMargin(PVChart.getWidth() / 2)

        ' Merge the pvChart to the back of the main price chart
        Call c.layout

        Call MainPlotArea.setBackground(Transparent, Transparent, &H888888)
        Call MainChart.getDrawArea().Merge(PVChart.makeChart3(), MainPlotArea.getLeftX(), MainPlotArea.getTopY(), 7, 0)
     End If
     Set rst = Nothing


'########################
' last part of the code above

    Set ChartViewer1.Picture = c.makePicture()
End If



#####################################

And the last picture is the result.

I had 83 ROws for Price-Volume-Combination

I did not find the problem (:-((

What's wrong?

Kind regards
Norbert
Chart_1.PNG
Chart_2.PNG

  Re: Price Volume
Posted by Peter Kwan on Oct-29-2013 00:58
Hi Norbert,

Just by reading the code, I can the following issues (or potential issue):

(a) Transparent is declared incorrect. In your code, it is &HFF00000. However, it should be &HFF000000. Anyway, I suggest you not to use your own Transparent variable. Instead, please use ChartDirector's built-in constant cd.Transparent. For example:

Call PVChart.setPlotArea(0, 0, PVChart.getWidth(), PVChart.getHeight(), cd.Transparent, -1, cd.Transparent, cd.Transparent)

.....

Call MainPlotArea.setBackground(cd.Transparent, cd.Transparent, &H888888)


(b) The line:

Set PVChart = cd.XYChart(MainChart.getWidth(), MainChart.getHeight())

should be:

Set PVChart = cd.XYChart(MainPlotArea.getWidth(), MainPlotArea.getHeight())


(c) I am not sure if the following line is correct or not:

        Call Layer.setXData(MP_Price_Data())

Usually, I would write the code as:

        Call Layer.setXData(MP_Price_Data)


Hope this can help.

Regards
Peter Kwan

  Re: Price Volume
Posted by Norbert on Oct-29-2013 16:49
Thanks a lot!
It works.
It was the transparent-definition.

The point c) is the same.
With both statements the function gets the  hole Array.


Thank you!

Regards
Norbert