|
get x coordinate of DateValue in Finance Chart |
Posted by Mahbub on Aug-04-2013 23:50 |
|
Hello Peter, How are you? I am very grateful to you and your company for helping a CSc. students like me. Now I'm working on a Graphics Project, that can draw lines, fibo etc. on a Finance chart. I have done it with Microsoft LineShape control in VB .net.
1. Now the problem arises during zooming (with view port) and scrolling. I want the drawings should be enlarged or shrinked or moved during zooming and scrolling.
In my logic, I can calculate the y coordinates. But I can't find the x coordinate of a given date value. Suppose a drawing started on 02-Jul-2013 candle and ends at 29-Jul-2013.
I can get those x coordinates in MouseMovePlotArea event. But in my database I save 02-Jul-2013 and 29-Jul-2013. When a user clicks on zoom button or clicks on Scrollbar, I want to find the current x coordinates of '02-Jul-2013' and 29-Jul-2013 in plot area, so that I can move the line shape accordingly. I have tried several options but failed. Could you please help me on this?
2. What is the best way to get a Candle Width in Candlestick finance chart?
Thanks in advance. |
Re: get x coordinate of DateValue in Finance Chart |
Posted by Peter Kwan on Aug-06-2013 02:10 |
|
Hi Mahbub,
1. In finanical charts, the date/time are rather arbitrary, unpredictable and somewhat random. It is because the date/time includes only trading dates and times. Trading days are affected by national and public holidays (which are different for every country), by natural disasters (eg. the stock exchange may cancel a trading day due to hurrican) or other events. So we cannot predict or calculate trading dates (eg. there is no formula to compute the number of trading days between "02-Jul-2013" and "29-Jul-2013".)
So in ChartDirector, the dates are treated as names. They are just for human reading. The actual x-coordinates are the trading session number. The first visible trading session is 0, the second visible trading session is 1 and so on. Trading session number determines the x-position of the chart elements.
So in your case, after you obtain the x-coordinate of the mouse click (in trading sessions), you may use it to determine the date. For example, if the user clicks on the 11th trading session (trading session number = 10), the date must be myTimeStamp(tradingSessionNumber + extraPoints). After zoom in, you can reverse the steps to determine the new trading session number of that date and use it to plot the line.
2. If you are using the FinanceChart object, the best method is to set the width with your own code (call the setDataWidth method of the CandleStickLayer object returned from FinanceChart.addCandleStick). If your code set the width, your code knows the width.
If you just need to know the approximate width (eg. to draw a selection rectangle around the candlestick), you may consider to just use the "slot" for a trading session as the width. The "slot" is the plot area width, divided by the number of trading session.
Regards
Peter Kwan |
Re: get x coordinate of DateValue in Finance Chart |
Posted by Mahbub on Aug-06-2013 06:36 |
|
Hi Peter,
You wrote - " After zoom in, you can reverse the steps to determine the new trading session number of that date and use it to plot the line." - How can I reverse the steps? Should I multiply the trading session with candle width? or use any builtin method like getxcoor.
getxcoor is not working, may be my fault. Could you please give an example?
When I took a screenshot of candlestick chart and measured the pixel width (in Photoshop) of each candle, it is variable - most of them are 7 pixel wide but some are 8 pixel in my 1 year chart. However, I can use your way to determine approximate width.
Thanks. |
Re: get x coordinate of DateValue in Finance Chart |
Posted by Peter Kwan on Aug-07-2013 00:20 |
|
Hi Mahbub,
In forward direction, your code first determine the x data coordinate (the trading session number) the user has clicked. Then your code add the "extraPoints" to get the array index. It can then read the date/time from your timeStamps array.
In the reverse direction, from the date/time, search (or binary search if efficiency is important) the timeStamps array to obtain the array index. Subtract the "extraPoints" to get the x data coordinate. If you would like to get the x pixel coordinate, you may use the XYChart.getXCoor of the XYChart you want to get the coordinate (the XYChart object that represents the main price chart if you want to draw on the main price chart). The XYChart.getXCoor can translate x data coordinates into x pixel coordinates.
For the candlestick width, I would expect in the same chart, all candlesticks would be of the same width. Of course, the candlestick widths can be different in different charts.
If the candlestick widths are not the same even in the same chart, is it possible to attach a sample, and inform me which two of the candlesticks are of different widths? I will investigate to see what would cause this issue.
Regards
Peter Kwan |
Re: get x coordinate of DateValue in Finance Chart |
Posted by Peter Kwan on Aug-07-2013 00:26 |
|
Hi Mahbub,
In my last message, when I refer to "candlestick widths", I mean the width of the candlestick symbol, not the spacing between two candlesticks. The spacing between the candlesticks is in general variable. For example, suppose the plot area is 800 pixels wide, and you have 137 candlesticks, so that the candlestick spacing should be 5.84 pixels. To keep the chart sharp and clear, the candlesticks should be drawn in integer positions. So most candlesticks would be 6 pixels apart, but some would be 5 pixels apart, so that the average will be 5.84 pixels apart.
Regards
Peter Kwan |
Re: get x coordinate of DateValue in Finance Chart |
Posted by Mahbub on Aug-07-2013 01:30 |
|
Ha ha, it's my fault to measure the candlestick width, I also measured the spaces in between.
I'll try your logic to locate x coordinate in pixel soon.
For the time being, thank you very much. Wish you a very happy life. |
|