A request that was addressed to ProRealTime:
I am using a Bollinger Band indicator with SMA5 and 1,8 deviation.
I was trying to implement a screener to show occurrencies of closed Bars with Low < Boll- or High > Boll+.
I tried to use the automatic code builder, then adjusted it a bit, but t seems not to work as expected.
How should it be modified to work properly?
Suggestion for an anwser:
p=5 //time period calculation of bollinger
s=1.8 //standard deviation
REM Calculate the moving average of Bollinger and the standard deviation
moyenneBollinger = AVERAGE[p](CLOSE)
REM Define standard deviation (can also be done using the STD fonction)
IF BARINDEX >= p-1 THEN
sumy2 = 0
sumy = 0
FOR i = 0 TO p-1
sumy2 = sumy2 + SQUARE(CLOSE[i])
sumy = sumy + CLOSE[i]
NEXT
ecartType = SQRT(sumy2 / p - SQUARE(sumy / p))
ELSE
ecartType = UNDEFINED
ENDIF
REM Deduce Bollinger
bollSup = moyenneBollinger + s * ecartType
bollInf = moyenneBollinger - s * ecartType
//bollMoy=(bollSup+bollInf)/2
c1 = (bollSup < high[1])
c2 = (bollInf > low[1])
criteria = close
SCREENER[c1 or c2] (criteria AS "Price")