xmd79

Order Blocks

Oct 14th, 2021
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. //@version=4
  2. study(title="Order Blocks", overlay=true,max_bars_back=1000)
  3.  
  4. // Input options
  5. sensitivity = input(title="Sensitivity", type=input.integer,defval=26, minval=5, maxval=100, group="BASIC SETTINGS")
  6.  
  7. bearishLLColour = input(title="Bearish OB Colour", type=input.color,defval=color.rgb(255,0,0, 80), group="STYLES")
  8. bullishLLColour = input(title="Bullish OB Colour", type=input.color,defval=color.rgb(0,255,0, 80), group="STYLES")
  9.  
  10.  
  11. // tracking for entries
  12. var int lastDownIndex=0
  13. var float lastDown=0
  14. var float lastDownClose=0
  15. var float lastDownLow=0
  16. var float lastDownOpen=0
  17.  
  18. var int lastUpIndex=0
  19. var float lastUp=0
  20. var float lastUpLow=0
  21. var float lastUpHigh=0
  22. var float lastUpClose=0
  23. var int longModeIndex=0
  24. var float lastUpOpen=0
  25.  
  26. // structure
  27. var int structureLowIndex=0
  28. float structureLow=1000000
  29.  
  30. // drawings
  31. var longBoxes = array.new_box()
  32. var shortBoxes = array.new_box()
  33.  
  34.  
  35. // load levels
  36. var int lastLongIndex=0
  37. var int lastShortIndex=0
  38. var bool lastShortIndex_EL=0
  39.  
  40. // stop run detection
  41. var box last_bull=na
  42. var box last_bear=na
  43.  
  44. var color barc=color.red
  45. var color obarc=color.white
  46. barc:=color.red
  47.  
  48.  
  49. // get the lowest point in the range
  50. structureLow:=lowest(low, sensitivity)[1]
  51.  
  52. // bearish break of structure
  53. if(crossunder(low,structureLow))
  54. // add short bos
  55. if(high>lastUpHigh)
  56. lastUpHigh:=high
  57. if((bar_index - lastUpIndex) < 4000)
  58.  
  59. // update structure high
  60. for p = 1 to (bar_index-lastUpIndex) by 1
  61. if(high[p]>lastUpHigh)
  62. lastUpHigh:=high[p]
  63.  
  64. last_bear:= box.new(left=lastUpIndex, top=lastUpHigh, bottom=lastUpLow,right=lastUpIndex, bgcolor=lastShortIndex==lastUpIndex?color.rgb(0, 0, 0, 100):bearishLLColour,border_color=bearishLLColour, extend=extend.right)
  65. array.push(shortBoxes,last_bear)
  66.  
  67.  
  68.  
  69. // bullish break of structure?
  70. if((array.size(shortBoxes)>0))
  71. for i = (array.size(shortBoxes)-1) to 0
  72. box=array.get(shortBoxes,i)
  73. top=box.get_top(box)
  74. bottom=box.get_bottom(box)
  75. left=box.get_left(box)
  76. if(high>top and (close>open) and (bar_index!=lastLongIndex))
  77. // remove the short box
  78. box.delete(box)
  79. array.remove(shortBoxes, i)
  80. // calculate LL bottom
  81. LLBottom= (low<lastDownLow?low:lastDownLow)
  82. // ok to darw
  83. if((bar_index - lastDownIndex) < 4000)
  84.  
  85. // update structure low
  86. for p = 1 to (bar_index-lastDownIndex) by 1
  87. if(low[p]<LLBottom)
  88. LLBottom:=low[p]
  89.  
  90. //
  91. last_bull:=box.new(left=lastDownIndex, top=lastDown, bottom=LLBottom,right=lastDownIndex, bgcolor=lastLongIndex==lastDownIndex?color.rgb(0, 0, 0, 100):lastShortIndex_EL==true?color.rgb(0, 255, 0, 80):bullishLLColour,border_color=lastLongIndex==lastDownIndex?color.rgb(0, 0, 0, 100):bullishLLColour, extend=extend.right)
  92. array.push(longBoxes, last_bull)
  93.  
  94. lastLongIndex:=bar_index
  95.  
  96. // remove LL if close below
  97. if((array.size(longBoxes) > 0))
  98. for i = (array.size(longBoxes)-1) to 0
  99. lbox=array.get(longBoxes,i)
  100. bottom=box.get_bottom(lbox)
  101. top=box.get_top(lbox)
  102. if(close<bottom)
  103. array.remove(longBoxes, i)
  104. box.delete(lbox)
  105.  
  106. // record last up and down candles
  107. if(close<open)
  108. lastDown:=high
  109. lastDownClose:=close
  110. lastDownOpen:=open
  111. lastDownLow:=low
  112. lastDownIndex:=bar_index
  113.  
  114. if(close>open)
  115. lastUp:=close
  116. lastUpIndex:=bar_index
  117. lastUpOpen:=open
  118. lastUpLow:=low
  119. lastUpClose:=close
  120. lastUpHigh:=high
  121.  
Advertisement
Add Comment
Please, Sign In to add comment