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

Message ListMessage List     Post MessagePost Message

  scrolling finance chart
Posted by Markus on Apr-12-2007 22:14
Hi!
I'm currently a novice in using ChartDirector and I have a question scaling and scrolling DateTime axis for financial charts.
Usually backtesting trading strategies need a certain number of data to check your strategy. As a feedback of all the executed trades there will be a small pic shown on the chart. the viewport of the the data will be only 30 days in a history about 10 years(that's an example! it could be a 5min chart showing the last six month otherwise).
How should I implement the scaling of the axis or realizing the scrolling?
Do you have any ideas?

thank you for your answer!

markus

  Re: scrolling finance chart
Posted by Peter Kwan on Apr-13-2007 04:37
Hi Markus,

Typically, in ChartDirector, you may scroll or rescale the chart by drawing another chart with the time range you want. For example, if you want to view the last 30 days of data, then you may plot the chart using the last 30 days of data. If the user then want to see another 30 days or data, you may redraw the chart using another 30 days of data.

You may use another user interface you want for the scrolling or zooming. It usually depends on the GUI framework you using (eg. the exact method for a web application, MFC application, Java SWING application, etc., may be different).

For example, in a Windows application, you may use a scroll bar. When the user moves the scroll bar, your code can handle the scroll event to determine which date range the user want to view, and redraw the chart using that date range. Some other common methods to select the date range include using a "calendar control" to select the dates, or simply use drop down list boxes, etc..

There are two "Zoomable and Scrollable Chart" examples that come with ChartDirector. May be you can try them to see how well this method works.

Hope this can help.

Regards
Peter Kwan

  Re: scrolling finance chart
Posted by Alden on Oct-14-2010 17:04
Hi Peter,

Are there any examples of zooming and scrolling a finance chart in a java swing
application?

Thanks!

  Re: scrolling finance chart
Posted by Peter Kwan on Oct-15-2010 03:33
Attachments:
Hi Alden,

There is an example somewhere in this forum, but it is in VB6. I have just ported it to Java SWING as attached.

Basically, you just need replace the XYChart code with the FinanceChart code in the Zooming and Scrolling Demonstation sample code.

Hope this can help.

Regards
Peter Kwan
ZoomScrollDemo3.java
ZoomScrollDemo3.java

26.50 Kb

  Re: scrolling finance chart
Posted by Alden on Oct-15-2010 03:40
Brilliant, thanks Peter! I will have a go at that!

  Re: scrolling finance chart
Posted by Alden on Oct-22-2010 17:06
Hi Peter,

Further to the above example, is there a similar function to
"viewer.setMouseUsage(Chart.MouseUsageScrollOnDrag);" for Keyboard input? I want to
be able to zoom in/out and scroll left/right using the arrow keys on my keyboard. I've
written all the keylisteners etc, but struggling to implement events that will provide this
functionality.

Many thanks!

  Re: scrolling finance chart
Posted by Peter Kwan on Oct-23-2010 02:42
Hi Alden,

Like all standard Java SWING controls for displaying images, the image is not capable of receiving keyboard focus. So there is no keyboard actions for the ChartViewer control.

For your case, you would need to have a control that is capable of receiving keyboard focus, and attach the keyboard event handler to that control.

Hope this can help.

Regards
Peter Kwan

  Re: scrolling finance chart
Posted by Alden on Feb-09-2011 07:37
Hi Peter,

I am displaying a chart in an Internal frame in java. I fill the frame with the chartviewer
chart as follows:

int frameheight = this.getContentHeight();

int chartHeight = (frameheight - topMargin - bottomMargin);
int indicatorHeight = (frameheight - topMargin - bottomMargin) * 2 / 12;

        if (!indicatorArray.isEmpty()){
              chartHeight = chartHeight - (indicatorHeight*indicator_count);
        }

When no indicator is added, the chart fits perfectly in the internal frame window.
However, when i add any indicator window to the chart, it overlaps the bottom of the chart
window. I can't seem to get the chart and indicator windows to fit together properly/evenly
spaced out in the internal frame window.

Any suggestions?
Many thanks!

  Re: scrolling finance chart
Posted by Peter Kwan on Feb-10-2011 01:41
Hi Alden,

To diagnose the problem, you may print out the variables frameheight, chartHeight and indicatorHeight. Then you may take a screen shot and use Windows Paint or any graphics editor to measure the chartHeight and indicatorHeight to see if they are the same as the heights you specified. This can confirm if ChartDirector is drawing the chart accurately as specified by your code.

Note that in the standard FinacenChart in ChartDirector Ver 5, there is a configurable gap between the various charts (see FinanceChart.setPlotAreaBorder). The default is 2 pixels.

If the above still does not solve the problem, would you mind to attach a screen shot and inform me what are the parameters frameheight, chartHeight and indicatorHeight. I will try to see if I can find any clue as to the cause of the problem.

Hope this can help.

Regards
Peter Kwan

  Re: scrolling finance chart
Posted by Alden on Feb-10-2011 19:13
Attachments:
Hi Peter,

I've only added the frame height values, as the width draws correctly. Note that I am
working on OSX.

Values printed to the output screen are as follows:

Frame height: 980
Chart height: 817
Indicator height: 163

The top and bottom margin values are both zero.

Using the code in the previous post, this is how it displays the chart in an internal frame.

Regards,
Allan
Screen shot 2011-02-10 at 11.07.50.jpg

  Re: scrolling finance chart
Posted by Peter Kwan on Feb-11-2011 02:26
Hi Alden,

The top margin is not 0 when the chart is first drawn (you can see around 25 pixels margin at the top of the chart). So I suspect your code is changing the margin on the fly when the chart is half-drawn. As a result, the position of the charts are computed using inconsistent margins, causing the problem.

To solve the problem, please set the margins before any chart is drawn. For example, you may set the margins immediately after creating FinanceChart object (before add the main price chart or any other chart).

Hope this can help.

Regards
Peter Kwan

  Re: scrolling finance chart
Posted by Alden on Feb-14-2011 04:06
Figured it out eventually! Thanks for the help.

  Re: scrolling finance chart
Posted by Stefano on Jun-11-2014 12:53
Attachments:
Hi,

I'm currently evaluating your Java API and used your great piece of code to create a basic
financial chart that is scrollable and zoomable.

I have a few questions regarding your code (I have attached a slightly modified version):

- The first thing I noticed is, when zooming or scrolling the chart, the redrawing for the
indicators seems incorrect. I think it has to come from the data selection when focusing on
a period. For example, the bollinger band with a period of 20 days will always omit the first
20 points, even if it is possible to compute everything from the broader range.

-  How can I achieve to have a track line across all the graph like in the example "Zooming
and Scrolling with Track Line (2)". I have tried to take part of the source code from this
example to adapt it to your code, but without success.


Thanks a lot.
ZoomScrollDemo3.java
ZoomScrollDemo3.java

32.21 Kb

  Re: scrolling finance chart
Posted by Peter Kwan on Jun-12-2014 03:02
Attachments:
Hi Stefano,

If you have technical indicators, you may add extra leading data values to the data series
that are passed to ChartDirector. I have attached the modified code for your reference. (It
is the same as your original code but with two lines added to account for the extra points.)

Hope this can help.

Regards
Peter Kwan
ZoomScrollDemo3.java
ZoomScrollDemo3.java

32.28 Kb

  Re: scrolling finance chart
Posted by Stefano on Jun-13-2014 09:22
Attachments:
Thanks for your fast and precise reply.

here is attached my version of a simple scrollable/zoomable Finance chart with a trackline
for future users.

Quick question: what is the benefit of moving to the licensed API ? We're only considering
this API for internal development.

Regards
ZoomScrollDemo3.java
ZoomScrollDemo3.java

35.82 Kb

  Re: scrolling finance chart
Posted by Peter Kwan on Jun-13-2014 23:33
Hi Stefano,

For licensing enquiries, please kindly send an email to sales@advsofteng.net. We are unable
to respond to license related enquiries here.

Regards
Peter Kwan