### Stock Portfolio Organizer

The ultimate porfolio management solution.

### WiseTrader Toolbox

**#1** Selling **Amibroker** Plugin featuring:

### RRG 2.1 for Amibroker (AFL)

Relative Rotation Graphs are plotted on a standard scatter-plot canvas with an x-axis (horizontal) and a y-axis (vertical). The JdK RS-Ratio indicator is the input for the horizontal axis, and the JdK RS-Momentum indicator is the input on the vertical axis. These axes cross at 100 to create four relative performance quadrants. The Relative Rotation Graph simply plots RS-Ratio and RS-Momentum values for each symbol. If the symbol universe is the nine sector SPDRs and the S&P 500 is the benchmark, we will see nine points on the Relative Rotation Graph (RRG) and each point represents that particular sector’s RS-Ratio and RS-Momentum value.

The Relative Rotation Graph is shown above with four possible combinations. Let’s assume we are using the nine sector SPDRs as our universe and the S&P 500 as the benchmark.

A sector is in the leading quadrant (green) when RS-Ratio and RS-Momentum are above 100 (/). A positive RS-Ratio indicates an uptrend in relative performance and positive momentum means this trend is still pushing higher.

A sector is in the weakening quadrant (yellow) when RS-Ratio is above 100, but RS-Momentum moves below 100 (+/-). A positive RS-Ratio indicates an uptrend in relative performance, but negative momentum means this uptrend is stalling or losing power.

A sector is in the lagging quadrant when RS-Ratio and RS-Momentum are both below 100 (-/-). A negative RS-Ratio indicates a downtrend in relative performance and negative momentum means this downtrend is still pushing lower.

A sector is in the improving quadrant when RS-Ratio is below 100, but RS-Momentum moves above 100 (-/+). A negative RS-Ratio indicates a downtrend in relative performance, but positive momentum means this downtrend is stalling or potentially reversing.

### Indicator / Formula

_SECTION_BEGIN( "RRG 2.2" ); _N( base = ParamStr( "Base", "EGX30" ) ); _N( list = ParamStr( "Symbols", "comi,hrho,heli,esrs,tmgh" ) ); tbar = Param( "Trailing Bar", 12, 1, 100, 1 ); color1 = ParamColor("Symbol 1:", colorRed); color2 = ParamColor("Symbol 2:", colorOrange); color3 = ParamColor("Symbol 3:", colorBrightGreen); color4 = ParamColor("Symbol 4:", colorDarkGreen); color5 = ParamColor("Symbol 5:", colorBlue); color6 = ParamColor("Symbol 6:", colorCustom10); color7 = ParamColor("Symbol 7:", colorPlum); color8 = ParamColor("Symbol 8:", colorBrown); color9 = ParamColor("Symbol 9:", colorViolet); color10 = ParamColor("Symbol 10:", colorCustom12); color11 = ParamColor("Symbol 11:", colorPink); color12 = ParamColor("Symbol 12:", colorIndigo); color13 = ParamColor("Symbol 13:", colorDarkGrey); color14 = ParamColor("Symbol 14:", colorTeal); color15 = ParamColor("Symbol 15:", colorTan); color16 = ParamColor("Symbol 16:", colorCustom16); color17 = ParamColor("Symbol 17:", colorBrightGreen); color18 = ParamColor("Symbol 18:", colorDarkBlue); color19 = ParamColor("Symbol 19:", colorDarkOliveGreen); color20 = ParamColor("Symbol 20:", colorYellow); list = Name()+","+list; EnableTextOutput( False ); GfxSetOverlayMode( 2 ); pxl = Status( "pxchartleft" ); pxr = Status( "pxchartright" ); pxt = Status( "pxcharttop" ); pxb = Status( "pxchartbottom" ); pxw = ( pxr - pxl ) / 2; pxh = ( pxb - pxt ) / 2; xm = pxl + pxw; ym = pxt + pxh; GfxMoveTo( pxl, ym ); GfxLineTo( pxr, ym ); GfxMoveTo( xm, pxt ); GfxLineTo( xm, pxb ); GfxSelectSolidBrush(ColorRGB(102,255,102)); GfxRectangle( xm, ym, pxr, pxt ); GfxSelectSolidBrush(ColorRGB(255,101,102)); GfxRectangle( xm, ym, pxl, pxb ); GfxSelectSolidBrush(ColorRGB(255,255,204)); GfxRectangle( xm, ym, pxr, pxb ); GfxSelectSolidBrush(ColorRGB(135,206,235)); GfxRectangle( xm, ym, pxl, pxt ); GfxSelectFont("Arial", Status("pxheight")/60 ); GfxSetTextColor( ParamColor( "Text Color", colorBlack ) ); GfxSetBkMode(0); // transparent GfxSetBkColor(colorPaleGreen); GfxTextOut( "Leading", pxr-120 , pxt +50 ); // Leading GfxSetBkColor(colorPink); GfxTextOut( "Lagging", pxl+15, pxb-55 ); // Lagging GfxSetBkColor(colorLightYellow); GfxTextOut( "Weakening ", pxr-100, pxb-65); // Weakening GfxSetBkColor(colorLightBlue); GfxTextOut( "Improving", pxl+15, pxt+60 ); // Improving GfxSelectFont("", Status("pxheight")/90 ); //GfxTextOut( "Updated by Ahmed Amin", Status("pxwidth")/80, Status("pxheight")/1.04 ); GfxTextOut( "Updateded by Ahmed Amin ", Status("pxwidth")/80, Status("pxheight")/1.04 ); function getrs ( sc, t ) { bc = Foreign( base, "C" ); sbr = sc / bc; rs1 = MA( sbr, 12 ); rs2 = MA( sbr, 26 ); rs = 100 * ( ( rs1 - rs2 ) / rs2 + 1 ); rm1 = MA( rs, 1 ); rm2 = MA( rs, 9 ); rm = 100 * ( ( rm1 - rm2 ) / rm2 + 1 ); return IIf( t, rs , rm ) - 100; } function drawpos ( x, y, sym, text ) { rsl = VarGet( "rsl" ); rsh = VarGet( "rsh" ); rml = VarGet( "rml" ); rmh = VarGet( "rmh" ); xx = pxl + pxw + x * ( pxw / ( Max( rsh, -rsl ) * 1.10 ) ); yy = pxb - pxh - y * ( pxh / ( Max( rmh, -rml ) * 1.10 ) ); xp = Nz( VarGet( "xp" + sym ), xx ); yp = Nz( VarGet( "yp" + sym ), yy ); VarSet( "xp" + sym, xx ); VarSet( "yp" + sym, yy ); GfxMoveTo( xp, yp ); GfxLineTo( xx, yy ); GfxCircle( xx, yy, IIf( text == "", 2, 4 ) ); if ( text != "" ) GfxTextOut( sym, xx + 6 , yy - 3 ); } for ( i = 0; ( sym = StrExtract( list, i ) ) != ""; i++ ) { SetForeign( sym ); rs = getrs( C, 1 ); rm = getrs( C, 0 ); for ( ii = BarCount - tbar; ii < BarCount; ii++ ) { rs_ = rs[ ii ]; rm_ = rm[ ii ]; rsh = Nz( VarGet( "rsh" ), rs_ ); if ( rs_ >= rsh ) VarSet( "rsh", rs_ ); rsl = Nz( VarGet( "rsl" ), rs_ ); if ( rs_ <= rsl ) VarSet( "rsl", rs_ ); rmh = Nz( VarGet( "rmh" ), rm_ ); if ( rm_ >= rmh ) VarSet( "rmh", rm_ ); rml = Nz( VarGet( "rml" ), rm_ ); if ( rm_ <= rml ) VarSet( "rml", rm_ ); } RestorePriceArrays( True ); } for ( i = 0; ( sym = StrExtract( list, i ) ) != ""; i++ ) { SetForeign( sym ); rs = getrs( C, 1 ); rm = getrs( C, 0 ); for ( ii = BarCount - tbar; ii < BarCount; ii++ ) { drawpos( rs[ ii ], rm[ ii ], sym, WriteIf( ii == BarCount - 1, sym, "" ) ); } RestorePriceArrays( True ); } _SECTION_END();

### 8 comments

#### Leave Comment

Please login here to leave a comment.

Back
1.SwetavTHANKS FOR THE INDICATOR.

2.iwanHalo Sir, How to scan all the Stocks under this AFL? Thank you.

3.iwanHallo Sir. I don’t see any color for each

Stocks. Please, explain the Code. Thank you.

4.wealtheroThanks for posting the codes. FYI, when I changed the RS MA period to 10 and 30 it matches the RRG calculation results (Daily basis) from the Refinitive Eikon terminal. The original 12 and 26 are close, but using 10 and 30 yielded the exact results as on the Eikon terminal.

`rs1 = MA( sbr, 10 ); rs2 = MA( sbr, 30 );`

5.ngocmai113Please Plot each symbol with each Color.

thanks alot

6.rwhoroI’m wondering why the plot changes whenever I click on a ticker in the Symbol window that is not one of those listed in the ParamList. Difficult to trust the chart because of that. Even “Reset All” doesn’t fix this, as by the code it shouldn’t affect the chart.

7.rwhoroI’ll post my revisions to the code to enable correct coloring of the lines if I can get an answer to my above question.

8.Oversleep5388came here for the rrg formula. this is the only one that worked.

guys, i wanted to thank you from the bottom of my heart!! Ahmed and wealthero, this is fantastic!

used it in my own web app.

it is not 100% like reuters but it is very, very close: