reference historical OHLC x bars back for robot vs. indicator

Created at 30 Jul 2019, 08:39
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!
AI

Aiki1000

Joined 22.07.2019

reference historical OHLC x bars back for robot vs. indicator
30 Jul 2019, 08:39


Greetings all -

Very new to cTrader, so apologies for the questions — I have spent some time reviewing API and examining cTrader reference and community indicators and robot code to familiarize myself with the proper code syntax. Have built a few indicators, etc.

However, it seems like some of the examples in the guides are not in sync with the current API, and there are several ways to do things, and none explicit (at least to me…) so a bit confused, and some guidance will be very much appreciated. I am used to finding my own answers in the docs, but not having any luck. Maybe it is just me…So, please:

Referencing bars

A - is there one way to do it that is correct syntax for indicators, but different syntax to reference bars back for robots? If so, what are those methods, and is there any other piece of code necessary to make it work?

 

In robot for ex., I put code in OnBar, since OHLC needs a finished bar to reference. Does this make sense?

I can see it requires MarketSeries and Last, or LastValue.

Either square (or round) brackets, and an int to hold the index, or (not, if no index). 

Some examples reference using (1) (2), but some others reference (-2), etc.

(Arrays in C# usually count from 0, so I was even wondering about how that fit in…)

 

Rather than me post code to all the things I have tried to work this out myself by printing variations to the log and hand checking the history on the charts - if anyone can set me straight or point me to documentation that isn't contradicted elsewhere, or deprecated in the API, I would be most grateful.

 

so...For robot:

Create variables for OHLC of last closed bar 

Create variables for OHLC of bar before that

Thanks so very much


@Aiki1000
Replies

PanagiotisCharalampous
30 Jul 2019, 09:37

Hi Aiki1000,

Thanks for posting in our forum. If you need the last value of a DataSeries, use LastValue. If you need any value before the last value, use Last(x) with x counting backwards e.g. if you need the bar before the last value, use Last(1).

Best Regards,

Panagiotis


@PanagiotisCharalampous

Aiki1000
30 Jul 2019, 18:47

RE:

Panagiotis Charalampous said:

Hi Aiki1000,

Thanks for posting in our forum. If you need the last value of a DataSeries, use LastValue. If you need any value before the last value, use Last(x) with x counting backwards e.g. if you need the bar before the last value, use Last(1).

Best Regards,

Panagiotis

Thank you Sir!

That settles that...perfect. And this sytax is the same for either robots, or Indicators, correct?

Again, I really apprecaite the response.


@Aiki1000

PanagiotisCharalampous
31 Jul 2019, 09:15

Hi Aiki1000,

Yes it is the same for both.

Best Regards,

Panagiotis


@PanagiotisCharalampous