12/6/2017 RSI Divergence Trading System: Unbelievable profit potential - Trading Tuitions
Trading Tuitions > Categories > Amibroker > Trading Systems> RSI Divergence Trading System: Unbelievable profit
potential
RSI Divergence
Trading System:
Unbelievable profit
potential
Posted on September 16, 2016 by admin
Divergences are one of the most reliable trading concepts that
provide very good buy/sell opportunities. Though it belongs to
classical technical analysis, yet it is widely used by modern
hedge fund trading systems. In a very layman term,
divergences are said to happen when price and momentum
does not confirm the same direction. For ex:- if price is going
up but momentum is going down or vice versa. There are
various momentum based indicator available through which
you can quantify divergences. In this post, we will go through a
RSI Divergence Trading System. This system has a very high
success rate and the credit for its development goes to Brad
Konia, who has uploaded it in WiseStockTrader. We have
added Buy/Sell signals to this systems and made it back-
testable.
Read our article on AFL tutorial here.
RSI Divergence
RSI Divergence occurs when price and RSI does not move in
same direction. If Price is going up and RSI is going down it’s
called Bearish RSI Divergence, while if price is going down
and RSI is going up it’s called Bullish RSI Divergence. The
below image explains it in a better way:
http://tradingtuitions.com/rsi-divergence-trading-system-unbelievable-profit-potential/ 1/6
12/6/2017 RSI Divergence Trading System: Unbelievable profit potential - Trading Tuitions
Image Source: http://www.guppytraders.com/gup342.shtml
The next section is going to describe Amibroker AFL code for
RSI Divergence Trading system. This system has unbelievable
profit potential. In a sample backtest for 16 years, it shows
100% success rate for NSE Nifty. Even for other scrips it
performs exceptionally well.
AFL Overview
Parameter Value
Preferred Time- Daily
frame
Indicators Used RSI(14)
Buy Condition RSI Bullish Divergence
Short Condition RSI Bearish Divergence
Sell Condition New peak formation in RSI
chart
Cover Condition New Trough formation in RSI
chart
Stop Loss No fixed stoploss
Targets No fixed target
Position Size 150 (fixed)
Initial Equity 200000
Brokerage 100 per order
Margin 10%
http://tradingtuitions.com/rsi-divergence-trading-system-unbelievable-profit-potential/ 2/6
12/6/2017 RSI Divergence Trading System: Unbelievable profit potential - Trading Tuitions
AFL Code
Note: This AFL uses Zig Zag indicator which makes it
prone to look into future. While its good for backtesting
purpose, we do not recommend to use the buy/sell signals
for live trading.
//------------------------------------------------------
//
// Formula Name: RSI Divergance
// Author/Uploader: Brad Konia
// E-mail: support@tradingtuitions.com
// Website: www.tradingtuitions.com
//------------------------------------------------------
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Ope
n %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L
, C ));
Plot(Close,"Price",color=colorBlue,style=styleCandle);
SetTradeDelays( 1, 1, 1, 1 );
SetOption( "InitialEquity", 200000);
SetOption("FuturesMode" ,True);
SetOption("MinShares",1);
SetOption("CommissionMode",2);
SetOption("CommissionAmount",50);
SetOption("AccountMargin",10);
SetOption("RefreshWhenCompleted",True);
SetPositionSize(150,spsShares);
//SetPositionSize(20,spsPercentOfEquity);
SetOption( "AllowPositionShrinking", True );
indName = "RSI"; // Specify the name of the indicator. Thi
s is cosmetic only.
length = Param(indName + " Length", 14, 8, 100, 1); // Ind
icator length
threshold = Param("Zig/Zag Threshold %", 10, 1, 50, 1); //
Minimum % change in indicator value to be considered a zi
g/zag
indVal = RSI(length); // Load the indVal array with the va
lues from the indicator of your choice
indZig = Zig(indVal, threshold); // Set the zig/zag values
for the indicator
indPeakVal1 = Peak(indVal, threshold, 1); // Most recent p
eak value
indPeakBars1 = PeakBars(indVal, threshold, 1); // Bars sin
ce most recent peak
indPeakVal2 = Peak(indVal, threshold, 2); // Second most r
ecent peak value
indPeakBars2 = PeakBars(indVal, threshold, 2); // Bars sin
ce second most recent peak
indTroughVal1 = Trough(indVal, threshold, 1); // Most rece
nt trough value
indTroughBars1 = TroughBars(indVal, threshold, 1); // Bars
since most recent trough
indTroughVal2 = Trough(indVal, threshold, 2); // Second mo
st recent trough value
indTroughBars2 = TroughBars(indVal, threshold, 2); // Bars
since second most recent trough
// Determine if current bar is a peak or trough
peakBar = indPeakBars1 == 0;
troughBar = indTroughBars1 == 0;
http://tradingtuitions.com/rsi-divergence-trading-system-unbelievable-profit-potential/ 3/6
12/6/2017 RSI Divergence Trading System: Unbelievable profit potential - Trading Tuitions
printf("\n peakBar : " + peakBar );
printf("\n troughBar : " + troughBar );
// Bearish divergence
divergeBear = IIf(peakBar AND (indPeakVal1 < indPeakVal2)
AND High > Ref(High, -indPeakBars2), True, False);
Short=divergeBear;
Cover=troughBar;
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
// Bullish divergence
divergeBull = IIf((indTroughBars1 == 0) AND (indTroughVal1
> indTroughVal2) AND Low < Ref(Low, -indTroughBars2), Tru
e, False);
Buy=divergeBull;
Sell=peakBar;
Buy=ExRem(Buy,Sell);
Sell=ExRem(Sell,Buy);
printf("\n divergeBear : " + divergeBear );
printf("\n divergeBull : " + divergeBull );
BuyPrice=Open;
SellPrice=Open;
ShortPrice=Open;
CoverPrice=Open;
printf("\nBuy : " + Buy );
printf("\nSell : " + Sell );
printf("\nShort : " + Short );
printf("\nCover : " + Cover );
/* Plot Buy and Sell Signal Arrows */
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(Cover, shapeSquare, shapeNone),colorGreen,
0, L, Offset=-40);
PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorLime, 0
,L, Offset=-50);
PlotShapes(IIf(Cover, shapeUpArrow, shapeNone),colorWhite,
0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0,
H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange,
0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite
, 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),colorWhit
e, 0,H, Offset=-45);
_SECTION_END();
http://tradingtuitions.com/rsi-divergence-trading-system-unbelievable-profit-potential/ 4/6
12/6/2017 RSI Divergence Trading System: Unbelievable profit potential - Trading Tuitions
RSI Divergence Trading
System: Screenshot
RSI Divergence Trading
System: Backtest Report
Parameter Value
Fixed Position Size
Initial Capital 200000
Final Capital 2425937
Scrip Name NSE Nifty
Backtest Period 08-Mar-2000 to 11-Aug-
2016
Timeframe Daily
Net Profit % 1112.97%
Annual Return % 16.12%
Number of Trades 88
Winning Trade % 100%
Average holding Period 7.09 periods
Max consecutive 0
losses
Max system % -4.83%
drawdown
Max Trade % -37.3%
drawdown
http://tradingtuitions.com/rsi-divergence-trading-system-unbelievable-profit-potential/ 5/6
12/6/2017 RSI Divergence Trading System: Unbelievable profit potential - Trading Tuitions
Th Annual return can increase multi-fold if you
allow compounding. Download the detailed backtest
report here.
Equity Curve
Profit Table
Additional Amibroker settings for
backtesting
Goto Symbol–>Information, and specify the lot size and margin
requirement. The below screenshot shows lot size of 75 and
margin requirement of 10% for NSE Nifty:
http://tradingtuitions.com/rsi-divergence-trading-system-unbelievable-profit-potential/ 6/6