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
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")
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
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")
Hi,
I’ve tested it and it’s working well. Cheers.
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
- 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
I’ll work on it tomorrow.
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??
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).
Hi,
Means that a bearish stochastic crossover happens after a bearish MACD has formed and vice versa. Hope that makes sense.
Thanks.
MM
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: