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

Message ListMessage List     Post MessagePost Message

  how to position a Chart, both X and Y
Posted by Chuck Van Dien on Jan-16-2021 05:38
Peter,

I am automating a reporting function where I create a .PNG of my financial chart at the end of each day.

To be consistent across all .PNG’s (days) it would be nice for the Chart to be in the same position (open to close) except according to each new day... (ideally, each chart would be programmatically adjusted a few bars before open, of each day).

I already have automated the zoom to be consistent, but I don’t know how to programmatically move the viewport horizontally to this “few bars before the open”.

I obviously know the DateTime of this bar... is there a way to programmatically move the viewport to begin at a certain DateTime (I also can convert DateTime to a bar index Integer)

Thank you for your help.
Chuck

  Re: how to position a Chart, both X and Y
Posted by Peter Kwan on Jan-16-2021 21:28
Hi Chuck,

Normally, if a financial chart contains more than one day, then the bars before the opening of each day are the bars of the previous day.

If you only want to display one day of data, you still need the data from the previous days to compute indicators. So to display a few bars before open, simply set the visible data to include a few bars from the previous day.

If you set the bars from the previous day to Chart.NoValue (for OHLCV data), then you would see the bars from the previous day. That period will appear blank. But then the indicators will not be computed correctly. If your chart does not display any indicators, then this may be an option. Just add a few bars before open and set those to Chart.NoValue.

Another option is to use Axis.setMargin to add some blank space before the starting point of the x-axis. If you are suppose to display 100 bars, but you only have 98 bars and you want to shift the open point to the right by two bars, you can set an axis margin equal to two bar's width. It is like:

myMainChart.xAxis().setMargin(0, Math.Round(2 / 100.0 * myMainChart.getPlotArea().getWidth()));

The setMargin to apply to the top chart in the FinanceChart. The above code assumes the top chart is the main price chart. If you have an indicator chart before the main price chart, the setMargin should apply to the top indicator chart.

Regards
Peter Kwan

  Re: how to position a Chart, both X and Y
Posted by Chuck Van Dien on Jan-16-2021 23:13
>If you only want to display one day of data, you still need the data from the previous days
>to compute indicators. So to display a few bars before open, simply set the visible data to
>include a few bars from the previous day.

This is what I would like to do... how is this specifically accomplished?

Thank you,
Chuck

  Re: how to position a Chart, both X and Y
Posted by Peter Kwan on Jan-18-2021 17:32
Hi Chuck Van Dien,

In Chartdirector, your data are in data arrays. To plot a finance chart for a certain day, the data array obviously needs to contain the data for that day. It also needs to contain the data from the previous day as they are needed to compute technical indicators. For example, if one day has 100 bars, your data array may contain 130 bars, with 30 bars from the previous day before the start of the day, and 100 bars for the data you want to plot. (The 30 bars is only an example. It depends on what technical indicator you want. If you have a 250 session moving average, you need 249 bars from the previous days.)

Suppose you have 130 bars with 30 bars from the previous day. In FinanceChart.setData, there is an "extraPoint" parameter. It is normally set to 30. In this way, ChartDirector knows that the first 30 bars are not to be plotted. So only the last 100 bars are plotted.

If you want to include the 2 bars from the previous day, you can set the extraPoint parameter to 28 instead of 30.

Regards
Peter Kwan

  Re: how to position a Chart, both X and Y
Posted by Chuck Van Dien on Jan-18-2021 20:33
Hi Peter,

I appreciate the walk through of the concept... my question is centered around the specific ChartDirector function(s) that allow me to position the viewport according to my needs.

Can you provide a code example VB.Net?

Thank you!
Chuck

  Re: how to position a Chart, both X and Y
Posted by Peter Kwan on Jan-18-2021 21:59
Hi Chuck,

By "viewport", do you mean the "viewport" that is typically used in Zoomable and Scrollable charts?

Assuming you are using array index as the full x-range of the viewport (which is typically the case for Financial Charts), and you know the array index of the bar you want to be the first visible bar, the viewport left must be:

Dim vpLeft As Double = viewer.getViewPortByValue("x", beginIndex)

If you know the array index N of the first bar of the day, then the array index of the first visible bar must be N - 2, assuming you want 2 bars from the previous day to be visible on the chart.

Regards
Peter Kwan