Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- study("Dirty Valuewhen")
- // Dirty equivalent of valuewhen.
- f_valuewhen(_cond, _src, _occ) =>
- _cnt = 0
- _ii = int(na)
- for _i=0 to 10000
- if na(_src[_i])
- // No more data and not found; exit.
- break
- int(na)
- else
- if _cond[_i]
- // Condition true. If proper occurrence save index; otherwise increment cnt of occurrences.
- if _cnt == _occ
- // Proper occurrence found, exit.
- _ii := _i
- break
- int(na)
- else
- _cnt := _cnt + 1
- // Return source at occurrece if proper occurrence found.
- na(_ii)? na:_src[_ii]
- cond = close > open and close[1] > open[1]
- src = bar_index
- occ = input(0)
- v1 = f_valuewhen(cond, src, occ)
- v2 = valuewhen(cond, src, occ)
- plot(v1, "f_valuewhen()", color.silver, 6, transp = 60)
- plot(v2, "valuewhen()")
Add Comment
Please, Sign In to add comment