AFL for RSI Crossover System:
The Trading Idea is to Buy when short-term momentum crosses above long-term momentum and vice versa.
RSI is a oscillator which depicts momentum in prices. We try using two RSI of different periods to judge the short-term momentum and long-term momentum. So trade entries will be based on RSI indicator.
However, by construction, RSI gives a lot of whipsaws while it oscillates up and down. So trade exits are done using RSI levels to avoid too frequent re-entries.
Buy: When short-term RSI crosses above long-term RSI
Sell: When RSI goes below 40 level
Script:
_SECTION_BEGIN( "RSI Crossover System" );
SetChartOptions( 0, chartShowArrows | chartShowDates );
Plot( C, "Close", ParamColor( "Color", colorBlack ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );
SetBarsRequired( 100000, 0 );
SetPositionSize(1, spsShares);
per1= Param("RSI Fast", 18, 5, 100, 1);
per2= Param("RSI Slow", 52, 15, 100, 1);
RSI1= RSI(per1);
RSI2= RSI(per2);
Buy=Sell=Short=Cover=Null;
flag=0; sflag=0;
for(i=0; i<BarCount; i++) { if(RSI2[i]>RSI1[i] AND RSI2[i-1]<RSI1[i-1] AND flag==0 AND sflag==0) { Buy[i]=1; flag=1; } if(40>RSI1[i] AND 40<RSI1[i-1] AND flag)
{ Sell[i]=1; flag=0; }
if(RSI2[i]<RSI1[i] AND RSI2[i-1]>RSI1[i-1] AND flag==0 AND sflag==0)
{ Short[i]=1; sflag=1; }
if(60<RSI1[i] AND 60>RSI1[i-1] AND sflag)
{ Cover[i]=1; sflag=0; }
}
Title = NumToStr( DateTime(), formatDateTime ) + " O " + O + " H " + H + " L " + L + " C " + C ;
PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorGreen, 0, L, Offset = -40 );
PlotShapes( IIf( Buy, shapeSquare, shapeNone ), colorLime, 0, L, Offset = -50 );
PlotShapes( IIf( Buy, shapeUpArrow, shapeNone ), colorWhite, 0, L, Offset = -45 );
PlotShapes( IIf( Sell, shapeDownArrow, shapeNone ), colorRed, 0, H, Offset = -45 );
PlotShapes( IIf( Short, shapeSquare, shapeNone ), colorRed, 0, H, Offset = 40 );
PlotShapes( IIf( Short, shapeSquare, shapeNone ), colorOrange, 0, H, Offset = 50 );
PlotShapes( IIf( Short, shapeDownArrow, shapeNone ), colorWhite, 0, H, Offset = -45 );
PlotShapes( IIf( Cover, shapeUpArrow, shapeNone ), colorBlue, 0, L, Offset = -45 );
_SECTION_END();