Accessing indicators from X bars ahead when shifts are applied

Created at 21 Jan 2021, 00:12
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!
TO

TOPGUNFX

Joined 20.08.2019

Accessing indicators from X bars ahead when shifts are applied
21 Jan 2021, 00:12


Hello,

Is it possible to retrieve the value of an indicator from X periods in the future (obviously with a shift applied to the indicator)? For example, the Alligator indicator with the following shifts applied (standard parameters):

ali = Indicators.Alligator(13, 8, 8, 5, 5, 3);
  • Jaws
    • Periods=13,
    • Shift=8
  • Lips
    • Periods=5
    • Shift=3
  • Teeth
    • Periods=8
    • Shift=5

To retrieve the Lips value from 1 bar in the past I can do:

ali.Lips.Last(1)

But when I try to retrieve the Lips value from 1 bar ahead it returns NaN:

ali.Lips.Last(-1)

On the chart the indicator values are available for X bars ahead (8, 3, 3 in this case). How do I access these values from X bars ahead from a cAlgo Robot? 

Thanks


@TOPGUNFX
Replies

PanagiotisCharalampous
21 Jan 2021, 08:35

Hi TOPGUNFX,

The last value of the indicator is always Last(0), shifted or not. If you want assosiate the indicator values with the bars then you need to take into consideration the shift as well. For example, based on your example above, the Jaws value that corresponds to Bars.Last(0) is alligator.Jaws.Last(13);

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous