I have found the TradingView "Pivot Point HL" built in Pine script, which gives me the pivot points. I am trying to write a Pine script that:
Find the nearest previous Higher Pivot Point then lowest Pivot Point since then till Current Price.
Draw Fibonacci Retracement between these two points.
See below pseudo algorithm I wrote that I am trying to achieve:
- LOOP Lookback starting from nearest HIGH pivot point (greater than current price) and keep going to the higher ones
- For each, Lookahead from that point and find the LOWEST price hit so far
- Calculate a specific Fib level for them and return these two Pivot Points and draw that Fib level if: CURRENT PRICE is BELOW that level.
See attached. The LOOKBACK would first try Pivot 1 GREEN with 1 RED, fail then try Pivot 2 GREEN with 2 RED, fail then try Pivot 3 GREEN with Pivot 2 RED, succeed, so we found our two points to draw the Fibonacci retracement from Pivot 3 GREEN to Pivot 2 RED.
Is this achievable in Pine? Any script or useful Pine snippets you can point me to, to help me code this LOOKBACK and LOOKFORWARD?