How to get Y coordinate for getting price Cross alert

@prakashganapathy, try this:

trendline = Study( "RE", getChartID() );    // this is a single Study named RE (a rectangle)

StartX = LastValue( ValueWhen( ExRem( trendline, 0 ), DateTime() ) );
EndX = LastValue( ValueWhen( trendline, DateTime() ) );
StartY = LastValue( ValueWhen( ExRem( trendline, 0 ), trendline ) );
EndY = LastValue( ValueWhen( trendline, trendline ) );

// Check the order of Ys to de sure that startY is lower then EndY
if( EndY < StartY )
{
    tempY = StartY;
    StartY = EndY;
    EndY = TempY;
}

Title = "{{NAME}} {{DATE}}\n" +
        "Start at X = " + WriteVal( StartX, formatDateTime ) + ", Y = " + StartY +
        "\nEnd at X = " + WriteVal( EndX, formatDateTime ) + ", Y = " + EndY;

// Check signals only in the selected date range
dt = DateTime();
rectDtRange = dt >= StartX AND dt <= EndX;

Buy = iif( rectDtRange, Cross( StartY, L ), 0 );
Sell = iif( rectDtRange, Cross( H, EndY ), 0 );
// these generate signals on the full chart, not only on the "rectangle" 
// Buy = Cross( StartY, L ); 
// Sell = Cross( H, EndY );

PlotShapes( shapeUpArrow*Buy, colorGreen, 0, L, -10 );
PlotShapes( shapeDownArrow*Sell, colorRed, 0, H, -10 );

Plot( C, "Close", colorDefault, styleCandle );

You need to add a single study (a rectangle): name it "RE".
The top of the code is essentialy the same as the KB article you referenced.
I simply added some extra lines to ensure that the rectangle Y coordinates are in the right order to act as support and resistance.
Moreover I also use StartX and EndX to get signals only when they happens in the "rectangle".

2 Likes