HighestSince selected bar. Was: HHV based on future data

I would like create an array which is the highest high of the closes for the next 200 bars into the future. This array needs to be recalculated at each next bar until I have reached the end of the price array. My intention is to use this in a loop for some other calculations I need to do.

I would also like to visualise this line by plotting it from the current selected bar.

I've had a few goes at this but it quickly goes nowhere. Any suggestions would be appreciated.

Below is a photoshopped screenshot of what I am trying to describe.

HHV200_Future

Based on your verbal description, it seems like you just need something like this:

fwdHHV = Ref(HHV(C,200), 199);    // Includes current bar; use 200 instead of 199 to exclude current bar

However, that does not seem to match what you're showing in your chart. Can you clarify your goal?

@mradtke this is one of the things I tried that initially seemed right but was not what I needed.

Below is something very similar to what I need, but change the horizontal line to the HHV of the closes.

priceField = ParamField( "Price field", 3 );
lookForward = Param( "Periods", 250, 1, 250, 1 );

YVal = priceField;
startBar = SelectedValue( BarIndex() );

X0 = StartBar;
Y0 = SelectedValue( YVal );
X1 = StartBar + lookForward;
Y1 = Y0;

FwdLine = LineArray( X0, Y0, X1, Y1, 0, 1 );

Plot( FwdLine, "\nLine", colorCustom11, styleDashed );

The way I see it is that I may need a nested loop to calculate a fresh HHV array at each bar. So at iteration i I would then enter a sub-loop and iterate into the future 200 times to construct the HHV array and so on.

@rb250660 @mradtke I don't understand, isn't Matt's solution what you are looking for?

Look at this knowledge base article

http://www.amibroker.com/kb/2016/01/25/how-to-read-highest-high-value-of-future-bars/

... and additionally one more article:

http://www.amibroker.com/kb/2015/01/14/drawing-line-extensions-on-future-bars-using-afl/

None of this solves the problem. The array needs to be based on the first bar being the current cursor location. No past bars can be used to construct the array which is what the KB article @portfoliobuilder linked to does.

Based on the first post's picture's red line it looks like you are rather looking for HighestSince selected bar and line being as long as lookforward variable.

If that is the case then here is solution:

priceField = ParamField( "Price field", 3 );
lookForward = Param( "Periods", 250, 1, 250, 1 );

YVal = priceField;
bi = BarIndex();
startBar = SelectedValue( bi );

HHVforward = IIf( bi<=startbar+lookForward, HighestSince( bi == startbar, YVal), Null);

Plot( HHVforward, "\nLine", colorCustom11, styleDashed );
Plot( C, "Price", colorDefault, styleCandle );

2018-03-25_182848

5 Likes

@fxshrat does it again. Thank you!