-3

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:

  1. Find the nearest previous Higher Pivot Point then lowest Pivot Point since then till Current Price.

  2. 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?

Pivots

zitrusire2520
  • 180
  • 2
  • 11
JoHa
  • 1,989
  • 10
  • 28
  • 42

1 Answers1

1

It is possible to LOOKBACK in PineScript, but it is not possible to LOOKFORWARD. If you want to save a value, that you can access later, then you need to save it to a var variable.

Here is a post I answered last summer, where I explain var variables in more detail. explaining var variable in post

Here is also a post from last summer, where I show how to save Pivot Points to var variables. saving to most recent pivot point in var variable

Marcus Cazzola
  • 313
  • 1
  • 9