xmd79

Block v.2

Oct 4th, 2021
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.80 KB | None | 0 0
  1. //@version=4
  2. study("Block v.2", overlay=true, max_boxes_count = 100)
  3. color c_up = input(color.green, "Bar Color Up", type = input.color)
  4. color c_down = input(color.red, "Bar Color Down", type = input.color)
  5. color c_up_b = input(color.green, "Box Color Up", type = input.color)
  6. color c_down_b = input(color.red, "Box Color Down", type = input.color)
  7. trans = input(85, minval = 0, maxval = 100)
  8. src = close
  9. float highs = 0.0
  10. float lows = 0.0
  11. highs := close > nz(highs[1]) or close < nz(lows[1]) ? high : max(high, highs[1])
  12. lows := close > nz(highs[1]) or close < nz(lows[1]) ? low : min(low, lows[1])
  13. colors = color.green
  14. colors := close > nz(highs[1]) or close < nz(lows[1]) ? close > open ? c_up : c_down : na
  15. new_block = close > highs[1] or close < lows[1]
  16. plotshape(new_block, "New Block", shape.diamond, location.abovebar, colors)
  17. barcolor(colors)
  18. //boxes
  19. var n = 0
  20. if(new_block)
  21. var cbar = 0
  22. var line line1 = na
  23. var line line2 = na
  24.  
  25. icolor = color.red
  26. icolor := close > open ? c_up_b : c_down_b
  27. cbar := new_block ? bar_index : na
  28. if (icolor != icolor[1] and icolor == c_up_b)
  29. mybox = box.new(left=bar_index, top=highs[1],
  30. right=cbar[1] , bottom=lows[1], bgcolor=color.new(icolor[1], trans),
  31. border_width=na)
  32. line1 := line.new(cbar[1], lows[1] ,cbar , highs[1])
  33. line.set_xy2(id = line2,x = cbar[1],y = lows[1])
  34. if (icolor != icolor[1] and icolor == c_down_b)
  35. mybox = box.new(left=bar_index, top=highs[1],
  36. right=cbar[1] , bottom=lows[1], bgcolor=color.new(icolor[1], trans),
  37. border_width=na)
  38. line.set_xy2(id = line1,x = cbar[1],y = highs[1])
  39. line2 := line.new(cbar[1], highs[1], cbar, lows[1])
  40.  
  41. line.set_color(id = line1, color = #2efb37)
  42. line.set_color(id = line2, color = #2efb37)
Advertisement
Add Comment
Please, Sign In to add comment