Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- int mbp = 1000
- version = 'v4.2'
- indicator('Ровные пацаны', overlay = true, max_lines_count = 500, max_bars_back = mbp, max_labels_count = 500)
- max_bars_back(time, mbp)
- max_bars_back(low, mbp)
- max_bars_back(close, mbp)
- max_bars_back(open, mbp)
- max_bars_back(high, mbp)
- color naColor = na
- equalPivotLiqCat = 'Ровные пацаны'
- eqlEnabled = input.bool(true, "EQL", group = equalPivotLiqCat, inline = 'm')
- eqlText = "EQHL"
- eqhEnabled = input.bool(true, "EQH", group = equalPivotLiqCat, inline = 'm')
- eqhText = "EQH"
- maxEQPs = input.int(10, "Max", minval = 1, maxval = 250, group = equalPivotLiqCat, inline = '2')
- findByWicks = input.bool(true, 'Учитывать вик?', group = equalPivotLiqCat, inline = 'm')
- eqpColor = input.color(color.new(color.black, 50), "Цвет", group = equalPivotLiqCat, inline = '1')
- eqpWidth = input.int(1, "", minval = 1, maxval = 5, group = equalPivotLiqCat, inline = '1')
- eqpStyle = input.string(line.style_dashed, "", options = [line.style_solid, line.style_dashed, line.style_dotted], group = equalPivotLiqCat, inline = '1')
- slopedView = true
- showPeriodLabels = true
- centerLabels = true
- lineStyle =line.style_solid
- lineColor = color.black
- lineWidth = 1
- var periodLabels = array.new<label>()
- var periodLines = array.new<line>()
- var editingLowSweeps = array.new<line>()
- var closedLowSweeps = array.new<line>()
- var editingHighSweeps = array.new<line>()
- var closedHighSweeps = array.new<line>()
- endBar = mbp - 1
- if endBar >= bar_index
- endBar := bar_index - 1
- noColor = color.new(color.white, 100)
- createTextLabel(tf) =>
- r = tf
- if str.contains(tf, 'M') or str.contains(tf, 'D') or str.contains(tf, 'Y') or str.contains(tf, 'W') or str.contains(tf, 's')
- r := tf
- else
- s = timeframe.in_seconds(tf)
- s /= 60
- if s / 60 >= 1
- r := str.tostring(s / 60) + 'H'
- else
- r := tf + 'm'
- r
- buildLevelsLowOrHigh(tf, tft, v, ov, lows, showcur, showprev, showcrossed, bi) =>
- var line curLine = na
- var label curLabel = na
- var line prevLine = na
- var label prevLabel = na
- var bool prevSwept = false
- var int pt = na
- var float mv = na
- var curtxt = (lows ? 'LO' : 'HO') + tf
- var prevtxt = 'P' + tf + (lows ? 'L' : 'H')
- if na(curLine)
- curLine := line.new(na, na, na, na, width = lineWidth, color = showcur ? lineColor : naColor, style = lineStyle)
- curLabel := label.new(na, na, na, size = size.small, color = noColor, style = centerLabels ? label.style_label_left : lows ? label.style_label_up : label.style_label_down, textcolor = showcur and showPeriodLabels ? lineColor : naColor)
- if showcur and showPeriodLabels
- array.push(periodLines, curLine)
- array.push(periodLabels, curLabel)
- prevLine := line.new(na, na, na, na, width = lineWidth, color = showprev ? lineColor : naColor, style = lineStyle)
- prevLabel := label.new(na, na, na, size = size.small, color = noColor, style = centerLabels ? label.style_label_left : lows ? label.style_label_up : label.style_label_down, textcolor = showprev and showPeriodLabels ? lineColor : naColor)
- if showprev and showPeriodLabels
- array.push(periodLines, prevLine)
- array.push(periodLabels, prevLabel)
- if na(pt) or pt != tft
- pt := tft
- x1 = line.get_x1(curLine)
- x2 = line.get_x2(curLine)
- if bi - x1 >= mbp
- x1 := bi - mbp
- if bi - x2 >= mbp
- x2 := bi - mbp
- line.set_xy1(prevLine, x1, line.get_y1(curLine))
- line.set_xy2(prevLine, x2, line.get_y2(curLine))
- label.set_xy(prevLabel, x2, line.get_y2(curLine))
- label.set_style(prevLabel, centerLabels ? label.style_label_left : lows ? label.style_label_up : label.style_label_down)
- prevSwept := false
- mv := na
- line.set_y1(curLine, ov)
- line.set_y2(curLine, ov)
- label.set_y(curLabel, ov)
- if na(mv) or (mv >= ov and lows) or (mv <= ov and not lows)
- mv := ov
- line.set_x1(curLine, bi)
- line.set_y1(curLine, mv)
- line.set_xy2(curLine, bi, mv)
- label.set_xy(curLabel, bi, mv)
- label.set_text(curLabel, curtxt)
- label.set_text(prevLabel, prevtxt)
- if not prevSwept
- line.set_x2(prevLine, bi)
- label.set_x(prevLabel, bi)
- if (ov <= line.get_y1(prevLine) and lows) or (ov >= line.get_y1(prevLine) and not lows)
- x = (line.get_x1(prevLine) + line.get_x2(prevLine)) / 2
- if bi - x >= mbp
- x := bi - mbp
- if not showcrossed
- x := na
- line.set_x1(prevLine, x)
- line.set_x2(prevLine, x)
- label.set_x(prevLabel, x)
- label.set_style(prevLabel, lows ? label.style_label_up : label.style_label_down)
- prevSwept := true
- buildLevels(tf, showcur = true, showprev = true, showcrossed = true) =>
- [tft, h, l] = request.security(syminfo.tickerid, tf, [time, high, low], barmerge.gaps_off, barmerge.lookahead_on)
- if showcur or showprev
- buildLevelsLowOrHigh(tf, tft, l, low, true, showcur, showprev, showcrossed, bar_index)
- buildLevelsLowOrHigh(tf, tft, h, high, false, showcur, showprev, showcrossed, bar_index)
- formatLevelLabels() =>
- if barstate.islast and showPeriodLabels
- i = 0
- indx = array.new<int>()
- while i < array.size(periodLines)
- array.push(indx, i)
- i += 1
- i := 0
- while i < array.size(indx)
- i_ind = array.get(indx, i)
- i_ln = array.get(periodLines, i_ind)
- x1 = line.get_x1(i_ln)
- x2 = line.get_x2(i_ln)
- i_v = line.get_y1(i_ln)
- j = i + 1
- while j < array.size(indx)
- j_ind = array.get(indx, j)
- j_ln = array.get(periodLines, j_ind)
- px1 = line.get_x1(j_ln)
- px2 = line.get_x2(j_ln)
- if i_v == line.get_y1(j_ln) and ((x1 >= px1 and x1 <= px2) or (x2 >= px1 and x2 <= px2) or (px1 >= x1 and px1 <= x2) or (px2 >= x1 and px2 <= x2))
- i_lb = array.get(periodLabels, i_ind)
- j_lb = array.get(periodLabels, j_ind)
- label.set_text(i_lb, label.get_text(i_lb) + ',' + label.get_text(j_lb))
- label.set_text(j_lb, na)
- array.remove(indx, j)
- else
- j += 1
- i += 1
- buildEqps(on, vs, lows) =>
- var eqps = array.new<line>()
- var labels = array.new<label>()
- if barstate.islast
- var last_handled = bar_index
- if array.size(eqps) == 0
- last_handled := bar_index - (mbp - 1) < 0 ? 0 : bar_index - (mbp - 1)
- pb = last_handled
- while pb <= bar_index
- last_bar = bar_index - pb
- pb += 1
- i = 0
- while i < array.size(eqps) and on
- l = array.get(eqps, i)
- if bar_index - line.get_x1(l) >= mbp
- line.delete(array.remove(eqps, i))
- label.delete(array.remove(labels, i))
- continue
- last_bi = bar_index - line.get_x1(l)
- last_v = vs[last_bi]
- if ((vs[last_bar] < last_v or vs[last_bar + 1] < last_v) and lows) or ((vs[last_bar] > last_v or vs[last_bar + 1] > last_v) and not lows)
- line.delete(array.remove(eqps, i))
- label.delete(array.remove(labels, i))
- else
- break
- off = last_bar + 2
- if on and not na(vs[off + 1])
- v = vs[off]
- if (lows and v < vs[off + 1] and v <= vs[off - 1]) or (not lows and v > vs[off + 1] and v >= vs[off - 1])
- bi = bar_index[off]
- i := 0
- while i < array.size(eqps)
- l = array.get(eqps, i)
- last_bi = bar_index - line.get_x1(l)
- if last_bi > mbp
- line.delete(array.remove(eqps, i))
- label.delete(array.remove(labels, i))
- continue
- last_v1 = vs[last_bi]
- last_body = lows ? math.min(open[last_bi], close[last_bi]) : math.max(open[last_bi], close[last_bi])
- update = (v >= last_v1 and v <= last_body and lows) or (v <= last_v1 and v >= last_body and not lows)
- if update and line.get_x1(l) != line.get_x2(l)
- last_bi := bar_index - line.get_x2(l)
- last_v2 = vs[last_bi]
- update := (v <= last_v2 and lows) or (v >= last_v2 and not lows)
- if update
- if slopedView
- line.set_xy2(l, bi, v)
- else
- line.set_xy2(l, bi, v)
- line.set_y1(l, v)
- txt = array.get(labels, i)
- label.set_textcolor(txt, eqpColor)
- label.set_xy(txt, (line.get_x1(l) + bi) / 2, (line.get_y1(l) + line.get_y2(l)) / 2)
- i += 1
- if (lows and v < vs[off + 1] and v <= vs[off - 1]) or (not lows and v > vs[off + 1] and v >= vs[off - 1])
- int after = array.size(eqps)
- i := 0
- while i < array.size(eqps)
- l = array.get(eqps, i)
- last_bi = bar_index - line.get_x1(l)
- if last_bi > mbp
- line.delete(array.remove(eqps, i))
- label.delete(array.remove(labels, i))
- //removeEqpInd(inds, i)
- after := array.size(eqps)
- continue
- last_v1 = vs[last_bi]
- if (last_v1 > v and not lows) or (last_v1 < v and lows)
- after := i
- break
- i += 1
- array.insert(eqps, after, line.new(bar_index[off], v, bar_index[off], v, width = eqpWidth, color = eqpColor, style = eqpStyle))
- array.insert(labels, after, label.new(bar_index[off], v, (lows ? eqlText : eqhText), size = size.small, color = noColor, style = not lows ? label.style_label_down : label.style_label_up, textcolor = naColor))
- last_handled := bar_index
- int eqpsLen = array.size(eqps)
- while eqpsLen > maxEQPs
- float minx1 = na
- int mini = na
- found = false
- i = 0
- eqpsLen := 0
- while i < array.size(eqps)
- l = array.get(eqps, i)
- if line.get_x1(l) != line.get_x2(l)
- eqpsLen += 1
- if (na(minx1) or minx1 > line.get_x1(l))
- minx1 := line.get_x1(l)
- mini := i
- i += 1
- if na(minx1)
- break
- line.delete(array.remove(eqps, mini))
- label.delete(array.remove(labels, mini))
- eqpsLen -= 1
- true
- //}
- var int r0 = 0
- var int r1 = 0
- var int r2 = 0
- t = timenow
- t := timenow
- buildEqps(eqlEnabled and findByWicks, low, true)
- buildEqps(eqhEnabled and findByWicks, high, false)
- r2 += timenow - t
Advertisement
Add Comment
Please, Sign In to add comment