# Plotting selected bars high or low with mouse click

Hi.
I've got a formula that works fine that will plot a horizontal ray starting from the low of the selected bar. I would like to alter the formula so that instead of plotting the low, if I point at the high of a bar I want to lock the line to that high and if I point to the low I want the line to lock to the low. The formula is quite long but I think that the part that I need to alter is the part that I have pasted below. Can someone please tell me how to plot the nearest high or low of the bar depending on which part of the bar I point at?

Thanks

``````y = GetCursorXPosition(0);

LineLevel = Low;   //IIf(y - SelectedValue(High) < y - SelectedValue(Low),SelectedValue(High),SelectedValue(Low));

function SupResLineLong_func(x1)
{

SRLineArray = Null;
SRLinestop = 0;

SRLinestop = LineLevel[x1];

SRLineArray[x1] = SRLinestop;

for( i = x1 + 1; i < BarCount; i++ )

{

if( SRLinestop > 0 )
{
SRLineArray [ i ] = SRLinestop;
}
}

return SRLineArray;
}
``````

I found a post by Jeetu

https://forum.amibroker.com/t/using-mouse-button-clicks-to-set-pivots-for-fibonacci-retracements-extensions/6694/25

that has been quite helpful but I'm completely stuck when it comes to saving the high or low. The line will plot on the respective high or low but only until I move the mouse. Can someone please help me with this?

``````MLBClicked = GetCursorMouseButtons() == 8;

MouseX = Nz( GetCursorXPosition( 1 ) );
MouseY = Nz( GetCursorYPosition( 0 ) );

selectBi = SelectedValue( BarIndex() );
selectH = SelectedValue( H );
selectL = SelectedValue( L );

CursoraboveH = MouseY> selectH ;
CursorbelowL = MouseY < SelectL;

function SupResLineLong_func(x1)
{

SRLineArray = Null;
SRLinestop = 0;

if (  CursoraboveH AND MLBClicked)
{
SRLinestop = High[x1];
}

if (  CursorbelowL AND MLBClicked)
{
SRLinestop = Low[x1];
}

SRLineArray[x1] = SRLinestop;

for( i = x1 + 1; i < BarCount; i++ )

{

if( SRLinestop > 0 )
{
SRLineArray [ i ] = SRLinestop;
}
}

return SRLineArray;
}
``````

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.