MACD Stochastic code
Forums › ProRealTime English forum › ProScreener support › MACD Stochastic code
- This topic has 12 replies, 3 voices, and was last updated 6 years ago by robertogozzi.
Tagged: Adx, Macd, Stochastic
-
-
07/12/2018 at 10:28 AM #75857
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
07/12/2018 at 12:31 PM #75865Stochastic + Macd CROSSOVER1234567StocK = 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 Up2SCREENER[Result] (Result AS "CrossOver")07/17/2018 at 8:47 AM #76112Good 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
07/17/2018 at 9:44 AM #76115There you go, it will return either 1 for LONG signals or 2 for SHORT signals (not tested, though):
Stochastic CROSSOVER + Macd1234567891011121314StocK = Stochastic[14,3](close)StocD = Average[5](StocK)MacdVal = Macd[12,26,9](close)Up = StocK CROSSES OVER StocDUp = Up AND MacdVal > 0Dn = StocK CROSSES UNDER StocDDn = Dn AND MacdVal < 0Result = 0IF Up THENResult = 1ELSIF Dn THENResult = 2ENDIFSCREENER[Result] (Result AS "Stoch CO")1 user thanked author for this post.
07/17/2018 at 10:28 AM #7612009/12/2018 at 5:54 PM #80306Hi 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
- Stochastic 14,3,5 should cross within MACD on the daily TF first with ADX above 20 and increasing
- 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
09/12/2018 at 11:35 PM #80326I’ll work on it tomorrow.
1 user thanked author for this post.
09/13/2018 at 7:55 AM #8033809/13/2018 at 9:24 AM #80351Up = 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??
09/13/2018 at 11:11 AM #80376Up = 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
1Up = StocK CROSSES OVER StocD AND MacdVal > 0but 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
123x = StocK CROSSES OVER StocDy = MacdVal > 0Up = x AND ybut 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).
1 user thanked author for this post.
09/13/2018 at 11:24 AM #80378Hi 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?09/16/2018 at 11:27 AM #8062009/17/2018 at 3:22 PM #80708Macd, Stochastic and Adx1234567891011121314151617181920212223242526272829TIMEFRAME (Daily)StocK1 = Stochastic[14,3](close)StocD1 = Average[5](StocK1)MacdVal1 = Macd[12,26,9](close)AdxVal = Adx[14]Up1 = StocK1 CROSSES OVER StocD1Up1 = Up1 AND MacdVal1 > 0Up1 = Up1 AND AdxVal > 20Up1 = Up1 AND AdxVal > AdxVal[1]Dn1 = StocK1 CROSSES UNDER StocD1Dn1 = Dn1 AND MacdVal1 < 0Dn1 = Dn1 AND AdxVal > 20Dn1 = Dn1 AND AdxVal > AdxVal[1]TIMEFRAME (4 hours)StocK2 = Stochastic[14,3](close)StocD2 = Average[5](StocK2)Up2 = StocK2 CROSSES OVER StocD2Dn2 = StocK2 CROSSES UNDER StocD2TIMEFRAME (default)result = 0IF Up1 AND Up2 THENResult = 1ELSIF Dn1 AND Dn2 THENResult = 2ENDIFSCREENER[Result] (Result AS "1=Up/2=Dn")There you go, give me some feedback after testing it:
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on