xmd79

Ровные пацаны

Dec 24th, 2022
400
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.76 KB | None | 0 0
  1. //@version=5
  2.  
  3.  
  4. int mbp = 1000
  5. version = 'v4.2'
  6. indicator('Ровные пацаны', overlay = true, max_lines_count = 500, max_bars_back = mbp, max_labels_count = 500)
  7.  
  8. max_bars_back(time, mbp)
  9. max_bars_back(low, mbp)
  10. max_bars_back(close, mbp)
  11. max_bars_back(open, mbp)
  12. max_bars_back(high, mbp)
  13.  
  14. color naColor = na
  15. equalPivotLiqCat = 'Ровные пацаны'
  16. eqlEnabled = input.bool(true, "EQL", group = equalPivotLiqCat, inline = 'm')
  17. eqlText = "EQHL"
  18. eqhEnabled = input.bool(true, "EQH", group = equalPivotLiqCat, inline = 'm')
  19. eqhText = "EQH"
  20. maxEQPs = input.int(10, "Max", minval = 1, maxval = 250, group = equalPivotLiqCat, inline = '2')
  21. findByWicks = input.bool(true, 'Учитывать вик?', group = equalPivotLiqCat, inline = 'm')
  22.  
  23. eqpColor = input.color(color.new(color.black, 50), "Цвет", group = equalPivotLiqCat, inline = '1')
  24. eqpWidth = input.int(1, "", minval = 1, maxval = 5, group = equalPivotLiqCat, inline = '1')
  25. eqpStyle = input.string(line.style_dashed, "", options = [line.style_solid, line.style_dashed, line.style_dotted], group = equalPivotLiqCat, inline = '1')
  26. slopedView = true
  27. showPeriodLabels = true
  28. centerLabels = true
  29. lineStyle =line.style_solid
  30. lineColor = color.black
  31. lineWidth = 1
  32.  
  33. var periodLabels = array.new<label>()
  34. var periodLines = array.new<line>()
  35.  
  36. var editingLowSweeps = array.new<line>()
  37. var closedLowSweeps = array.new<line>()
  38.  
  39. var editingHighSweeps = array.new<line>()
  40. var closedHighSweeps = array.new<line>()
  41.  
  42.  
  43. endBar = mbp - 1
  44. if endBar >= bar_index
  45. endBar := bar_index - 1
  46.  
  47. noColor = color.new(color.white, 100)
  48.  
  49.  
  50. createTextLabel(tf) =>
  51. r = tf
  52. 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')
  53. r := tf
  54. else
  55. s = timeframe.in_seconds(tf)
  56. s /= 60
  57. if s / 60 >= 1
  58. r := str.tostring(s / 60) + 'H'
  59. else
  60. r := tf + 'm'
  61. r
  62.  
  63. buildLevelsLowOrHigh(tf, tft, v, ov, lows, showcur, showprev, showcrossed, bi) =>
  64. var line curLine = na
  65. var label curLabel = na
  66. var line prevLine = na
  67. var label prevLabel = na
  68. var bool prevSwept = false
  69. var int pt = na
  70. var float mv = na
  71. var curtxt = (lows ? 'LO' : 'HO') + tf
  72. var prevtxt = 'P' + tf + (lows ? 'L' : 'H')
  73.  
  74. if na(curLine)
  75. curLine := line.new(na, na, na, na, width = lineWidth, color = showcur ? lineColor : naColor, style = lineStyle)
  76. 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)
  77. if showcur and showPeriodLabels
  78. array.push(periodLines, curLine)
  79. array.push(periodLabels, curLabel)
  80. prevLine := line.new(na, na, na, na, width = lineWidth, color = showprev ? lineColor : naColor, style = lineStyle)
  81. 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)
  82. if showprev and showPeriodLabels
  83. array.push(periodLines, prevLine)
  84. array.push(periodLabels, prevLabel)
  85.  
  86.  
  87. if na(pt) or pt != tft
  88. pt := tft
  89. x1 = line.get_x1(curLine)
  90. x2 = line.get_x2(curLine)
  91. if bi - x1 >= mbp
  92. x1 := bi - mbp
  93. if bi - x2 >= mbp
  94. x2 := bi - mbp
  95. line.set_xy1(prevLine, x1, line.get_y1(curLine))
  96. line.set_xy2(prevLine, x2, line.get_y2(curLine))
  97. label.set_xy(prevLabel, x2, line.get_y2(curLine))
  98. label.set_style(prevLabel, centerLabels ? label.style_label_left : lows ? label.style_label_up : label.style_label_down)
  99. prevSwept := false
  100. mv := na
  101.  
  102. line.set_y1(curLine, ov)
  103. line.set_y2(curLine, ov)
  104. label.set_y(curLabel, ov)
  105.  
  106.  
  107. if na(mv) or (mv >= ov and lows) or (mv <= ov and not lows)
  108. mv := ov
  109. line.set_x1(curLine, bi)
  110.  
  111. line.set_y1(curLine, mv)
  112. line.set_xy2(curLine, bi, mv)
  113. label.set_xy(curLabel, bi, mv)
  114.  
  115. label.set_text(curLabel, curtxt)
  116. label.set_text(prevLabel, prevtxt)
  117.  
  118. if not prevSwept
  119. line.set_x2(prevLine, bi)
  120. label.set_x(prevLabel, bi)
  121. if (ov <= line.get_y1(prevLine) and lows) or (ov >= line.get_y1(prevLine) and not lows)
  122. x = (line.get_x1(prevLine) + line.get_x2(prevLine)) / 2
  123. if bi - x >= mbp
  124. x := bi - mbp
  125. if not showcrossed
  126. x := na
  127. line.set_x1(prevLine, x)
  128. line.set_x2(prevLine, x)
  129. label.set_x(prevLabel, x)
  130. label.set_style(prevLabel, lows ? label.style_label_up : label.style_label_down)
  131. prevSwept := true
  132.  
  133.  
  134. buildLevels(tf, showcur = true, showprev = true, showcrossed = true) =>
  135. [tft, h, l] = request.security(syminfo.tickerid, tf, [time, high, low], barmerge.gaps_off, barmerge.lookahead_on)
  136. if showcur or showprev
  137. buildLevelsLowOrHigh(tf, tft, l, low, true, showcur, showprev, showcrossed, bar_index)
  138. buildLevelsLowOrHigh(tf, tft, h, high, false, showcur, showprev, showcrossed, bar_index)
  139.  
  140. formatLevelLabels() =>
  141. if barstate.islast and showPeriodLabels
  142. i = 0
  143. indx = array.new<int>()
  144. while i < array.size(periodLines)
  145. array.push(indx, i)
  146. i += 1
  147. i := 0
  148. while i < array.size(indx)
  149. i_ind = array.get(indx, i)
  150. i_ln = array.get(periodLines, i_ind)
  151. x1 = line.get_x1(i_ln)
  152. x2 = line.get_x2(i_ln)
  153. i_v = line.get_y1(i_ln)
  154. j = i + 1
  155. while j < array.size(indx)
  156. j_ind = array.get(indx, j)
  157. j_ln = array.get(periodLines, j_ind)
  158. px1 = line.get_x1(j_ln)
  159. px2 = line.get_x2(j_ln)
  160. 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))
  161. i_lb = array.get(periodLabels, i_ind)
  162. j_lb = array.get(periodLabels, j_ind)
  163. label.set_text(i_lb, label.get_text(i_lb) + ',' + label.get_text(j_lb))
  164. label.set_text(j_lb, na)
  165. array.remove(indx, j)
  166. else
  167. j += 1
  168.  
  169. i += 1
  170.  
  171.  
  172. buildEqps(on, vs, lows) =>
  173. var eqps = array.new<line>()
  174. var labels = array.new<label>()
  175. if barstate.islast
  176. var last_handled = bar_index
  177. if array.size(eqps) == 0
  178. last_handled := bar_index - (mbp - 1) < 0 ? 0 : bar_index - (mbp - 1)
  179. pb = last_handled
  180. while pb <= bar_index
  181. last_bar = bar_index - pb
  182. pb += 1
  183. i = 0
  184. while i < array.size(eqps) and on
  185. l = array.get(eqps, i)
  186. if bar_index - line.get_x1(l) >= mbp
  187. line.delete(array.remove(eqps, i))
  188. label.delete(array.remove(labels, i))
  189. continue
  190. last_bi = bar_index - line.get_x1(l)
  191. last_v = vs[last_bi]
  192. 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)
  193. line.delete(array.remove(eqps, i))
  194. label.delete(array.remove(labels, i))
  195. else
  196. break
  197. off = last_bar + 2
  198. if on and not na(vs[off + 1])
  199. v = vs[off]
  200. 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])
  201. bi = bar_index[off]
  202. i := 0
  203. while i < array.size(eqps)
  204. l = array.get(eqps, i)
  205. last_bi = bar_index - line.get_x1(l)
  206. if last_bi > mbp
  207. line.delete(array.remove(eqps, i))
  208. label.delete(array.remove(labels, i))
  209. continue
  210. last_v1 = vs[last_bi]
  211.  
  212. last_body = lows ? math.min(open[last_bi], close[last_bi]) : math.max(open[last_bi], close[last_bi])
  213. update = (v >= last_v1 and v <= last_body and lows) or (v <= last_v1 and v >= last_body and not lows)
  214. if update and line.get_x1(l) != line.get_x2(l)
  215. last_bi := bar_index - line.get_x2(l)
  216. last_v2 = vs[last_bi]
  217. update := (v <= last_v2 and lows) or (v >= last_v2 and not lows)
  218. if update
  219. if slopedView
  220. line.set_xy2(l, bi, v)
  221. else
  222. line.set_xy2(l, bi, v)
  223. line.set_y1(l, v)
  224. txt = array.get(labels, i)
  225. label.set_textcolor(txt, eqpColor)
  226. label.set_xy(txt, (line.get_x1(l) + bi) / 2, (line.get_y1(l) + line.get_y2(l)) / 2)
  227. i += 1
  228.  
  229.  
  230. 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])
  231. int after = array.size(eqps)
  232. i := 0
  233. while i < array.size(eqps)
  234. l = array.get(eqps, i)
  235. last_bi = bar_index - line.get_x1(l)
  236. if last_bi > mbp
  237. line.delete(array.remove(eqps, i))
  238. label.delete(array.remove(labels, i))
  239. //removeEqpInd(inds, i)
  240. after := array.size(eqps)
  241. continue
  242. last_v1 = vs[last_bi]
  243. if (last_v1 > v and not lows) or (last_v1 < v and lows)
  244. after := i
  245. break
  246. i += 1
  247. array.insert(eqps, after, line.new(bar_index[off], v, bar_index[off], v, width = eqpWidth, color = eqpColor, style = eqpStyle))
  248. 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))
  249.  
  250.  
  251. last_handled := bar_index
  252. int eqpsLen = array.size(eqps)
  253. while eqpsLen > maxEQPs
  254. float minx1 = na
  255. int mini = na
  256. found = false
  257. i = 0
  258. eqpsLen := 0
  259. while i < array.size(eqps)
  260. l = array.get(eqps, i)
  261. if line.get_x1(l) != line.get_x2(l)
  262. eqpsLen += 1
  263. if (na(minx1) or minx1 > line.get_x1(l))
  264. minx1 := line.get_x1(l)
  265. mini := i
  266. i += 1
  267. if na(minx1)
  268. break
  269. line.delete(array.remove(eqps, mini))
  270. label.delete(array.remove(labels, mini))
  271. eqpsLen -= 1
  272. true
  273.  
  274. //}
  275. var int r0 = 0
  276. var int r1 = 0
  277. var int r2 = 0
  278. t = timenow
  279. t := timenow
  280. buildEqps(eqlEnabled and findByWicks, low, true)
  281. buildEqps(eqhEnabled and findByWicks, high, false)
  282. r2 += timenow - t
Advertisement
Add Comment
Please, Sign In to add comment