The AIQ code based on Sylvain Vervoort’s article in the September issue of Stocks & Commodities, “Oscillators, Smoothed,” is provided at www.TradersEdgeSystems.com/traderstips.htm and is also shown below.
In the chart of Sanderson Farms (SANF) with a color bar study that shows potential buys (green bars) when both oscillators are moving up and they are both oversold (below 20). It sells (red bars) when both oscillators are moving down and they are both overbought (above 80). The bands shown are based on the modified Bollinger Bands that are used in the calculation of the modified Percent b oscillator. For comparison purposes, I have also provided the formula for John Bollinger’s original Percent b indicator as well as for the original smoothed %K indicator.
!Author: Sylvain Vervoort, TASC Sept 2013
!Coded by: Richard Denning 7/6/13
C is [close].
H is [high].
L is [low].
smaLen is 2.
smoLen is 3.
sdLen is 18.
kLen is 3.
!CODE FOR MODIFIED PERCENT B INDICATOR:
SMA1 is simpleavg(C,smaLen).
SMA2 is simpleavg(SMA1,smaLen).
SMA3 is simpleavg(SMA2,smaLen).
SMA4 is simpleavg(SMA3,smaLen).
SMA5 is simpleavg(SMA4,smaLen).
SMA6 is simpleavg(SMA5,smaLen).
SMA7 is simpleavg(SMA6,smaLen).
SMA8 is simpleavg(SMA7,smaLen).
SMA9 is simpleavg(SMA8,smaLen).
SMA10 is simpleavg(SMA9,smaLen).
rainbow is (5*SMA1 + 4*SMA2 + 3*SMA3 + 2*SMA4
+ SMA5 + SMA6 + SMA7 + SMA8 + SMA9
+SMA10) / 20.
EMA1 is expavg(rainbow,smoLen).
EMA2 is expavg(EMA1,smoLen).
diff is EMA1 – EMA2.
ZLRB is EMA1 + diff.
EMAZ1 is expavg(ZLRB,smoLen).
EMAZ2 is expavg(EMAZ1,smoLen).
EMAZ3 is expavg(EMAZ2,smoLen).
TEMAZ is 3*EMAZ1 – 3*EMAZ2 + EMAZ3.
SDTEMAZ is sqrt(variance(TEMAZ,sdLen)).
TEMAZ18 is valresult(TEMAZ,18).
TEMAZ17 is valresult(TEMAZ,17).
TEMAZ16 is valresult(TEMAZ,16).
TEMAZ15 is valresult(TEMAZ,15).
TEMAZ14 is valresult(TEMAZ,14).
TEMAZ13 is valresult(TEMAZ,13).
TEMAZ12 is valresult(TEMAZ,12).
TEMAZ11 is valresult(TEMAZ,11).
TEMAZ10 is valresult(TEMAZ,10).
TEMAZ9 is valresult(TEMAZ,9).
TEMAZ8 is valresult(TEMAZ,8).
TEMAZ7 is valresult(TEMAZ,7).
TEMAZ6 is valresult(TEMAZ,6).
TEMAZ5 is valresult(TEMAZ,5).
TEMAZ4 is valresult(TEMAZ,4).
TEMAZ3 is valresult(TEMAZ,3).
TEMAZ2 is valresult(TEMAZ,2).
TEMAZ1 is valresult(TEMAZ,1).
WMA18TEMAZ is (18*TEMAZ + 17*TEMAZ1 + 16*TEMAZ2
+ 15*TEMAZ3 + 14*TEMAZ4 + 13*TEMAZ5
+ 12*TEMAZ6 + 11*TEMAZ7 + 10*TEMAZ8
+ 9*TEMAZ9 + 8*TEMAZ10 + 7*TEMAZ11
+ 6*TEMAZ12 + 5*TEMAZ13 + 4*TEMAZ14
+ 3*TEMAZ15 + 2*TEMAZ16 + 1*TEMAZ17 ) /
!Plot the following as single line indicator with 50 line:
PBmod is (TEMAZ + 2*SDTEMAZ – WMA18TEMAZ) / (4*SDTEMAZ)*100.
!CODE FOR MODIFIED BOLLIGER BANDS:
BBupMod is TEMAZ + 2*SDTEMAZ. !Plot on chart area
BBdnMod is TEMAZ – 2*SDTEMAZ. !Plot on chart area
!CODE FOR STANDARD PERCENT B:
sdC is sqrt(variance(C,sdLen)).
!For comparison the following is the percent B:
pctB is (C+2*sdC-simpleavg(C,sdLen))/(4*sdC)*100.
!CODE FOR MODIFIED SLOW STOCHASTIC:
typ is (H+L+C)/3.
RBC is (rainbow + typ) / 2.
nom is RBC – lowresult(RBC,kLen).
den is highresult(RBC,kLen) – lowresult(RBC,kLen).
fastKmod is min(100,max(0,100*nom / den)).
Kmod is simpleavg(fastKmod,smoLen).
!CODE FOR STANDARD SLOW STOCHASTIC:
n is (C – lowresult(L,kLen)).
d is (highresult(H,kLen)-lowresult(L,kLen)).
fastK is min(100,max(0,100*n / d)).
slowK is simpleavg(fastK,smoLen).
!COLOR STUDY FOR MODIFIED OSCILLATORS
Green if PBmod > valresult(PBmod,1)
and Kmod > valresult(Kmod,1)
and PBmod < 20 and Kmod < 20.
Red if PBmod < valresult(PBmod,1)
and Kmod < valresult(Kmod,1)
and PBmod > 80 and Kmod > 80.
for AIQ Systems