简体   繁体   中英

Is there a way to get high/low values of selected bars?

With Pine Script, I would like to visualize pivot points (highs and lows) on a microlevel, concerning 3 bars according with the following condition for pivot highs:

(high[1] > high[0]) and (high[1] > high[2])

Next, I would like to visualize higher order pivot highs following the condition:

(pivothigh[1] > pivothigh[0]) and (pivothigh[1] > pivothigh[2])

Finally, I would like to make the same process for one further level. The first step has been done, however, I have problems with my second aims. How can I get the pivot high of the microlevel pivot highs?

study("Pivot points")

//Define the width to look for pivot highs
leftBars = input(1)
rightBars= input(1)

pivhigh = pivothigh(high,leftBars,rightBars)

//plotting the pivot highs on the micro level (however, with an additional offset)
plotshape(pivhigh, style = shape.xcross, location = location.abovebar, color=color.green, offset = -rightBars)

You can use arrays to store and evaluate the pivots and add the pivot high/low values to the higher order arrays as they occur.

var float[] first_order_pvhs = array.new_float()
var float[] second_order_pvhs = array.new_float()
var float[] third_order_pvhs = array.new_float()

if high[1] > high[0] and high[1] > high[2]
    array.unshift(first_order_pvhs, high[1])

pvh1_0 = array.get(first_order_pvhs, 0)
pvh1_1 = array.get(first_order_pvhs, 1)
pvh1_2 = array.get(first_order_pvhs, 2)

if pvh1_1 > pvh1_0 and pvh1_1 > pvh1_2
    array.unshift(second_order_pvhs, pvh1_1)

pvh2_0 = array.get(second_order_pvhs, 0)
pvh2_1 = array.get(second_order_pvhs, 1)
pvh2_2 = array.get(second_order_pvhs, 2)

if pvh2_1 > pvh2_0 and pvh2_1 > pvh2_2
    array.unshift(third_order_pvhs, pvh2_1)

You can see my implementation here: Higher Order Pivots

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