MACD Stochastic code

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #75857 quote
    MrMagic
    Participant
    Average

    Good morning all,

    Can anyone help with a screener for a MACD Stochastic code to screen for Stochastic crossover (default settings 14,3,5)  followed by MACD (default settings) crossover in the same direction within two candlesticks of each other?

    Thank you.

    KR,

    MM

    #75865 quote
    robertogozzi
    Moderator
    Master
    StocK      = Stochastic[14,3](close)
    StocD      = Average[5](StocK)
    MacdVal    = Macd[12,26,9](close)
    Up1        = summation[3](StocK CROSSES OVER StocD)
    Up2        = summation[3](MacdVal CROSSES OVER 0)
    Result     = Up1 AND Up2
    SCREENER[Result] (Result AS "CrossOver")
    MrMagic and Nicolas thanked this post
    #76112 quote
    MrMagic
    Participant
    Average

    Good morning robertogozzi,

    Thanks for the above. Can you help with a code for a buy signal when MACD is already above the zero line and stochastic (settings 14,3,5) %K crosses over %D and a sell signal when MACD is already below the zero line and stochastic (settings 14,3,5) %K  crosses under %D?

    Cheers.

    KR.

    MM

    #76115 quote
    robertogozzi
    Moderator
    Master

    There you go, it will return either 1 for LONG signals or 2 for SHORT signals (not tested, though):

    StocK      = Stochastic[14,3](close)
    StocD      = Average[5](StocK)
    MacdVal    = Macd[12,26,9](close)
    Up         = StocK CROSSES OVER StocD
    Up         = Up AND MacdVal > 0
    Dn         = StocK CROSSES UNDER StocD
    Dn         = Dn AND MacdVal < 0
    Result     = 0
    IF Up THEN
       Result = 1
    ELSIF Dn THEN
       Result = 2
    ENDIF
    SCREENER[Result] (Result AS "Stoch CO")
    MrMagic thanked this post
    #76120 quote
    MrMagic
    Participant
    Average

    Hi,

    I’ve tested it and it’s working well. Cheers.

    robertogozzi thanked this post
    #80306 quote
    MrMagic
    Participant
    Average

    Hi all,

    I wonder if you could help me with a procode. Let me see if I make sense.

    I’m trying to write a screener code for two timeframes, let’s say. Daily and 4Hours

    Below are my criteria

    1. Stochastic 14,3,5 should cross within MACD on the daily TF first with ADX above 20 and increasing
    2. Then on the 4 hour TF, stochastic to cross and be in the same direction as Daily, or alert if it’s already in the same direction as Daily.

    So even if the stoch has crossed on the daily, there shouldn’t be an alert until H4 stoch crosses in the same direction.

    I hope I made sense: it’s been a long day.

    Thanks.

    KR,

    MM

    #80326 quote
    robertogozzi
    Moderator
    Master

    I’ll work on it tomorrow.

    MrMagic thanked this post
    #80338 quote
    MrMagic
    Participant
    Average

    Thanks. Bless.

    #80351 quote
    GraHal
    Participant
    Master

    Up         = StocK CROSSES OVER StocD

    Up         = Up AND MacdVal > 0

    I have to ask as I get confused when I see code like above 🙂

    How can Up = x AND ALSO  … Up = x +y ??

    Is it because Up = x + y is the last line of code stating what Up =  … so that is what PRT works on??

    Hope that makes sense??

    #80376 quote
    robertogozzi
    Moderator
    Master

    Up = StocK CROSSES OVER StocD
    Up = Up AND MacdVal > 0
    I have to ask as I get confused when I see code like above 🙂
    How can Up = x AND ALSO  … Up = x +y ??
    Is it because Up = x + y is the last line of code stating what Up =  … so that is what PRT works on??
    Hope that makes sense??

    I could have written

    Up = StocK CROSSES OVER StocD AND MacdVal > 0

    but for clarity i split the line in two to make it easier to read and debug.

    Actually two simple conditions is not much trouble, but with more conditions this way is much more readable and easier to debug (for me), despite it may waste some newlines, but adding some text won’t affect performance.

    It’s because AND requires that ALL conditions be TRUE, no matter if you split it in more lines. Some compilers may skip the second line if the first one is false.

    I could also have written

    x  = StocK CROSSES OVER StocD
    y  = MacdVal > 0
    Up = x AND y

    but this is off topic now, should you have other similar questions you would like to be answered I suggest that you open a new topic in the General Trading forum (this is coding automatic trading).

    GraHal thanked this post
    #80378 quote
    robertogozzi
    Moderator
    Master

    Hi all,
    I wonder if you could help me with a procode. Let me see if I make sense.
    I’m trying to write a screener code for two timeframes, let’s say. Daily and 4Hours
    Below are my criteria
    1.  Stochastic 14,3,5 should cross within MACD on the daily TF first with ADX above 20 and increasing
    what does WITHIN mean? should they both cross at the same time?

    #80620 quote
    MrMagic
    Participant
    Average

    Hi,

    Means that a bearish stochastic crossover happens after a bearish MACD has formed and vice versa. Hope that makes sense.

    Thanks.

    MM

    #80708 quote
    robertogozzi
    Moderator
    Master
    TIMEFRAME (Daily)
    StocK1     = Stochastic[14,3](close)
    StocD1     = Average[5](StocK1)
    MacdVal1   = Macd[12,26,9](close)
    AdxVal     = Adx[14]
    Up1        = StocK1 CROSSES OVER StocD1
    Up1        = Up1 AND MacdVal1 > 0
    Up1        = Up1 AND AdxVal > 20
    Up1        = Up1 AND AdxVal > AdxVal[1]
    Dn1        = StocK1 CROSSES UNDER StocD1
    Dn1        = Dn1 AND MacdVal1 < 0
    Dn1        = Dn1 AND AdxVal > 20
    Dn1        = Dn1 AND AdxVal > AdxVal[1]
    
    TIMEFRAME (4 hours)
    StocK2     = Stochastic[14,3](close)
    StocD2     = Average[5](StocK2)
    Up2        = StocK2 CROSSES OVER StocD2
    Dn2        = StocK2 CROSSES UNDER StocD2
    
    TIMEFRAME (default)
    
    result = 0
    IF Up1 AND Up2 THEN
       Result = 1
    ELSIF Dn1 AND Dn2 THEN
       Result = 2
    ENDIF
    SCREENER[Result] (Result AS "1=Up/2=Dn")

    There you go, give me some feedback after testing it:

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

MACD Stochastic code


ProScreener: Market Scanners & Detection

New Reply
Author
author-avatar
MrMagic @mrmagic Participant
Summary

This topic contains 12 replies,
has 3 voices, and was last updated by robertogozzi
7 years, 4 months ago.

Topic Details
Forum: ProScreener: Market Scanners & Detection
Language: English
Started: 07/12/2018
Status: Active
Attachments: 2 files
Logo Logo
Loading...