By the help of forum members, the following indicator, moving average deviation rate has been used for proscreening in long and short during the moving average line cross the two standard deviation lines. However, the results are not equal to the chart I find.
//Moving average deviation rate
//input
maPeriod = 21
//deviation rate
sma = average[maPeriod](close)
rate = close / sma * 100 - 100
//deviation rate std
stdCenter = average[maPeriod * 2](rate)
istd = std[maPeriod * 2](rate)
plusDev = stdCenter + istd * 2
minusDev = stdCenter - istd * 2
return rate coloured(255,0,0), stdcenter coloured(0,255,0), plusdev coloured(0,255,0), minusdev coloured(0,255,0)
May I seek your advice on setup the proscreening code?
The below code for the screener is working correctly, I embed the whole indicator code into the stock screener:
//Moving average deviation rate
//input
maPeriod = 21
//deviation rate
sma = average[maPeriod](close)
rate = close / sma * 100 - 100
//deviation rate std
stdCenter = average[maPeriod * 2](rate)
istd = std[maPeriod * 2](rate)
plusDev = stdCenter + istd * 2
minusDev = stdCenter - istd * 2
test = rate crosses over plusdev or rate crosses under minusdev
screener[test]