PineCoders

Dirty valuewhen()

Mar 8th, 2020
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. //@version=4
  2. study("Dirty Valuewhen")
  3.  
  4. // Dirty equivalent of valuewhen.
  5. f_valuewhen(_cond, _src, _occ) =>
  6. _cnt = 0
  7. _ii = int(na)
  8. for _i=0 to 10000
  9. if na(_src[_i])
  10. // No more data and not found; exit.
  11. break
  12. int(na)
  13. else
  14. if _cond[_i]
  15. // Condition true. If proper occurrence save index; otherwise increment cnt of occurrences.
  16. if _cnt == _occ
  17. // Proper occurrence found, exit.
  18. _ii := _i
  19. break
  20. int(na)
  21. else
  22. _cnt := _cnt + 1
  23. // Return source at occurrece if proper occurrence found.
  24. na(_ii)? na:_src[_ii]
  25.  
  26. cond = close > open and close[1] > open[1]
  27. src = bar_index
  28. occ = input(0)
  29.  
  30. v1 = f_valuewhen(cond, src, occ)
  31. v2 = valuewhen(cond, src, occ)
  32.  
  33. plot(v1, "f_valuewhen()", color.silver, 6, transp = 60)
  34. plot(v2, "valuewhen()")
Add Comment
Please, Sign In to add comment