condition to check back 50 bars from the current bar

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #118652 quote
    Johann
    Participant
    Average

    Hi Nicolas,

    I would like to code a condition which check previous bars whether the short term MA is above or below a long term MA. For example if I want the condition to check back 50 bars from the current bar if the 5MA is above the 10MA. Can you please help with the code. Thank you.

    #118654 quote
    Nicolas
    Keymaster
    Master

    Create a variable that check if the shorter average is above the longer one:

    test = average[5]>average[10]

    Then use an offset of that condition 50 bars back in your code:

    if test[50] then 
     // ... do something 
    endif
    Johann thanked this post
    #118655 quote
    Vonasi
    Moderator
    Master

    Just to clarify things a little. The current bar/candle is bar zero so if you want to check 50 bars back and the count includes the current bar then it would be test[49]. If you want to check 50 bars back and not include the current bar in the count back then it is test[50] you need.

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

condition to check back 50 bars from the current bar


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Johann @johann Participant
Summary

This topic contains 2 replies,
has 3 voices, and was last updated by Vonasi
6 years ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 02/04/2020
Status: Active
Attachments: No files
Logo Logo
Loading...