get the Barindex of a vertical line

i draw a vertical line with hand and want to get the barindex in afl.
I can do it with a free drawed line, but not with a vertical line.
Study is "SU":
StartBarX = LastValue( ValueWhen( ExRem( SU, 0 ), BarIndex() ) );
That works with a free drawed line, with SU as ID. How can I do that with a vertical line?

Many Thanks.

@htrader I asked exactly the same question over 3 years ago on the Yahoo Group and got this reply from @aron - thanks for that :+1: I remember this as if it was yesterday as I was a newcomer then :wink:

Study() function will not return any values in case of a vertical line, therefore the study line goes undetected.

Plot( C , "", colorDefault );
st = Study( "ST", GetChartID());

Title = "Values: ";
for( i = 0; i < BarCount; i++ )
    value = st[i] ;
    if ( value )
    Title += "\n" + value;




Summing up - I'm afraid, you can't use vertical Study() the way you want. Here is this thread: Link

Thank you for this quick reply. It only doesnt work with a full vertical line. I was looking for this. You can check this, this works for me.

Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
st = Study( "ST", GetChartID());
Title = "Values: ";
BarX = ValueWhen( ST, BarIndex() ) ;
Title += "\nBarindex: " + BarX;

Yes, I know that. That's why I have shown you the above (@aron 's ) example.

By the way, if you draw a trendline holding X key pressed, you will get perfect vertical line. Similarily when you draw a trendline with Y key pressed, you will get perfect horizontal line (which can be shorter than when using Horizontal line Tool).

A quote from: AmiBroker 5.63.0 BETA Read Me

Added X/Y constaints for drawing tools. When you hold down "Y" key, start and end Y co-ordinates are set to equal value (with trend line it gives horizontal line ). When you hold down "X" key you get perfectly vertical line (X start/end set to equal value)


Thank you, Milosz, nice tip. Very good "workaround". Maybe even better, because clearer in the chart.

1 Like