def nan = if isnan(close) then 1 else 0; def pvh = if high[-1] < high && high > high[1] then 1 else double.nan; def pvl = if low[-1] > low && low < low[1] then 1 else double.nan; def lefthigh = fold i = 0 to 252 with checker = 0 while pvh == 1 and checker != 1 and nan != 1 do if getvalue(pvh, 1 + i) == 1 and high > getvalue(high, 1 + i) then 1 else 0; def righthigh = fold j = 0 to 252 with checker2 = 0 while pvh == 1 and checker2 != 1 and nan != 1 do if getvalue(pvh, -1 - j) == 1 and high > getvalue(high, -1 - j) then 1 else 0; def secondpivothigh = if lefthigh == 1 and righthigh == 1 then 1 else double.nan; def leftlow = fold k = 0 to 252 with checker3 = 0 while pvl == 1 and checker3 != 1 and nan != 1 do if getvalue(pvl, 1 + k) == 1 and low < getvalue(low, 1 + k) then 1 else 0; def rightlow = fold p = 0 to 252 with checker4 = 0 while pvl == 1 and checker4 != 1 and nan != 1 do if getvalue(pvl, -1 - p) == 1 and low < getvalue(low, -1 - p) then 1 else 0; def secondpivotlow = if leftlow == 1 and rightlow == 1 then 1 else double.nan; plot secondorderhigh = secondpivothigh; plot secondorderlow = secondpivotlow; secondorderhigh.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN); secondorderlow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);