condition to check back 50 bars from the current bar

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #118652 quote
    JohannJohann
    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
    NicolasNicolas
    Keymaster
    Legend

    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
    VonasiVonasi
    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.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

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 VonasiVonasi
6 years, 8 months ago.

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