Hi,
I’m looking for a way to detect stocks for which the price crossed over the SMA50 in the last 10 days.
thanks
Hello Here you have:
sma = average[50](close)
n = barssince(close crosses over sma)
screener[n<10]
If you also want the price to be above the average, you just have to change the last line with this one: screener[n<10 and close > sma]
There you go:
Sma50 = average[50,0](close)
c1 = summation[10](close CROSSES OVER Sma50)
c2 = close > Sma50
c3 = high <> low
Cond = c1 AND c2 AND c3
SCREENER[Cond]
Two is better than one! 🙂
great, thanks.
I had never heard about this barssince function.
and what if I also want to make sure the price did not go below SMA50 after it crossed over the SMA ?
Hello again, following the same logic as before you can program the following:
sma = average[50](close)
n = barssince(close crosses over sma)
m = barssince(close crosses under sma)
screener[n<10 and m>=10]
it is starting to drive me crazy 🙂
SMA200 = average[200](close)
n200 = barssince(close crosses over SMA200)
priceCrossedSMA200 = n200 < 3
priceAboveSMA200 = low > SMA200
CondSMA200 = (priceCrossedSMA200 and priceAboveSMA200)
SCREENER[CondSMA200] (volume)
here is the script I wrote based on your ideas. It includes stocks where the price did not cross the SMA200 in the last 3 days. I dont get why. Any idea ?
It works, but to avoid those stocks that have never crossed the sma200 we can add this n200>=0:
SMA200 = average[200](close)
n200 = barssince(close crosses over SMA200)
priceCrossedSMA200 = n200 < 3 and n200 >= 0
priceAboveSMA200 = low > SMA200
CondSMA200 = (priceCrossedSMA200 and priceAboveSMA200)
screener[CondSMA200]
thanks Ivan, appreciate it
How would you deal with this screenshot ? where the price came close from above to the SMA200, but did not cross it. Then price went back up. I’d like to include those patterns in the detection
Hello
I would create a line parallel to the sma200 at X distance. From there I would proceed the same as in previous screener but now the reference average would be the parallel to the sma.
To ensure that the price comes from crossing down the sma200 offset without having crossed down the sma200 then we can control the barindex of each situation.
sma = average[50](close)
smadist = sma + 2/100*sma
n = barssince(close crosses over smadist)
if close crosses under sma then
$crossSMA[0]=barindex
endif
if close crosses under smadist then
$crossSMAdist[0]=barindex
endif
setup = n>=0 and n<5 and $crossSMA[0]<$crossSMAdist[0] and close > smadist
screener[setup]
Did you investigate how to rank these stocks by the number of days they have spent over their SMA200 or something else?