Hello I just need help with the macd screener with a variable look back.
I tried using the automated service but I can’t get it to work
all I wanted to know is when the Macd signal line and MacD Liner have crossed or are equal and if that is up or if that is down,
and then be able to adjust how many bars it looks back so on a 4hour chart I want it to look back 20, so that’s 20 4hour bars, if someone here could be really helpful and get this sorted for me I would be so grateful thank you very much
This is the code you need. It will fetch through the last lookback periods to know if the MACD signal line has crosses over or under the zero line. It will always give you the last signal (bearish=1 or bullish=-1 one), because of course many crosses may have occurred in the lookback period!
signal=MACDline[12,26,9](close)
lookback=10
for i = 0 to lookback do
if signal[i] crosses over 0 then
condition=1
direction=1
break
endif
if signal[i] crosses under 0 then
condition=1
direction=-1
break
endif
next
screener[condition](direction as "bull or bear")
thank you Nicolas BUT it need to be the macd line NOT zero line, I am going to try and fix it my self but just in cases could you as well please
hello iv just gave it a try and i found the same issues if that the look back period never seems to work it set to 2 or 3 and it still counting all the crosses it does not seam to do it job, any thoughts on that
I found the mistake sorry, I didn’t reset the condition variable at each iteration.
I changed the crosses detection to the MACD line with its signal line instead of the zero one.
Mline=MACDline[12,26,9](close)
Msignal=exponentialaverage[9](Mline)
lookback=3
condition=0
for i = 0 to lookback do
if MLine[i] crosses over Msignal[i] then
condition=1
direction=1
break
endif
if Mline[i] crosses under Msignal[i] then
condition=1
direction=-1
break
endif
next
screener[condition](direction as "bull or bear")
Thank you ever so much for what you just did, really appreciate it I struggle a lot with the code on PReal it even though it’s very simple I just do not have the hindsight I haven’t got it, so thank you very much
kind regards
Patrick k Templar