// Downloaded From https://www.WiseStockTrader.com
_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();