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

Message ListMessage List     Post MessagePost Message

  FinanceChart and addScatterLayer
Posted by christophe.dupre on Aug-09-2010 21:18
Hello there,

I've been trying to add an arrow for Buy/Sell signal on my finance charts. After doing a forum search, it seems to me that I could use the addScatterLayer function but when I tried, I get the following error:
TypeError: unknown method MultiChart.addScatterLayer.

Here is the code snipset:

t, symbol, first, high, low, close, volume = zip(*self.data[ startIndex:endIndex] )

x = self.ui.chartLabel.geometry().width() - 10
y = self.ui.chartLabel.geometry().height() - 10
self.chart = FinanceChart(x )

self.chart.setData(t, high, low, first, close, volume, 5)
self.chart.addScatterLayer(t[20], close[20], "Natural", TriangleSymbol, 11, 0x33ff33)


self.mainChart = self.chart.addMainChart( y * 0.7 )
#chart.xAxis().setLabels(labels)
layer = self.chart.addCandleStick(0x00ff00, 0xff0000)
self.chart.addVolIndicator(y * 0.20, 0x808080, 0x808080, 0x808080)

# Set the line width to 2 pixels
layer.setLineWidth(1)

# Output the chart
tmpChart = self.chart.makeChart2(BMP)
pix = QPixmap()
pix.loadFromData(tmpChart)
self.ui.chartLabel.setPixmap(pix)


Thanks for the help.

Christophe Dupre

  Re: FinanceChart and addScatterLayer
Posted by Peter Kwan on Aug-09-2010 23:16
Hi christophe.dupre,

There are two issues:

1. In your case, there are two charts - the main price chart and the volume indicator chart. You need to add the scatter layer to the chart you want the symbol to appear. If you want the symbol to appear in the main price chart, you mayadd the scatter layer to the main price chart. The FinanceChart is not actually a chart, but a container for your charts.

2. In FinanceChart, all data should be synchronized. They should all have the same length. For example, the t, high, low, first, close, volume data are all synchronized. Your scatter points should use synchronized data too. Also, like all financial indicators, the timestamps are not needed.

self.mainChart = self.chart.addMainChart( y * 0.7 )

#your scatter layer data, initialized to NoValue
symbolData = [NoValue] * len(t)
#put a symbol at the closing price position of the 21st session
symbolData[20] = close[20]

#add the symbol to the main price chart
self.mainChart.addScatterLayer(None, symbolData, "Natural", TriangleSymbol, 11, 0x33ff33)

Hope this can help.

Regards
Peter Kwan

  Re: FinanceChart and addScatterLayer
Posted by MarkZB on Jun-09-2018 14:06
Attachments:
Hi Peter

I believe my issue is similar. I want to add "Completed Orders" to the Finanace Chart using...

// Add scatter layer, using 11 pixels green (33ff33) circle symbols
mainChart.addScatterLayer(dataX1, dataY1, "Completed BUYS", Chart.CircleShape, 11, 0x33ff33);

How do I calculate dataX1 from the timestamp of the completed orders?
CompletedOrders.png

  Re: FinanceChart and addScatterLayer
Posted by MarkZB on Jun-09-2018 16:38
ok i worked it out

this method helps...

public static int GetIdxOfClosestTime(DateTime fileDate, DateTime[] viewPortTIMESTAMPS)
        {
            DateTime closestDate;
            long min = long.MaxValue;
            int closestIdx = 0;
            int idx = 0;
            foreach (DateTime date in viewPortTIMESTAMPS) {
                if (Math.Abs(date.Ticks - fileDate.Ticks) < min) {
                    min = Math.Abs(date.Ticks - fileDate.Ticks);
                    closestDate = date;
                    closestIdx = idx;
                }
                idx++;
            }
            return closestIdx;
        }/