Representation of coordinates on a chart

Created at 05 Apr 2021, 20:48
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
ST

strakmi

Joined 30.12.2020

Representation of coordinates on a chart
05 Apr 2021, 20:48


Hi,

I have built a few cBots by now and I'd love to hear if the other developers here came into the problem of representing a point on a chart.

If you want to represent a point on the price chart, you need two coordinates to do so. The y-coordinate is obviously the price at the point, but you can use either its DateTime or the index of the closest bar for the x-coordinate.

Both of those approaches have their advantages - cAlgo natively goes with the DateTime option, for example when drawing lines between points. However, this approach hits its limits when you want to perform some analysis of multiple points. I don't see a way to do a simple linear regression or any statistical analysis of points scattered on a nonlinear scale in the DateTime format.

On the other hand, if you define the x-coordinate of each point as the index of the nearest bar, you don't run into any issues when doing statistics on them. I, however, don't like that it is inconsistent with the cAlgo API and not as precise as the DateTime format. The bars may also get reindexed at some point, for example when you load more price history, which creates more potential issues.

What's your take on this issue? Could there be another way to solve it?


@strakmi
Replies

amusleh
06 Apr 2021, 11:23

Hi,

You can change date time to a numerical unit like Unix time and then use it instead of date time for your statistical models, as I know all time series data uses the date time for x coordinate.


@amusleh