how do i calculate the value of an indicator on Nth previous bar?

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #175711 quote
    borderlineJim
    Participant
    Senior

    hello again

    I was wondering if any of the programming wizards could help with some simple code…

    I would like to calculate the value of an indicator (ATR) on a previous bar so that I can potentially open positions if the volatility is rising…  I was thinking of using just 2 bars for this.  This will act somewhat like a filter.

    Simply put:  if after 2 bars the volatility is rising based on the ATR value, then I will look to open a position on the 3 bar (using a trigger from a lower time-frame).  I hope this makes sense.

    Kind Regards

    Jim

    #175719 quote
    robertogozzi
    Moderator
    Master

    Simply use [N] to refer to the previous Nth bar.

    ATR = AverageTrueRange[14](close)
    IF ATR[2] THEN    //check the ATR value 2 bars ago
     .
     .
    ENDIF
    borderlineJim thanked this post
    #175762 quote
    borderlineJim
    Participant
    Senior

    thanks again Roberto!

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

how do i calculate the value of an indicator on Nth previous bar?


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by borderlineJim
4 years, 6 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 08/19/2021
Status: Active
Attachments: No files
Logo Logo
Loading...