problem with MACD cross over and new high break outs

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #135825 quote
    forexbull
    Participant
    Junior

    Hi

    I’ve been trying to write an indicator to highlight breakouts above 20 period highs but only those that have happened within 20 days after the cross of the MACD (highlight the start of a new trend). I can code the individual parameters but can’t work out how to combine them together.

    y=highest[20](high)[1]
    mymacd = macdline[12,26,9]
    crossup = mymacd crosses over 0
    signal=high crosses over y
    return signal, crossup

    I was thinking that a loop looking back over the prior 20 days after each new 20 day high to check for a MACD cross would be a potential solution but I can’t work out how to code it.

    I would be grateful if someone could assist.

    Thanks

    Andrew

    #135852 quote
    robertogozzi
    Moderator
    Master

    Do you want that at least 20 bars have elapsed after the Macd crossover?

    Or, if only say 12 bars have elapsed, then you want to retrieve the highest high of those 12 bars instead of 20?

    #135862 quote
    Vonasi
    Moderator
    Master

    Use SUMMATION.

    y=highest[20](high)[1]
    mymacd = macdline[12,26,9]
    crossup = summation[20](mymacd crosses over 0) <> 0
    signal=high crosses over y
    return signal, crossup
    #135878 quote
    robertogozzi
    Moderator
    Master

    There you go:

    y       = highest[20](high)[1]
    mymacd  = macdline[12,26,9]
    crossup = mymacd crosses over 0
    signal  = high crosses over y
    For i = 0 to BarIndex
       If crossup[i] then
          Break
       Endif
    Endif
    If i > 20 then //clear signals if more than 20 bars
       signal  = 0
       crossup = 0
    Endif
    return signal, crossup

    This should do for 20- bars.

    #135880 quote
    robertogozzi
    Moderator
    Master

    Vonasi’s code is much simpler!

    Vonasi thanked this post
    #135943 quote
    forexbull
    Participant
    Junior

    That’s exactly what I was looking for!

    Thanks for the help.

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

problem with MACD cross over and new high break outs


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
forexbull @forexbull Participant
Summary

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

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 06/13/2020
Status: Active
Attachments: No files
Logo Logo
Loading...