Hello Nikolay,
I see your point. Very good question. Thank You. The following block of code looks like it has a look ahead bias:
px[(px<= px.shift(-1)) & (px < px.shift(+1))] One bar after (px.shift(-1)) and one bar before (px.shift(+1)).
This is a vectorised filter. It looks at pas data, searches for highs surrounded by lows for swign fractal highs and lows surrounded by highs to find fractal lows.
Now in real time, let' say the current bar is a high. If we ran the code, it would not be identified as a high until the following bar. When the data updates, the new bar would be lower than the previous one and a fractal would be identified.
This is why when we run real time data that periodically refreshes, we do not need to run the function fractal_date_df(df,_h,_l,_c) to identify when fractals occur. This function works for historical data,not continuous data.
When running real time data in production, all we need to do is:
- run the functions fractal(px, lvl) (which you copied above) and fractal_df(df,_h,_l,_c)
- Calculate the delta in regime from this bar to the previous
I hope this answered your question. If not, we can hop a call if You want to. I could walk You through the code and get to know you.
Once again, thank You very much for your question. Really really appreciated