Moving average cross with MACD

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #248566 quote
    segie
    Participant
    Senior

    Hi,

    Please help me with a screener

    1.Price moving average 20 cross e.g. over
    2. Refer to attached code. I need a condition where the moving average cross takes place under conditions/ during the times where e.g. the zerolagMACD is currently/must be trading over signalMACD and vice versa, at the time of the moving average cross (note: not referring to the point where both need to cross at the same time).
    3. trading range macd e.g 0 to 0.1

    Regards,
    Segie

    // — settings
    short = 12
    long = 26
    signal = 9
    / — end of settings
    MAshort1 = exponentialaverage[short](close)
    EMAshort2 = exponentialaverage[short](EMAshort1)
    DifferenceShort = EMAshort1 - EMAshort2
    ZeroLagShort = EMAshort1 + DifferenceShort
    flag=0
    
    EMAlong1 = exponentialaverage[long](close)
    EMAlong2 = exponentialaverage[long](EMAlong1)
    DifferenceLong = EMAlong1 - EMAlong2
    ZeroLagLong = EMAlong1 + DifferenceLong
    
    ZeroLagMACD = ZeroLagShort - ZeroLagLong
    
    signal1=ExponentialAverage[signal](ZEROLAGMACD)
    signal2=ExponentialAverage[signal](signal1)
    DIFFERENCE2=signal1-signal2
    SignalMACD=signal1+DIFFERENCE2
    
    if zerolagMACD crosses over signalMACD then
    flag=1
    endif
    if zerolagMACD crosses under signalMACD then
    flag=2
    endif
    
    // Price between 1-20
    PriceRang = close>=3 and close<=10
    
    screener [flag=2 and PriceRang](flag as "flag")
    #248567 quote
    robertogozzi
    Moderator
    Master

    Can you better explain rule 2?

    #248568 quote
    segie
    Participant
    Senior

    Please see attached.

    When 20ma cross takes place it must correspond with the appropriate color of the MACD.

    E.g Whith Bull MA cross then MACD must also be in the ‘blue’. zerolagMACD currently trading over signalMACD

    If there’s a bull MA cross but MACD in the ‘red’ then shouldn’t be part if the screened items. i,e zerolagMACD currently trading under signalMACD

    Both must align.

    PRC-MACD-20X.png PRC-MACD-20X.png
    #248582 quote
    Iván González
    Moderator
    Master

    Hi! I think instead using flags you should just code macd>signal.

    // — settings
    short = 12
    long = 26
    signal = 9
    
    EMAshort1 = exponentialaverage[short](close)
    EMAshort2 = exponentialaverage[short](EMAshort1)
    DifferenceShort = EMAshort1 - EMAshort2
    ZeroLagShort = EMAshort1 + DifferenceShort
    
    EMAlong1 = exponentialaverage[long](close)
    EMAlong2 = exponentialaverage[long](EMAlong1)
    DifferenceLong = EMAlong1 - EMAlong2
    ZeroLagLong = EMAlong1 + DifferenceLong
    
    ZeroLagMACD = ZeroLagShort - ZeroLagLong
    
    signal1=ExponentialAverage[signal](ZEROLAGMACD)
    signal2=ExponentialAverage[signal](signal1)
    DIFFERENCE2=signal1-signal2
    SignalMACD=signal1+DIFFERENCE2
    
    screener[close crosses over average[20](close) and zerolagMACD>signalMACD and (zerolagMACD>0 and zerolagMACD<0.1)]
    robertogozzi thanked this post
Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.

Moving average cross with MACD


ProScreener: Market Scanners & Detection

New Reply
Author
author-avatar
segie @segie Participant
Summary

This topic contains 3 replies,
has 3 voices, and was last updated by Iván González
8 months ago.

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