简体   繁体   中英

Find nearest previous Higher Pivot Point then lowest Pivot Point since then till Current Price (Pine)

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

支点

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM