Check if two MA's crossed within lasts 120 candles

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

    Is there a way to know if two MA’s crossed within the lasts 120 candles?

    #12584 quote
    Nicolas
    Keymaster
    Master

    1472825722_flagPlease update your country flag in your profile. Thank you 🙂

    You can make a test with a summation of successful boolean condition:
    test = summation[120](ma1 crosses over ma2)>0
    If test returns “1”, it is true that a moving average crossover has occurred within the last 120 candlesticks.
    grizzly thanked this post
    #12586 quote
    Johan
    Participant
    Average
    I came up with…
    // No trade during consolidation
    if (MA200 crosses under MA400) or (MA200 crosses over MA400) then
    noTradeBar = barIndex[0]
    noTrade = 1
    endif
    
    if (noTradeBar + 120 < barIndex) then
    noTrade = 0
    endif
    
    graph noTrade
    But your code looks a bit more compact 🙂 Going to try it out. Thanks!
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.

Check if two MA's crossed within lasts 120 candles


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Johan @johan_holmberg Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by Johan
9 years, 5 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 09/01/2016
Status: Active
Attachments: No files
Logo Logo
Loading...