Moving AVerage Crossover for Multiple days

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #140301 quote
    ZionTrader
    Participant
    New

    Good day,

    I was wondering if anyone can assist with with a moving average cross for a number of days. For example below is the bearish moving average which shows all the instruments where its 50 day moving average crosses below its 200 moving average for today. However, I don’t want just today’s bearish Moving average crossover , but I want to see the last 5 days. If anyone can assist I would really appreciate it.

    REM Calculate a simple moving average over the last 50 days
    ma50 = AVERAGE[50]
    
    
    REM Calculate a simple moving average over the last 200 days
    ma200 = AVERAGE[200]
    
    
    REM Calculate the speed at which the short MA crosses under the long MA
    speed = MOMENTUM(ma50-ma200) * 100 / CLOSE
    
    
    REM Display securities for which short MA has just crossed under long MA.  Show the fastest crossings first.
    IF ma50 CROSSES UNDER ma200 THEN
    SCREENER (speed AS "Speed")
    ENDIF

    Thanks.

    #142631 quote
    kaq52
    Participant
    Average

    Hi, please find attached.

    I have set the field “DayCount = 4” covering five days, change it to any number (e.g., changing it to 9 will give crossover in last 10 days).

    Have fun …kaq52

    //Author KAQ52
    //This screener finds crossover of two averages in last n days
    
    DayCount = 4  //change it as appropriate
    
    REM Calculate a simple moving average over the last 50 days
    ma50 = AVERAGE[50]
    REM Calculate a simple moving average over the last 200 days
    ma200 = AVERAGE[200] 
    REM Calculate the speed at which the short MA crosses under the long MA
    speed = MOMENTUM(ma50-ma200) * 100 / CLOSE
    
    
    Crossover=0  //flag for detecting crossover
    
    
    For i = 0 to daycount
    if (ma50[i] crosses over ma200[i]) or (ma50[i] crosses under ma200[i]) then
    CrossOver=1
    break
    endif
    next
    
    
    REM Display securities for which short MA has just crossed under long MA.  Show the fastest crossings first.
    
    SCREENER [Crossover] (speed AS "Speed")
    
    
    Average-Crossover-screener.itf
    #142643 quote
    robertogozzi
    Moderator
    Master

    Replace lines 17-22 with this ONE:

    CrossOver = summation[DayCount]((ma50 crosses over ma200) or (ma50 crosses under ma200))

    As for your FOR…NEXT iterations, 0 TO DAYCOUNT will check the last 5 periods, while summation 4 (the last 4, not 0 to 4).

    ZionTrader thanked this post
    #142664 quote
    kaq52
    Participant
    Average

    Thanks RobertGozi, your solution looks much precise.

    My understanding so far is that “for i = 0 to daycount” with daycount=4 loop will get below five values, thus covering five days(including current one). Is this understanding not correct please?

    ma20[0] —current candle

    ma20[1]

    ma20[2]

    ma20[3]

    ma20[4]

    ZionTrader thanked this post
    #142669 quote
    robertogozzi
    Moderator
    Master

    Yes, that’s correct.

    Summation, instead, with the same value for DayCount you’ll check one less bar, 0 to 3.

    #142798 quote
    ZionTrader
    Participant
    New

    Thank you very much for assistance. Appreciated.

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

Moving AVerage Crossover for Multiple days


ProScreener: Market Scanners & Detection

New Reply
Author
author-avatar
ZionTrader @ziontrader Participant
Summary

This topic contains 5 replies,
has 3 voices, and was last updated by ZionTrader
5 years, 6 months ago.

Topic Details
Forum: ProScreener: Market Scanners & Detection
Language: English
Started: 07/28/2020
Status: Active
Attachments: 1 files
Logo Logo
Loading...