// Downloaded From https://www.WiseStockTrader.com

/*
** Rotasi Saham / Stock Rotation XY-Chart Exploration
** Author: newbie123
** --------
** Explore Stocks based on their position in the XY-Chart quadrant.
*/

_N( base = ParamStr( "Base", "IHSG" ) );
Value = Param( "Trx Value (in Billion)", 50, 0, 1000, 1 );

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;
}

rs = getrs( C, 1 );
rm = getrs( C, 0 );

Lagging = rs < 0 AND rm < 0;
Improving = rs < 0 AND rm > 0;
Leading = rs > 0 AND rm > 0;
Weakening = rs > 0 AND rm < 0;

pos = WriteIf( Lagging, "3. Lagging",
               WriteIf( Improving, "4. Improving",
                        WriteIf( Leading, "1. Leading",
                                 WriteIf( Weakening, "2. Weakening", "5." ) ) ) );

qcolor = IIf( Lagging, colorOrange,
              IIf( Improving, colorSkyblue,
                   IIf( Leading, colorBrightGreen,
                        IIf( Weakening, colorYellow, colorLightGrey ) ) ) );

VAL = V * C / ( 10 ^ 9 * 0.01 /*fraksi lot - Indonesian Market*/ ); // in billion
Chg = ROC( C, 1 );

Filter = LastValue( VAL ) > Value;

AddColumn( C, "Last", 1.0, colorDefault, colorDefault, 70 );
AddColumn( Chg, "%Chg", 1.2, IIf( Chg > 0, colorGreen, IIf( Chg < 0, colorRed, colorDefault ) ), IIf( Chg >= 5, colorPaleGreen, IIf( Chg <= -5, colorPink, colorDefault ) ), 70 );
AddTextColumn( pos, "Quadrant Pos", 1.0, IIf( qcolor == colorLightGrey, qcolor, colorDefault ), qcolor, 170 );
AddColumn( VAL, "Trx Value", 1.2, colorDefault, colorDefault, 100 );

SetSortColumns( 5, -6 );