Advance – Decline Indicator Strategy (Amibroker Code)

The original article can be found here.

Code in plain English:

  • If the 2-day RSI of the advance-decline indicator goes below 15, then buy SPY at the close.
  • When the 2-day RSI of the advance-decline indicator goes above 85, then sell SPY at the close.

Amibroker code:

FremmedADV=Foreign("NY-adv-issues","close",fixup=1);
FremmedDECL=Foreign("NY-decl-issues","close",fixup=1);

Difference = ( FremmedADV - FremmedDECL ) ;
DiffSqrt = IIF( Difference > 0, sqrt( Difference ), - sqrt( - Difference ) );
AD = Cum( DiffSqrt );
RSIAD=RSIa(AD,2);

Buy= RSIAD<15 ;
buyPrice=Close;
Sell= rsiAD>85;
sellPrice=Close ;