Advertisement
Guest User

Untitled

a guest
Jan 29th, 2020
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.45 KB | None | 0 0
  1. //@version=4
  2. study("Momo Gaps 0.31", overlay=true)
  3.  
  4. sbb = true // input(true, title="Large Bars")
  5. biglook = 10 // input(10, minval=1, maxval=99, title="Big Bar Lookback")
  6. usebodies = false // input(false, title="Use Bodies, not Wicks")
  7. range = usebodies ? max(open, close) - min(open, close) : high - low
  8. stddevlevel = 3 // input(title="Sensitivity", type=float, defval=3, step=0.5)
  9. bardev = stdev(range, biglook) * stddevlevel
  10. bigup = close > open and abs(close - open) > bardev
  11. bigdown = close < open and abs(open - close) > bardev
  12. bigbar = bigup or bigdown
  13. fillgaps = input(false, title="Highlight Whole Gap")
  14. widthoflines = input(title="Line Thickness", type=input.integer, defval=2, minval=1, maxval=5)
  15.  
  16. gapup = high[2] < low[0] and high[2] > low[1] and high[1] > low[0]
  17. gapdown = low[2] > high[0] and low[2] < high[1] and low[1] < high[0]
  18.  
  19.  
  20. gapup_high = fixnan(gapup ? low[0] : na)
  21. gapup_low = fixnan(gapup ? high[2] : na)
  22. gapup_low := gapup_low < low ? gapup_low : na
  23. // plot(barssince(cross(gapup_low, low)))
  24. // plot(barssince(gapup_low != gapup_low[1]))
  25. // gapup_low := barssince(cross(gapup_low, low)) >= barssince(gapup_low != gapup_low[1]) ? gapup_low : na
  26. gapup_high_ext = fixnan(valuewhen(change(gapup_high) != 0, gapup_high, 1))
  27. gapup_low_ext = fixnan(valuewhen(change(gapup_low) != 0, gapup_low, 1))
  28.  
  29. // gap_start = high[length]
  30. // gap_end = low[length - 1]
  31. // gap_bull = false
  32. // gap_bear = false
  33. inf_gap = 0.0
  34. sup_gap = 0.0
  35.  
  36. // if barstate.islast
  37. // for j = 1 to length
  38. // gap_bull := false
  39. // gap_bear = false
  40. // inf_gap := 0.0
  41. // sup_gap := 0.0
  42.  
  43. // if high[j] < low[j - 1] //bull gap
  44. // gap_start := high[j]
  45. // gap_end := low[j - 1]
  46. // gap_bull := true
  47. // inf_gap := gap_start
  48. // sup_gap := gap_end
  49. // for i = (j-1) to 0
  50. // sup_gap := min(sup_gap, low[i])
  51. // if ((sup_gap - inf_gap)/(syminfo.mintick*10) < pips) // only gap > x pips are considered
  52. // gap_bull := false
  53.  
  54. // if low[j] > high[j - 1] //bear gap
  55. // gap_start := low[j]
  56. // gap_end := high[j - 1]
  57. // gap_bear := true
  58. // inf_gap := gap_end
  59. // sup_gap := gap_start
  60. // for i = (j-1) to 0
  61. // inf_gap := max(inf_gap, high[i])
  62. // if ((sup_gap - inf_gap)/(syminfo.mintick*10) < pips) // only gap > x pips are considered
  63. // gap_bear := false
  64.  
  65. //Affichage gap Bull ou Bear
  66.  
  67. if gapup
  68. // label_bull = label.new(bar_index-1, na, 'Bull gap: ' + tostring((sup_gap - inf_gap)/(syminfo.mintick*10)) + ' pips\n' + '[' + tostring(inf_gap) + ' ; ' + tostring(sup_gap) + ']',
  69. // color=color.green,
  70. // textcolor=color.white,
  71. // style=label.style_labelup, yloc=yloc.belowbar)
  72. // //label.delete(label_bull[1])
  73. var line_bull_inf = line(na)
  74. line_bull_inf := line.new(x1 = bar_index-1, y1 = gapup_high,
  75. x2 = bar_index, y2 = gapup_high,
  76. extend=extend.right, color = color.green, style = line.style_solid, width = 1)
  77. //line.delete(line_bull_inf[3])
  78.  
  79. for i = 0 to 20
  80. if not na(line_bull_inf[i]) and line.get_y1(line_bull_inf[i]) >= low and line.get_x1(line_bull_inf[i]) + 1 == line.get_x2(line_bull_inf[i])
  81. line.set_x2(line_bull_inf[i], bar_index)
  82. line.set_extend(line_bull_inf[i], extend.none)
  83.  
  84. var line_bull_sup = line(na)
  85. line_bull_sup := line.new(x1 = bar_index-1, y1 = gapup_low,
  86. x2 = bar_index, y2 = gapup_low,
  87. extend=extend.right, color = color.green, style = line.style_solid, width = 1)
  88.  
  89. //line.delete(line_bull_sup[3])
  90. for i = 0 to 20
  91. if not na(line_bull_sup[i]) and line.get_y1(line_bull_sup[i]) >= low and line.get_x1(line_bull_sup[i]) + 1 == line.get_x2(line_bull_sup[i])
  92. line.set_x2(line_bull_sup[i], bar_index)
  93. line.set_extend(line_bull_sup[i], extend.none)
  94.  
  95. color_1 = color.new(color.lime, 100)
  96. p1 = plot(fillgaps ? gapup_high : na, color=gapup_low == gapup_low[1] ? color.lime : color_1, offset=0, title="gapup_high", linewidth=widthoflines, style=plot.style_linebr)
  97. color_2 = color.new(color.gray, 100)
  98. p2 = plot(gapup_low, color=gapup_low == gapup_low[1] ? color.lime : color_2, offset=0, title="gapup_low", linewidth=widthoflines)
  99. color_3 = color.new(color.lime, 40)
  100. color_4 = color.new(color.lime, 100)
  101. fill(p1, p2, color=gapup_low == gapup_low[1] ? color_3 : color_4)
  102.  
  103. //plot(barssince(gapup_low != 0) < 2 ? gapup_low : na, color=gapup_low == gapup_low[1] ? blue : color(gray,80), offset=-2, title="gapup_low_pre", linewidth=widthoflines)
  104. //plot(gapup_low_ext, color=gapup_low_ext == gapup_low_ext[1] ? lime : color(gray,80), offset=-3, title="gapup_low_ext", linewidth=widthoflines)
  105.  
  106. gapdown_high = fixnan(gapdown ? low[2] : na)
  107. gapdown_low = fixnan(gapdown ? high[0] : na)
  108. gapdown_high := gapdown_high > high ? gapdown_high : na
  109. gapdown_high_ext = fixnan(valuewhen(change(gapdown_high) != 0, gapdown_high, 1))
  110. gapdown_low_ext = fixnan(valuewhen(change(gapdown_low) != 0, gapdown_low, 1))
  111.  
  112. if gapdown
  113. // label_bear = label.new(bar_index-1, na, 'Bear gap: ' + tostring((sup_gap - inf_gap)/(syminfo.mintick*10)) + ' pips\n' + '[' + tostring(inf_gap) + ' ; ' + tostring(sup_gap) + ']',
  114. // color=color.red,
  115. // textcolor=color.white,
  116. // style=label.style_labeldown, yloc=yloc.abovebar)
  117. // //label.delete(label_bear[1])
  118.  
  119. var line_bear_inf = line(na)
  120. line_bear_inf := line.new(x1 = bar_index-1, y1 = gapdown_high,
  121. x2 = bar_index, y2 = gapdown_high,
  122. extend=extend.right, color = color.red, style = line.style_solid, width = 1)
  123. //line.delete(line_bear_inf[3])
  124. for i = 0 to 20
  125. if not na(line_bear_inf[i]) and line.get_y1(line_bear_inf[i]) <= high and line.get_x1(line_bear_inf[i]) + 1 == line.get_x2(line_bear_inf[i])
  126. line.set_x2(line_bear_inf[i], bar_index)
  127. line.set_extend(line_bear_inf[i], extend.none)
  128.  
  129. var line_bear_sup = line(na)
  130. line_bear_sup := line.new(x1 = bar_index-1, y1 = gapdown_low,
  131. x2 = bar_index, y2 = gapdown_low,
  132. extend=extend.right, color = color.red, style = line.style_solid, width = 1)
  133. //line.delete(line_bear_sup[3])
  134.  
  135. for i = 0 to 20
  136. if not na(line_bear_sup[i]) and line.get_y1(line_bear_sup[i]) <= high and line.get_x1(line_bear_sup[i]) + 1 == line.get_x2(line_bear_sup[i])
  137. line.set_x2(line_bear_sup[i], bar_index)
  138. line.set_extend(line_bear_sup[i], extend.none)
  139.  
  140. color_5 = color.new(color.gray, 100)
  141. p3 = plot(gapdown_high, color=gapdown_high == gapdown_high[1] ? color.fuchsia : color_5, offset=0, title="gapdown_high", linewidth=widthoflines)
  142. color_6 = color.new(color.fuchsia, 100)
  143. p4 = plot(fillgaps ? gapdown_low : na, color=gapdown_high == gapdown_high[1] ? color.fuchsia : color_6, offset=0, title="gapdown_low", linewidth=widthoflines)
  144. color_7 = color.new(color.fuchsia, 40)
  145. color_8 = color.new(color.fuchsia, 100)
  146. fill(p3, p4, color=gapdown_low == gapdown_low[1] ? color_7 : color_8)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement