How to change level in 0 -- 50 -- 100 and ignore buy signal above overbought zone and sell signal below oversold zone

Arrows = ParamToggle( "Buy/Sell Arrows", "No|Yes", 1 );
RSI_Length = Param( "RSI Length", 13, 1, 250, 1, 1 );
Stoc_Length = Param( "Stocastic Length", 8, 1, 250, 1, 1 );
WMA_Length = Param( "WMA Length", 6, 1, 40, 1, 1 );
BullSig = BearSig = Trigger = 0;



Value1 = RSIa( C, RSI_Length ) - LLV( RSIa( C, RSI_Length ), Stoc_Length );
Value2 = HHV( RSIa( C, RSI_Length ), Stoc_Length ) - LLV( RSIa( C, RSI_Length ), Stoc_Length );
Value3 = Nz( Value1 / Value2 );
Value4 = 2 * ( WMA( Value3, WMA_Length ) -0.5 );
Trigger = Ref( Value4, -1 );


BullSig = IIf( Cross( Value4, Trigger  ), True, False );
BearSig = IIf( Cross( Trigger, Value4  ), True, False );


//Filter = BullSig OR BearSig;
//AddColumn(IIf(BullSig,BullSig,BearSig), fgcolor = colorBlue, bkcolor=IIf(BullSig,colorGreen,colorRed));

Buy= BullSig;
Sell= BearSig;


Plot( Value4, "StocRSI", colorLightBlue );
Plot( Trigger, "Trigger", colorRed );
Plot( 0 , "", colorWhite, styleDashed );

if ( Arrows )
{
    PlotShapes( shapeUpArrow*BullSig, colorBrightGreen );
    PlotShapes( shapeDownArrow*BearSig, colorRed );
}




@jiten02, if I understand the first part of your topic title, you need to "rescale" the values that you want to plot, using something like this snippet (insert it in your code):

function Rescale( a, from, to )
{
    local minV, maxV, tmp;

    // check parameters
    if( from == to )
    {
        Error( "Rescale function: 'from' and 'to' parameters should NOT be equal" );
    }

    if( from > to )
    {
        tmp = from;
        from = to;
        to = tmp;
    }

    minV = LastValue( Lowest( a ) );
    maxV = LastValue( Highest( a ) );

    // A bit faster if you want to use it only for plotting "visible bars"  - remove the 2 lines above and uncomment these
    // minV = LowestVisibleValue( a );
    // maxV = HighestVisibleValue( a );

    // min-max normalization - see https://en.wikipedia.org/wiki/Feature_scaling
    return ( from  + ( to - from ) * ( ( a - minV ) / ( maxV - minV ) ) );
}

// define rescaling values ("scale_from" should be less than "scale_to")
scale_from = 0;
scale_to   = 100;

Value4 = Rescale( 2 * ( WMA( Value3, WMA_Length ) - 0.5 ), scale_from, scale_to );
Trigger = Rescale( Ref( Value4, -1 ), scale_from, scale_to );

midLine = scale_from + ( ( scale_to - scale_from ) / 2 );

// some other code...

Plot( Value4, "StocRSI", colorLightBlue );
Plot( Trigger, "Trigger", colorRed );
Plot( midline, "", colorWhite, styleDashed );

For the rest of the question (I suppose the topic title is your question), I suggest to elaborate a bit if you want to get more feedback.

1 Like