|
FinanceChart and AddScatterLayer |
Posted by Robby Stamper on Jul-09-2022 03:28 |
|
Hi,
I have used ".addScatterLayer()" in the past to add trades to a chart. I recently implemented the FinanceChart from the sample code, but .addScatterLayer is not a method on the FinanceChart object.
Is it possible for me to add trades to a FinanceChart similar to .addScatterLayer()?
Thanks!
Robby Stamper
James River Capital Corp
804-928-1799
m.addScatterLayer(buyXs, buyYs, "Long - Buys", Chart.TriangleSymbol, 10, 0x008800); |
Re: FinanceChart and AddScatterLayer |
Posted by Peter Kwan on Jul-09-2022 22:52 |
|
Hi Robby,
The FinanceChart is a container that can contain a main price chart and other technical indicator charts (RSI, MACD, etc). The addScatterLayer needs to apply to the chart you want the scatter symbols to appear. If it is applied to the FinanceChart itself, ChartDirector cannot know which chart you want to add the scatter symbols to.
The following is an example that adds scatter symbols to the main price chart in a FinanceChart:
https://www.advsofteng.com/doc/cdnet.htm#financesymbols.htm
Best Regards
Peter Kwan |
Re: FinanceChart and AddScatterLayer |
Posted by Robby Stamper on Jul-11-2022 23:41 |
|
Thanks Peter,
I found that sample code on late Friday and implemented it. However, my trades are not showing up on the chart.
I have tried setting my X values to the DateTime() timestamps in the chart. I have tried setting my X values to the xth index in the array of timestamps. Neither method works.
I also noticed that in your sample code, you pass a null for the x array.
Could you please advise what the x Values should be when using it in a FinanceChart? The Y values don't need to be adjusted in any way do they? Do I need to bring these scatter layers to the foreground? Is it possible that they are behind the Donchian Channel in the attached image?
I added the following code to my version of frmfinancedemo.cs. I added it in the drawChart() method. Your example had it in the createChart() method. I think that difference has to do with the fact that the finance chart that I implemented is scrollable.
Many Thanks in advance. Robby
// Add scatter layer, using 11 pixels green (33ff33) circle symbols
XYChart mainChart = m.addMainChart(255);
ScatterLayer buyLayer = mainChart.addScatterLayer(sellXs, sellYs, "Long - Sells", Chart.InvertedTriangleShape, 11, 0x00ffff);
buyLayer.getDataSet(0).setSymbolOffset(0, 20);
// Add scatter layer, using 11 pixels blue (3333ff) triangle symbols
ScatterLayer sellLayer = mainChart.addScatterLayer(buyXs, buyYs, "Long - Buys", Chart.TriangleSymbol, 10, 0x008800);
sellLayer.getDataSet(0).setSymbolOffset(0, -20);
// output the chart
viewer.Chart = m;
|
Re: FinanceChart and AddScatterLayer |
Posted by Peter Kwan on Jul-12-2022 01:35 |
|
Hi Robby,
The y-array should be similar to other arrays (such as the high, low, open, close arrays) in the FinanceChart. All these arrays use the timeStamps array as the x-coordinates, so you do not need to provide x-coordinates.
For your case, if there is a symbol at a particular position, you can put the position of the symbol in the corresponding y-array element. If there no symbol at a particular position, you can put Chart.NoValue in the array element.
The following is how we do this is our sample code:
// The y-data array are the same size as all other data arrays
double[] buySignal = new double[closeData.Length];
......
// Iterate all the positions (all arrays should be of the same size, so the
// sma5.Length should be the same length as the timeStamps array)
for(int i = 0; i < sma5.Length; ++i) {
// The default is no symbol
buySignal[i] = Chart.NoValue;
if (i > 0) {
// If there is a buy signal, put the position of the symbol in the array element
if ((sma5[i - 1] <= sma20[i - 1]) && (sma5[i] > sma20[i])) {
buySignal[i] = lowData[i];
}
}
}
Hope this can help.
Regards
Peter Kwan |
|