Algo Trading 102: Triple RSI

Algo Trading 102

Algorithmic Trading 102: The Triple RSI

In our next installment of our Automated Trading Series, we'll be leveraging the Multicharts platform and the Relative Strength Indicator across multiple lengths in order to identify trading opportunities. Although this is a relatively simple trading strategy, it can be the basis for a more elaborate trading solution when paired with other indicators and proper risk and money management.

Note that I will include the INDICATOR code (in blue text) and the STRATEGY CODE (in green text) below.

The following will display the code for the Triple RSI Indicator.
You should see a single indicator underneath your chart once you create it with this code:

{
Indicator: _TM_TripleRSI v1.00
Strategy Details: Shows multiple RSIs in a single chart.

VERSION:
1.00: Using 3 RSI Indicators
}

//-----------------------------------------#
// Inputs
//
inputs:
LengthRSI1( 5 ),
LengthRSI2( 14 ),
LengthRSI3( 21 ),
Price(Close),
OverSold(30.00),
OverBought(70.00),
OverSColor( Cyan ),
OverBColor( Red );

vars:
rsiLow(0), rsiHigh(0),
OBStrength(0), OSStrength(0),
iCount(0);

vars:
rsi1(0), rsi2(0), rsi3(0),
rsiOB1(0), rsiOB2(0), rsiOB3(0),
rsiOS1(0), rsiOS2(0), rsiOS3(0);

//-----------------------------------------#
// Initialize
//

//-----------------------------------------#
// Calculate Aggregation Strength
//
rsi1 = RSI(Price, LengthRSI1);
rsi2 = RSI(Price, LengthRSI2);
rsi3 = RSI(Price, LengthRSI3);

//-----------------------------------------#
// Crossing Points
//

// OverBought
if rsi1 crosses below OverBought then rsiOB1 = 1 else rsiOB1 = 0;
if rsi2 crosses below OverBought then rsiOB2 = 1 else rsiOB2 = 0;
if rsi3 crosses below OverBought then rsiOB3 = 1 else rsiOB3 = 0;

// OverSold
if rsi1 crosses above OverSold then rsiOS1 = 1 else rsiOS1 = 0;
if rsi2 crosses above OverSold then rsiOS2 = 1 else rsiOS2 = 0;
if rsi3 crosses above OverSold then rsiOS3 = 1 else rsiOS3 = 0;

//-----------------------------------------#
// Calculate Strength
//
OBStrength = rsiOB1 + rsiOB2 + rsiOB3;
OSStrength = rsiOS1 + rsiOS2 + rsiOS3;

// if OBStrength > 0 or OSStrength > 0 then print("#", Symbol_CurrentBar, ":: ", "OBStrength:", OBStrength, ", OSStrength:", OSStrength);

//-----------------------------------------#
// Chart Plots
//
Plot1( rsi1, "RSI1");
Plot2( rsi2, "RSI2");
Plot3( rsi3, "RSI3");

if rsi1 > OverBought then SetPlotColor( 1, Red) else if rsi1 < OverSold then SetPlotColor( 1, Cyan ); if rsi2 > OverBought then SetPlotColor( 2, Red) else if rsi2 < OverSold then SetPlotColor( 2, Cyan ); if rsi3 > OverBought then SetPlotColor( 3, Red) else if rsi3 < OverSold then SetPlotColor( 3, Cyan );

Plot20( OverBought, "OverBot" ) ;
Plot21( OverSold, "OverSld" ) ;

 

The following will display the code for the Triple RSI Strategy.
Note, I have commented out various portions that you can turn ON or OFF as needed.

 

{
Strategy: _TM_TripleRSI v1.00
Strategy Details: Shows multiple RSIs in a single chart.

VERSION:
1.00: Using 3 RSI Indicators
}

//-----------------------------------------#
// Inputs
//
inputs:
LengthRSI1( 5 ),
LengthRSI2( 14 ),
LengthRSI3( 21 ),
Price(Close),
OverSold(30.00),
OverBought(70.00),
OverSColor( Cyan ),
OverBColor( Red );

vars:
rsiLow(0), rsiHigh(0),
OBStrength(0), OSStrength(0),
iCount(0);

vars:
rsi1(0), rsi2(0), rsi3(0),
rsiOB1(0), rsiOB2(0), rsiOB3(0),
rsiOS1(0), rsiOS2(0), rsiOS3(0);

//-----------------------------------------#
// Initialize
//

//-----------------------------------------#
// Calculate Aggregation Strength
//
rsi1 = RSI(Price, LengthRSI1);
rsi2 = RSI(Price, LengthRSI2);
rsi3 = RSI(Price, LengthRSI3);

//-----------------------------------------#
// Crossing Points
//

// OverBought
if rsi1 crosses below OverBought then rsiOB1 = 1 else rsiOB1 = 0;
if rsi2 crosses below OverBought then rsiOB2 = 1 else rsiOB2 = 0;
if rsi3 crosses below OverBought then rsiOB3 = 1 else rsiOB3 = 0;

// OverSold
if rsi1 crosses above OverSold then rsiOS1 = 1 else rsiOS1 = 0;
if rsi2 crosses above OverSold then rsiOS2 = 1 else rsiOS2 = 0;
if rsi3 crosses above OverSold then rsiOS3 = 1 else rsiOS3 = 0;

//-----------------------------------------#
// Calculate Strength
//
OBStrength = rsiOB1 + rsiOB2 + rsiOB3;
OSStrength = rsiOS1 + rsiOS2 + rsiOS3;

// --------------------------------------------------------------------------------#
// UNCOMMENT CODE GROUPINGS BELOW AS YOU SEE FIT
// --------------------------------------------------------------------------------#

//-----------------------------------------#
// Enter Trade (RSI 1 only)
//
if rsiOB1 = 1 then sellshort this bar at close;
if rsiOS1 = 1 then Buy this bar at close;

//-- Revision 1 (RSI 1 [fastest] crosses in opposite direction)
if marketposition <> 0 and rsi1 crosses above OverBought then buytocover this bar at close;
if marketposition <> 0 and rsi1 crosses below OverSold then Sell this bar at close;

//-----------------------------------------#
// Enter Trade (RSI 1 and 2)
//
//if rsiOB1 = 1 and rsiOB2 = 1 then sellshort this bar at close;
//if rsiOS1 = 1 and rsiOS2 = 1 then Buy this bar at close;

//-- Revision 1 (RSI 1 [fastest] crosses in opposite direction)
//if marketposition <> 0 and rsi1 crosses above OverBought then buytocover this bar at close;
//if marketposition <> 0 and rsi1 crosses below OverSold then Sell this bar at close;

//-----------------------------------------#
// Enter Trade (RSI 1, 2 and 3)
//
//if rsiOB1 = 1 and rsiOB2 = 1 and rsiOB3 = 1 then sellshort this bar at close;
//if rsiOS1 = 1 and rsiOS2 = 1 and rsiOS3 = 1 then Buy this bar at close;

//-- Revision 1 (RSI 1 [fastest] crosses in opposite direction)
//if marketposition <> 0 and rsi1 crosses above OverBought then buytocover this bar at close;
//if marketposition <> 0 and rsi1 crosses below OverSold then Sell this bar at close;

 

Should you have any questions regarding the code or how you install it in MultiCharts or EasyLanguage, reach out to me via email: gregory@tradersmeetup.net

Note: For educational use only.  Do not use for live trading. Our Disclaimer applies. 

Enjoy!