Francesco Bufi’s adaptive thresholds technique

The AIQ code is provided here for Francesco Bufi’s adaptive thresholds technique and his four test systems, as described in his article in the October 2024 Stocks and Commodities issue (“Overbought/Oversold Oscillators: Useless Or Just Misused?”).

Did people like J. Welles Wilder and John Murphy (pioneers in technical analysis and the authors of several notable books in the field) work with no purpose other than to cheat us? Or have their techniques perhaps stopped working? Are some of these techniques indeed useless, as some would claim? Here’s a test to find out.

Francesco Bufi presents a strategy based on the relative strength index (RSI) that continuously adjusts the buying level.

Since the author optimized the test systems for intraday trading and the AIQ code provided here is based on daily bar trading, the parameters may need to be adjusted to get a realistic test.

!Overbought/Oversold Oscillators: Useless Or Just Misused?
!Author: Francesco P. Bufi, TASC October 2024
!Coded in AIQ by: Richard Denning, 8/17/2024

!INPUTS:
C is [close].
C1 is valresult(C,1).
H is [high].
L is [low].
TrendLen is 200.
RSILen is 2.
BuyLevel is 14.
UpBuyLevel is 12.
DnBuyLevel is 4.
AdaptLen is 8.
KAdaptive is 6.
ExitBars is 3.

!BAT:
StdDev is sqrt(variance(C,AdaptLen)).
value1 is StdDev.
value2 is slope2(C,AdaptLen).
value3 is value2/value1.
value3a is iff(value3>0.5,0.5,iff(value3<-0.5,-0.5,value3)).
BAT is value3a.

!TREND:
SMA is simpleavg(C,TrendLen).
Trend is iff(C > SMA,1,-1).

!! RSI WILDER
!To convert Wilder Averaging to Exponential Averaging use this formula:
!ExponentialPeriods = 2 * WilderPeriod - 1.
U is C - C1.
D is C1 - C.
W1 is RSILen.
rsiLen1 is 2 * W1 - 1.
AvgU is ExpAvg(iff(U>0,U,0),rsiLen1).
AvgD is ExpAvg(iff(D>=0,D,0),rsiLen1).
rsi is 100-(100/(1+(AvgU/AvgD))).

!SYSTEMS FOR TESTING:
! Sys1:
Buy1 if rsi<BuyLevel.

!Sys2:
Buy2 if rsi<BuyLevel and Trend=1.

!Sys3:
Buy3 if (Trend=1 and rsi<UpBuyLevel) or (Trend=-1 and rsi<DnBuyLevel).

!Sys4:
BL is BuyLevel*KAdaptive*BAT.
Buy4 if rsi<BuyLevel*KAdaptive*BAT. 

Sell if {position days} >= ExitBars.

ShowValues if 1.

—Richard Denning
rdencpa@gmail.com
for AIQ Systems