# Stochastic RSI AFL

Hi,

Can anybody share Stochastic RSI AFL? It’s not available by default in Amibroker indicator list. I follow manually from investing.com but I need the same in Amibroker. Pls help.

Regards,

1 Like

I think this is what you want.

``````//==================================
//==================================
// 	From John Ehler's book     ===
// 	Rocket Science for Traders ===
//                     	     		===
// 	AFL By Robert Dunbar  	   ===
//==================================
//==================================

Arrows = ParamToggle( "Buy/Sell Arrows", "No|Yes", 0 );
RSI_Length = Param( "RSI Length", 10, 1, 40, 1, 1 );
Stoc_Length = Param( "Stocastic Length", 10, 1, 40, 1, 1 );
WMA_Length = Param( "WMA Length", 10, 1, 40, 1, 1 );
BullSig = BearSig = Trigger = 0;

Value1 = RSIa( C, RSI_Length ) - LLV( RSIa( C, RSI_Length ), Stoc_Length );
Value2 = HHV( RSIa( C, RSI_Length ), Stoc_Length ) - LLV( RSIa( C, RSI_Length ), Stoc_Length );
Value3 = Nz( Value1 / Value2 );
Value4 = 2 * ( WMA( Value3, WMA_Length ) - 0.5 );
Trigger = Ref( Value4, -1 );

BullSig = IIf( Cross( Value4, Trigger ), True, False );
BearSig = IIf( Cross( Trigger, Value4 ), True, False );

Plot( Value4, "StocRSI", colorLightBlue );
Plot( Trigger, "Trigger", colorRed );
Plot( 0 , "", colorWhite, styleDashed );

if ( Arrows )
{
PlotShapes( shapeUpArrow*BullSig, colorBrightGreen );
PlotShapes( shapeDownArrow*BearSig, colorRed );
}
``````
2 Likes

Hi,
Thanks for ur code. But StochRSI value runs between 0 and 100. Pls see an example in the attached picture. I am looking for this code.

2 Likes

Technically that is not entirely accurate. Chande and Kroll I think first published this indicator in an article published in May 1993, Technical Analysis of Stocks & Commodities magazine (but it was popularized in their 1994 book The New Technical Trader). At that time they had the initial calculation as a Stochastic of the RSI and that would vary from 0 to 1. But here is their exact text from that article,

So the web site you are looking at seems to have taken that approach and then they appear to be making the two common "slow Stochastic" smoothings, %K and %D. So you can multiply the code you were given above by 100 or code your own using whichever moving average and %K %D smoothing periods you like.

1 Like

@pradipkumarmajumder here is one untested attempt at what you may want. Please check and double check as I have not.

``````// Attempt at StochasticRSI v1.1
// will use the "Slow Stochastic" calculations, i.e. smoothing
// both the original and then the smoothed Stochastic yet again

RSIperiods = Param( "RSIperiods", 14, 1, 100, 1 );
Stochperiods = Param( "Stochperiods", 14, 1, 100, 1 );

Kperiods = Param( "Kperiods", 3, 1, 50, 1 );
Dperiods = Param( "Dperiods", 3, 1, 50, 1 );
OBthreshold = Param( "OBthreshold", 80, 55, 100, 5 );
OSthreshold = Param( "OSthreshold", 20, 0, 50, 5 );

TheRSI = RSI( RSIperiods );
llRSI = LLV( TheRSI, Stochperiods );
hhRSI = HHV( TheRSI, Stochperiods );

StochasticRSI = 100 * ( ( TheRSI - llRSI ) / ( hhRSI - llRSI + 0.00001 ) );

StocK_rsi = MA( StochasticRSI, Kperiods );
StocD_rsi = MA( StocK_rsi, Dperiods );

Plot( StocK_rsi, "StochK(" + Kperiods + ") of RSI(" + RSIperiods + ")", colorRed, styleLine | styleThick );
Plot( StocD_rsi, "StochD(" + Dperiods + ") of RSI(" + RSIperiods + ")", colorBlue, styleDashed | styleThick );
PlotGrid( OBthreshold, colorRed, 1 );
PlotGrid( OSthreshold, colorGreen, 1 );

``````

6 Likes