some very simply code below (in theory) and I can’t explain some of the results eg the screen returns MNG (UK) where the close was last below 20ma 4 bars ago but 32 is returned – this is driving me nuts what on earth am I doing wrong?
timeframe(monthly)
ma = average[20](close)
c1 = barssince(close < ma)
SCREENER[c1](c1 as “bars”)
The line
c1 = barssince(close < ma)
assigns C1 the bar where the condition has been met, which will ALWAYS retain a value other than 0, so it will always be true, thus returning ALL instruments.
Try changing the last line so that it only scans the instruments where the condition has only been met within the last 5 (or any other number of your choice) bars:
SCREENER[c1 <= 5](c1 as “bars”)
JSParticipant
Senior
Hi,
I’m getting the right results…
Did you set the “Period” to “Month”… ?
JSParticipant
Senior
It is also possible that your “data” has not yet been adjusted to dividends…
So I was not adjusting for dividend, data now look consistent. Thanks so much.
This leads onto a separate question, should adjustment be enabled or disabled. The chart for the particular asset I was looking is massively different probably becuase it has a hefty 10% yield!
JSParticipant
Senior
When you use a “screener” you always have to adjust the data for dividend because a “screener” works with “real-time” data (data adjusted for dividend)…