|
add additional data to finance chart |
Posted by John on Aug-22-2013 15:53 |
|
hi,
i want to add a set of trades data to indicate when i traded on a particular stock to a
finance chart i am coding in .NET 4.0 (C#). i'm planning to use a groupbox (as per this
link: http://www.chartdir.com/forum/download_thread.php?
bn=chartdir_support&pattern=&thread=1284968737) or just the winchartviewer windows
form component to display the chart in my windows form program.
basically, i am looking to indicate certain points on the candlestick chart, using a
combination of dots above the candlesticks and a tooltip to display additional information
- such as entry price, exit price and time of trade. the data will be read in from a
CSV/text file and stored as arrays (eg double[] entryPrice, double[] exitPrice, DateTime[]
tradeTime etc.).
how do i incorporate such data into the finance chart? or would i be required to shift to
a candlestick-based XY chart to accommodate this additional data?
i have attached a file with my code, with commented sections to indicate the point(s) in
my code where i intend to add the data. i have also attached two charts - a sample
chart (my current output), and a sample chart for my desired output to visually explain
what i am trying to achieve.
how do i plot dots/squares/etc. to indicate the positions i have taken (buy & sell)
according to the relevant time? since the date/time indicators on the x-axis are only for
users to read - and it is trading sessions that are used as x-axis indicators, what
parameters do i need to use in order to match up the trades data i have with the
candles at the same time? (eg length of datetime[] tradeTime array versus length of
datetime[] candleTimes array, etc.)
Let me know,
Thanks,
John
|
|
finchartcode.txt |
---|
var myTuple = f1.myDBRead(stockSymbol, date);
DateTime[] candletimesArray = myTuple.Item1;
double[] lowData = myTuple.Item4;
double[] openData = myTuple.Item2;
double[] closeData = myTuple.Item5;
double[] highData = myTuple.Item3;
double[] volumeData = myTuple.Item6;
//THIS IS THE CODE TO DOWNLOAD MY CSV DATA
var myTuple2 = f1.myCSVRead(stockSymbol, date);
DateTime[] candletimesArray = myTuple2.Item1;
double[] entryPrice = myTuple2.Item2;
double[] exitPrice = myTuple2.Item3;
//THERE WILL BE AN INITIAL MISMATCH IN LENGTH OF THE DATA ABOVE, AND THE OHLC DATA
//I CAN CORRECT THIS AS REQUIRED, BUT WOULD APPRECIATE ANY SUGGESTIONS
int extraDays = 0;
FinanceChart c = new FinanceChart(640);
//title and other styling code
c.setData(candletimesArray, highData, lowData, openData, closeData, volumeData,
extraDays);
//HERE IS WHERE I WANT TO ADD CAPABILITY OF DISPLAYING THE EXTRA DATA ON THE SAME CHART
//HOW DO I DO THIS?
c.setPlotAreaStyle(0xffffff, 0xdddddd, 0xffffff, 0xffffff, 0xffffff);
c.addMainChart(240);
c.addCandleStick(0x00EE00, 0xE65C01);
c.addVolIndicator(75, 0xff00ff, 0xff00ff, 0xff00ff);
viewer.Chart = c;
//existing tooltip
viewer.ImageMap = c.getHTMLImageMap("clickable", "",
"title='{xLabel} \\nHigh:{high}\\nOpen:{open}\\n" +
"Close:{close}\\nLow:{low}'");
//DESIRED TOOLTIP
viewer.ImageMap = c.getHTMLImageMap("clickable", "",
"title='{xLabel} \\nEntry:{entry}\\nExit:{exit}\\n" +
"Time of Trade:{tradeTime}'"); |
| |
Re: add additional data to finance chart |
Posted by Peter Kwan on Aug-23-2013 01:07 |
|
Hi John,
First, you would need to inform ChartDirector the position of your symbols. This can be done
by using a scatter layer. An example is:
XYChart mainPriceChart = c.addMainChart(240);
ScatterLayer mySpecialLayer = mainPriceChart.addScatterLayer(null,
mySymbolPositionArray, "ABC", Chart.SquareSymbol, 9, 0xff0000);
In the above, the mySymbolPositionArray are the position of the symbols expressed in price.
The arrary length should be the same as all other arrays (same length as candletimesArray
or closeData array). If there is no symbol for a particular trading session, please use
Chart.NoValue as the symbol position. The "Chart.SquareSymbol, 9, 0xff0000" are the
shape, size and color of the symbol. If there are more than 1 type of symbols, please use
additional scatter layers.
For the tooltips, you can use anything you like. You just need to provide the tooltips as an
array of text strngs. The code is like:
mySpecialLayer.addExtraField(myArrayOfTooltips);
mySpecialLayer.setHTMLImageMap("", "", "title='{field0}'");
Note that the myArrayOfTooltips should only contain tooltips for visible positions, so its
length should be equal to the length of candletimesArray, minus extraDays.
Hope this can help.
Regards
Peter Kwan |
Re: add additional data to finance chart |
Posted by John on Aug-29-2013 01:55 |
|
Hi Peter,
Thanks for your reply. I was successfully able to chart the scatter layer of my positions
over the finance chart.
However, there is still a lingering issue that prevents me from getting the result I want.
The function addScatterLayer requires a double[] input for both x and y data. this is unlike
the setData() function, which takes a DAteTime[] input for timestamps on the x-axis.
Because of this, there is a mismatch in the positions of the trades data, with respect to the
candlesticks and their times.
My question is this: how do I input the same datetime[] array is the x-input for
addScatterLayer so that the scatter plot shows up exactly in line with the candles? if this
isn't a possibility, is there any way to convert this datetime[] array to double[] for use in
the addScatterLayer function?
Let me know,
Thanks,
John |
Re: add additional data to finance chart |
Posted by Peter Kwan on Aug-30-2013 02:37 |
|
Hi John,
In a financial chart, there is no need to specify the timestamps for a data series. The timestamps are just for human reading on the x-axis.
For your scatter layer, is your scatter data array the same length as any other data arrays? For example, if the closeData array has 200 points, does you scatter data array also has 200 points?
If the scatter data array has the same number of points as the closeData array, the points should match one to one. So if you would like to put a symbol at the same position as closeData[30], you just need to put the symbol data point at myScatterData[30].
If there are no symbols at certain positions, please put Chart.NoValue in those positions in the scatter data array.
For the x-coordinates in addScatterLayer, simply use null as suggested in my earlier message.
Hope this can help.
Regards
Peter Kwan |
|