Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=4
- study("Momo Gaps 0.31", overlay=true)
- sbb = true // input(true, title="Large Bars")
- biglook = 10 // input(10, minval=1, maxval=99, title="Big Bar Lookback")
- usebodies = false // input(false, title="Use Bodies, not Wicks")
- range = usebodies ? max(open, close) - min(open, close) : high - low
- stddevlevel = 3 // input(title="Sensitivity", type=float, defval=3, step=0.5)
- bardev = stdev(range, biglook) * stddevlevel
- bigup = close > open and abs(close - open) > bardev
- bigdown = close < open and abs(open - close) > bardev
- bigbar = bigup or bigdown
- fillgaps = input(false, title="Highlight Whole Gap")
- widthoflines = input(title="Line Thickness", type=input.integer, defval=2, minval=1, maxval=5)
- gapup = high[2] < low[0] and high[2] > low[1] and high[1] > low[0]
- gapdown = low[2] > high[0] and low[2] < high[1] and low[1] < high[0]
- gapup_high = fixnan(gapup ? low[0] : na)
- gapup_low = fixnan(gapup ? high[2] : na)
- gapup_low := gapup_low < low ? gapup_low : na
- // plot(barssince(cross(gapup_low, low)))
- // plot(barssince(gapup_low != gapup_low[1]))
- // gapup_low := barssince(cross(gapup_low, low)) >= barssince(gapup_low != gapup_low[1]) ? gapup_low : na
- gapup_high_ext = fixnan(valuewhen(change(gapup_high) != 0, gapup_high, 1))
- gapup_low_ext = fixnan(valuewhen(change(gapup_low) != 0, gapup_low, 1))
- // gap_start = high[length]
- // gap_end = low[length - 1]
- // gap_bull = false
- // gap_bear = false
- inf_gap = 0.0
- sup_gap = 0.0
- // if barstate.islast
- // for j = 1 to length
- // gap_bull := false
- // gap_bear = false
- // inf_gap := 0.0
- // sup_gap := 0.0
- // if high[j] < low[j - 1] //bull gap
- // gap_start := high[j]
- // gap_end := low[j - 1]
- // gap_bull := true
- // inf_gap := gap_start
- // sup_gap := gap_end
- // for i = (j-1) to 0
- // sup_gap := min(sup_gap, low[i])
- // if ((sup_gap - inf_gap)/(syminfo.mintick*10) < pips) // only gap > x pips are considered
- // gap_bull := false
- // if low[j] > high[j - 1] //bear gap
- // gap_start := low[j]
- // gap_end := high[j - 1]
- // gap_bear := true
- // inf_gap := gap_end
- // sup_gap := gap_start
- // for i = (j-1) to 0
- // inf_gap := max(inf_gap, high[i])
- // if ((sup_gap - inf_gap)/(syminfo.mintick*10) < pips) // only gap > x pips are considered
- // gap_bear := false
- //Affichage gap Bull ou Bear
- if gapup
- // 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) + ']',
- // color=color.green,
- // textcolor=color.white,
- // style=label.style_labelup, yloc=yloc.belowbar)
- // //label.delete(label_bull[1])
- var line_bull_inf = line(na)
- line_bull_inf := line.new(x1 = bar_index-1, y1 = gapup_high,
- x2 = bar_index, y2 = gapup_high,
- extend=extend.right, color = color.green, style = line.style_solid, width = 1)
- //line.delete(line_bull_inf[3])
- for i = 0 to 20
- 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])
- line.set_x2(line_bull_inf[i], bar_index)
- line.set_extend(line_bull_inf[i], extend.none)
- var line_bull_sup = line(na)
- line_bull_sup := line.new(x1 = bar_index-1, y1 = gapup_low,
- x2 = bar_index, y2 = gapup_low,
- extend=extend.right, color = color.green, style = line.style_solid, width = 1)
- //line.delete(line_bull_sup[3])
- for i = 0 to 20
- 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])
- line.set_x2(line_bull_sup[i], bar_index)
- line.set_extend(line_bull_sup[i], extend.none)
- color_1 = color.new(color.lime, 100)
- 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)
- color_2 = color.new(color.gray, 100)
- p2 = plot(gapup_low, color=gapup_low == gapup_low[1] ? color.lime : color_2, offset=0, title="gapup_low", linewidth=widthoflines)
- color_3 = color.new(color.lime, 40)
- color_4 = color.new(color.lime, 100)
- fill(p1, p2, color=gapup_low == gapup_low[1] ? color_3 : color_4)
- //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)
- //plot(gapup_low_ext, color=gapup_low_ext == gapup_low_ext[1] ? lime : color(gray,80), offset=-3, title="gapup_low_ext", linewidth=widthoflines)
- gapdown_high = fixnan(gapdown ? low[2] : na)
- gapdown_low = fixnan(gapdown ? high[0] : na)
- gapdown_high := gapdown_high > high ? gapdown_high : na
- gapdown_high_ext = fixnan(valuewhen(change(gapdown_high) != 0, gapdown_high, 1))
- gapdown_low_ext = fixnan(valuewhen(change(gapdown_low) != 0, gapdown_low, 1))
- if gapdown
- // 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) + ']',
- // color=color.red,
- // textcolor=color.white,
- // style=label.style_labeldown, yloc=yloc.abovebar)
- // //label.delete(label_bear[1])
- var line_bear_inf = line(na)
- line_bear_inf := line.new(x1 = bar_index-1, y1 = gapdown_high,
- x2 = bar_index, y2 = gapdown_high,
- extend=extend.right, color = color.red, style = line.style_solid, width = 1)
- //line.delete(line_bear_inf[3])
- for i = 0 to 20
- 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])
- line.set_x2(line_bear_inf[i], bar_index)
- line.set_extend(line_bear_inf[i], extend.none)
- var line_bear_sup = line(na)
- line_bear_sup := line.new(x1 = bar_index-1, y1 = gapdown_low,
- x2 = bar_index, y2 = gapdown_low,
- extend=extend.right, color = color.red, style = line.style_solid, width = 1)
- //line.delete(line_bear_sup[3])
- for i = 0 to 20
- 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])
- line.set_x2(line_bear_sup[i], bar_index)
- line.set_extend(line_bear_sup[i], extend.none)
- color_5 = color.new(color.gray, 100)
- p3 = plot(gapdown_high, color=gapdown_high == gapdown_high[1] ? color.fuchsia : color_5, offset=0, title="gapdown_high", linewidth=widthoflines)
- color_6 = color.new(color.fuchsia, 100)
- p4 = plot(fillgaps ? gapdown_low : na, color=gapdown_high == gapdown_high[1] ? color.fuchsia : color_6, offset=0, title="gapdown_low", linewidth=widthoflines)
- color_7 = color.new(color.fuchsia, 40)
- color_8 = color.new(color.fuchsia, 100)
- fill(p3, p4, color=gapdown_low == gapdown_low[1] ? color_7 : color_8)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement