Advertisement
xmd79

Realtime TPO Profile [Kioseff Trading]

Jan 12th, 2023
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 38.08 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © KioseffTrading
  3.  
  4. //@version=5
  5. indicator("Realtime TPO Profile [Kioseff Trading]", shorttitle = "Realtime TPO Profile", overlay = true, max_lines_count = 500, max_boxes_count = 500, max_labels_count = 500, max_bars_back = 2000)
  6.  
  7. ti = input.string(defval = "Regular", title = "Calculation Type", options = ["Regular", "Fixed Range", "Fixed Interval"], group = "Calculation Type")
  8.  
  9. auto = input.string(defval = "Custom", options = ["Auto", "Custom"], title = "Auto Calculate Tick Levels? Custom?", inline = "1", group = "Current Session Configurations")
  10. tickzz = input.float(defval = 50 ,title = "Ticks", inline = "1", group = "Current Session Configurations")
  11. tickLevels = input.bool(false, title = "Show Tick Levels?", group = "Current Session Configurations")
  12. textSize = input.string(defval = "Small", options = ["Auto","Tiny", "Small", "Normal", "Large", "Huge"], group = "Current Session Configurations")
  13. showIb = input.bool(defval = false, title = "Show Initial Balance Range?", group = "Current Session Configurations")
  14.  
  15.  
  16. sess = input.string(defval = "D", title = "Recalculate After How Much Time?", tooltip = "from 1 to 1440 for minutes \nfrom 1D to 365D for days \nfrom 1W to 52W for weeks \nfrom 1M to 12M for months", group = 'If "Regular" is Selected')
  17.  
  18. st = input.time(defval = timestamp("19 Sep 2022 00:00 +0300"), title = "Fixed Range Start", group = 'If "Fixed Range" Is Selected')
  19.  
  20. timE = input.session(defval = "1300-1700", title = "Time Range", group = 'If "Fixed Interval" is Selected', tooltip = 'Select "Fixed Interval" For The "Calculation Type" Setting To Activate This Feature')
  21.  
  22.  
  23. showPre = input.bool(defval = true, title = "Show Previous Sessions TPO?", group = "Previous Session Settings")
  24. blackBox = input.bool(defval = false, title = "Segment Previous Sessions With Black Box?", group = "Previous Session Settings")
  25. rang = input.bool(defval = true, title = "Show Previous Sessions Ranges?", group = "Previous Session Settings")
  26.  
  27. distCalc = input.float(defval = 5.0, title = "% Distance to Hide Old SP Lines", tooltip = "If Price Exceeds The % Threshold Defined For This
  28. Setting (Price Distance From An Existing Sp Line - The Sp Line Will Dissapear Until Price Is Within Proximity Once More",
  29. group = "Previous Session Settings")
  30. distCalc2 = input.float(defval = 5.0, title = "% Distance to Hide Old VA Lines", tooltip = "If Price Exceeds The % Threshold Defined For This
  31. Setting (Price Distance From An Existing Va Line - The Va Line Will Dissapear Until Price Is Within Proximity Once More",
  32. group = "Previous Session Settings")
  33. distCalc3 = input.float(defval = 5.0, title = "% Distance to Hide Old POC Lines", tooltip = "If Price Exceeds The % Threshold Defined For This
  34. Setting (Price Distance From An Existing Poc Line - The Poc Line Will Dissapear Until Price Is Within Proximity Once More",
  35. group = "Previous Session Settings")
  36.  
  37.  
  38.  
  39.  
  40. spShw = input.bool(defval = true, title = "Show SP Lines and Labels", group = "Display Options", tooltip = "If Deselected, TPO Letters Will Only Turn Red When a SP Forms. No Other Identifying Features are Displayed")
  41. fr = input.bool(defval = true, title = "Show Fixed Range Label and Line?" , group ="Display Options")
  42. warn = input.bool(defval = true, title = "Show Warning", group = "Display Options")
  43. col = input.color(defval = color.gray, title = "Main Character Color (Gray Default)", group = "Colors")
  44. col1 = input.color(defval = color.red , title = "SP Character Color (Red Default)", group = "Colors")
  45. col2 = input.color(defval = color.yellow, title = "POC Character Color (Yellow Default)", group = "Colors")
  46. col3 = input.color(defval = color.blue, title = "IB Character Color (Blue Default)", group = "Colors")
  47. col4 = input.color(defval = color.lime, title = "Value Area Color (Lime Default)", group = "Colors")
  48. col5 = input.color(defval = color.white, title = "Value Area Letter Color (White Default)", group = "Colors")
  49. fnt = input.string(defval = "Default", title = "Font Type", options = ["Default", "Monospace"], group = "Colors")
  50.  
  51.  
  52. if fr == true and barstate.islast
  53. line.new(math.round(st), close, math.round(st), close + 0.001, extend = extend.both, color = color.white, width = 4, xloc = xloc.bar_time)
  54. if ti != "Fixed Range"
  55. var box frStart = box.new(math.round(st), high + ta.tr, math.round(st), low - ta.tr,
  56. bgcolor = color.new(color.white, 100), border_color = na, text_size = size.normal, text_color = color.white, text_wrap = text.wrap_none, text = "If Selected in Settings, \nFixed Range Begins Here", xloc = xloc.bar_time)
  57.  
  58. fixTime = time(timeframe.period, timE)
  59.  
  60. fonT = switch fnt
  61.  
  62. "Default" => font.family_default
  63. "Monospace" => font.family_monospace
  64.  
  65.  
  66. finTim = switch ti
  67.  
  68. "Regular" => timeframe.change(sess)
  69. "Fixed Range" => time[1] < st and time >= st
  70. "Fixed Interval" => na(fixTime[1]) and not na(fixTime)
  71.  
  72.  
  73. sz = switch textSize
  74.  
  75. "Auto" => size.auto
  76. "Tiny" => size.tiny
  77. "Small" => size.small
  78. "Normal" => size.normal
  79. "Large" => size.large
  80. "Huge" => size.huge
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87. var string [] str = array.from(
  88.  
  89. " A",
  90. " B",
  91. " C",
  92. " D",
  93. " E",
  94. " F",
  95. " G",
  96. " H",
  97. " I",
  98. " J",
  99. " K",
  100. " L",
  101. " M",
  102. " N",
  103. " O",
  104. " P",
  105. " Q",
  106. " R",
  107. " S",
  108. " T",
  109. " U",
  110. " V",
  111. " W",
  112. " X",
  113. " Y",
  114. " Z",
  115. " a",
  116. " b",
  117. " c",
  118. " d",
  119. " e",
  120. " f",
  121. " g",
  122. " h",
  123. " i",
  124. " j",
  125. " k",
  126. " l",
  127. " m",
  128. " n",
  129. " o",
  130. " p",
  131. " q",
  132. " r",
  133. " s",
  134. " t",
  135. " u",
  136. " v",
  137. " w",
  138. " x",
  139. " y",
  140. " z"
  141.  
  142. )
  143.  
  144.  
  145. if barstate.isfirst
  146.  
  147.  
  148. sX = ""
  149.  
  150. for i = 0 to 51
  151. sX := array.get(str, i) + "1 "
  152. array.push(str, sX)
  153. for i = 0 to 51
  154. sX := array.get(str, i) + "2 "
  155. array.push(str, sX)
  156. for i = 0 to 51
  157. sX := array.get(str, i) + "3 "
  158. array.push(str, sX)
  159. for i = 0 to 51
  160. sX := array.get(str, i) + "4 "
  161. array.push(str, sX)
  162. for i = 0 to 51
  163. sX := array.get(str, i) + "5 "
  164. array.push(str, sX)
  165. for i = 0 to 51
  166. sX := array.get(str, i) + "6 "
  167. array.push(str, sX)
  168. for i = 0 to 51
  169. sX := array.get(str, i) + "7 "
  170. array.push(str, sX)
  171. for i = 0 to 51
  172. sX := array.get(str, i) + "8 "
  173. array.push(str, sX)
  174. for i = 0 to 51
  175. sX := array.get(str, i) + "9 "
  176. array.push(str, sX)
  177. for i = 0 to 51
  178. sX := array.get(str, i) + "10 " // => Loops are run sequentially, not simultaneously, so string characters populate in order
  179. array.push(str, sX)
  180. for i = 0 to 51
  181. sX := array.get(str, i) + "11 "
  182. array.push(str, sX)
  183. for i = 0 to 51
  184. sX := array.get(str, i) + "12 "
  185. array.push(str, sX)
  186. for i = 0 to 51
  187. sX := array.get(str, i) + "13 "
  188. array.push(str, sX)
  189. for i = 0 to 51
  190. sX := array.get(str, i) + "14 "
  191. array.push(str, sX)
  192. for i = 0 to 51
  193. sX := array.get(str, i) + "15 "
  194. array.push(str, sX)
  195. for i = 0 to 51
  196. sX := array.get(str, i) + "16 "
  197. array.push(str, sX)
  198. for i = 0 to 51
  199. sX := array.get(str, i) + "17 "
  200. array.push(str, sX)
  201. for i = 0 to 51
  202. sX := array.get(str, i) + "18 "
  203. array.push(str, sX)
  204. for i = 0 to 51
  205. sX := array.get(str, i) + "19 "
  206. array.push(str, sX)
  207. for i = 0 to 51
  208. sX := array.get(str, i) + "20 "
  209. array.push(str, sX)
  210. for i = 0 to 51
  211. sX := array.get(str, i) + "21 "
  212. array.push(str, sX)
  213. for i = 0 to 51
  214. sX := array.get(str, i) + "22 "
  215. array.push(str, sX)
  216. for i = 0 to 51
  217. sX := array.get(str, i) + "23 "
  218. array.push(str, sX)
  219. for i = 0 to 51
  220. sX := array.get(str, i) + "24 "
  221. array.push(str, sX)
  222. for i = 0 to 51
  223. sX := array.get(str, i) + "25 "
  224. array.push(str, sX)
  225. for i = 0 to 51
  226. sX := array.get(str, i) + "26 "
  227. array.push(str, sX)
  228. for i = 0 to 51
  229. sX := array.get(str, i) + "27 "
  230. array.push(str, sX)
  231. for i = 0 to 51
  232. sX := array.get(str, i) + "28 "
  233. array.push(str, sX)
  234. for i = 0 to 51
  235. sX := array.get(str, i) + "29 "
  236. array.push(str, sX)
  237. for i = 0 to 51
  238. sX := array.get(str, i) + "30 "
  239. array.push(str, sX)
  240. for i = 0 to 51
  241. sX := array.get(str, i) + "31 "
  242. array.push(str, sX)
  243. for i = 0 to 51
  244. sX := array.get(str, i) + "32 "
  245. array.push(str, sX)
  246. for i = 0 to 51
  247. sX := array.get(str, i) + "33 "
  248. array.push(str, sX)
  249. for i = 0 to 51
  250. sX := array.get(str, i) + "34 "
  251. array.push(str, sX)
  252. for i = 0 to 51
  253. sX := array.get(str, i) + "35 "
  254. array.push(str, sX)
  255. for i = 0 to 51
  256. sX := array.get(str, i) + "36 "
  257. array.push(str, sX)
  258. for i = 0 to 51
  259. sX := array.get(str, i) + "37 "
  260. array.push(str, sX)
  261. for i = 0 to 51
  262. sX := array.get(str, i) + "38 "
  263. array.push(str, sX)
  264. for i = 0 to 51
  265. sX := array.get(str, i) + "39 "
  266. array.push(str, sX)
  267. for i = 0 to 51
  268. sX := array.get(str, i) + "39 "
  269. array.push(str, sX)
  270. for i = 0 to 51
  271. sX := array.get(str, i) + "40 "
  272. array.push(str, sX)
  273. for i = 0 to 51
  274. sX := array.get(str, i) + "41 "
  275. array.push(str, sX)
  276. for i = 0 to 51
  277. sX := array.get(str, i) + "42 "
  278. array.push(str, sX)
  279. for i = 0 to 51
  280. sX := array.get(str, i) + "43 "
  281. array.push(str, sX)
  282. for i = 0 to 51
  283. sX := array.get(str, i) + "44 "
  284. array.push(str, sX)
  285. for i = 0 to 51
  286. sX := array.get(str, i) + "45 "
  287. array.push(str, sX)
  288. for i = 0 to 51
  289. sX := array.get(str, i) + "46 "
  290. array.push(str, sX)
  291. for i = 0 to 51
  292. sX := array.get(str, i) + "47 "
  293. array.push(str, sX)
  294. for i = 0 to 51
  295. sX := array.get(str, i) + "48 "
  296. array.push(str, sX)
  297. for i = 0 to 51
  298. sX := array.get(str, i) + "49 "
  299. array.push(str, sX)
  300. for i = 0 to 51
  301. sX := array.get(str, i) + "50 "
  302. array.push(str, sX)
  303. for i = 0 to 51
  304. sX := array.get(str, i) + "51 "
  305. array.push(str, sX)
  306. for i = 0 to 51
  307. sX := array.get(str, i) + "52 "
  308. array.push(str, sX)
  309. for i = 0 to 51
  310. sX := array.get(str, i) + "53 "
  311. array.push(str, sX)
  312. for i = 0 to 51
  313. sX := array.get(str, i) + "54 "
  314. array.push(str, sX)
  315. for i = 0 to 51
  316. sX := array.get(str, i) + "55 "
  317. array.push(str, sX)
  318. for i = 0 to 51
  319. sX := array.get(str, i) + "56 "
  320. array.push(str, sX)
  321. for i = 0 to 51
  322. sX := array.get(str, i) + "57 "
  323. array.push(str, sX)
  324. for i = 0 to 51
  325. sX := array.get(str, i) + "58 "
  326. array.push(str, sX)
  327. for i = 0 to 51
  328. sX := array.get(str, i) + "59 "
  329. array.push(str, sX)
  330. for i = 0 to 51
  331. sX := array.get(str, i) + "60 "
  332. array.push(str, sX)
  333. for i = 0 to 51
  334. sX := array.get(str, i) + "61 "
  335. array.push(str, sX)
  336. for i = 0 to 51
  337. sX := array.get(str, i) + "62 "
  338. array.push(str, sX)
  339. for i = 0 to 51
  340. sX := array.get(str, i) + "63 "
  341. array.push(str, sX)
  342. for i = 0 to 51
  343. sX := array.get(str, i) + "64 "
  344. array.push(str, sX)
  345. for i = 0 to 51
  346. sX := array.get(str, i) + "65 "
  347. array.push(str, sX)
  348. for i = 0 to 51
  349. sX := array.get(str, i) + "66 "
  350. array.push(str, sX)
  351.  
  352.  
  353.  
  354.  
  355.  
  356. cond(y, x) =>
  357. not na(str.match(label.get_text(array.get(y, x)), "[1-9]"))
  358.  
  359.  
  360. cond2(y, x) =>
  361. not na(str.match(label.get_text(array.get(y, x)), "[10-66]"))
  362.  
  363.  
  364.  
  365.  
  366.  
  367. atr = ta.atr(14)
  368. var float tickz = 0.0
  369. ticks2 = array.new_float()
  370.  
  371. if ti == "Regular" or ti == "Fixed Interval"
  372. if last_bar_index - bar_index == 1601
  373. if syminfo.mintick >= 0.01
  374. tickz := auto == "Custom" ? tickzz :
  375. auto == "Auto" and timeframe.period == "1" ? atr * 50 :
  376. auto == "Auto" and timeframe.period == "5" ? atr * 40 :
  377. atr * 30
  378.  
  379. else
  380. tickz := auto == "Custom" ? tickzz : atr * 100000
  381. else
  382. if time < st
  383. if syminfo.mintick >= 0.01
  384. tickz := auto == "Custom" ? tickzz :
  385. auto == "Auto" and timeframe.period == "1" ? atr * 50 :
  386. auto == "Auto" and timeframe.period == "5" ? atr * 40 :
  387. atr * 30
  388. else
  389. tickz := auto == "Custom" ? tickzz : atr * 100000
  390.  
  391.  
  392. var line [] tpoLines = array.new_line()
  393. ticks = array.new_float()
  394. var float max = 0.0
  395. var float min = 10000000
  396. var float [] track = array.new_float()
  397. var label [] pocL = array.new_label()
  398. var float [] finChe = array.new_float()
  399. var line j = line.new(time, high, time, low, color = color.aqua, width = 4, xloc = xloc.bar_time)
  400. var int first = 0
  401. var int firstBar = 0
  402. max := math.max(high, max)
  403. min := math.min(low, min)
  404. var float ibF = 0.0
  405. var line [] ib = array.new_line()
  406. var label [] tpoLabels = array.new_label()
  407. var label [] SP = array.new_label()
  408. var line [] val = array.new_line()
  409. var label [] VA = array.new_label()
  410. var line ibBar = na
  411. var linefill fil = na
  412. var label op = label.new(time, open, xloc = xloc.bar_time, size = size.large, text_font_family = fonT, color = color.new(color.white, 100), text = "●", style = label.style_label_right, textcolor = color.blue)
  413. var int timRound = 0
  414. if session.isfirstbar_regular[4] and timRound == 0
  415. timRound := math.round(time - time[4])
  416.  
  417. timeCond = switch ti
  418.  
  419. "Regular" => last_bar_index - bar_index <= 1600
  420. "Fixed Range" => time >= st
  421. "Fixed Interval" => last_bar_index - bar_index <= 1600
  422.  
  423.  
  424. if timeCond
  425.  
  426.  
  427. if showIb == true and ti == "Regular"
  428. if time == ibF
  429.  
  430. array.push(ib, line.new(first, max, time, max, color = color.new(col3, 50), xloc = xloc.bar_time))
  431. array.push(ib, line.new(first, min, time, min, color = color.new(col3, 50), xloc = xloc.bar_time))
  432.  
  433. if array.size(ib) > 1
  434.  
  435. linefill.new(array.get(ib, 0), array.get(ib, 1), color.new(col3, 95))
  436.  
  437. if time == ibF and ti == "Regular"
  438. line.delete(ibBar)
  439. ibBar := line.new(first, max, first, min, color = color.blue, xloc =xloc.bar_time, width = 4)
  440.  
  441.  
  442. if finTim
  443.  
  444.  
  445. if array.size(val) > 0
  446. for i = 0 to array.size(val) - 1
  447. line.delete(array.shift(val))
  448.  
  449. if array.size(VA) > 0
  450. for i = 0 to array.size(VA) - 1
  451. label.delete(array.shift(VA))
  452.  
  453. if array.size(track) > 0
  454. array.clear(track)
  455.  
  456. if array.size(finChe) > 0
  457. array.clear(finChe)
  458.  
  459. if array.size(ib) > 0
  460. for i = 0 to array.size(ib) - 1
  461. line.delete(array.shift(ib))
  462.  
  463. if array.size(tpoLines) > 0
  464. for i = 0 to array.size(tpoLines) - 1
  465. line.delete(array.shift(tpoLines))
  466.  
  467. if array.size(tpoLabels) > 0
  468. for i = 0 to array.size(tpoLabels) - 1
  469. label.delete(array.shift(tpoLabels))
  470.  
  471. if array.size(SP) > 0
  472. for i = 0 to array.size(SP) - 1
  473. label.delete(array.shift(SP))
  474.  
  475. if array.size(pocL) > 0
  476. for i = 0 to array.size(pocL) - 1
  477. label.delete(array.shift(pocL))
  478.  
  479. max := high
  480. min := low
  481.  
  482. first := math.round(time)
  483. ibF := math.round(timestamp(year, month, dayofmonth, hour + 1, minute, second))
  484.  
  485. label.set_x(op, first), label.set_y(op, open)
  486.  
  487. firstBar := bar_index
  488. array.push(ticks, low)
  489. array.push(track, low)
  490. for i = 1 to 500
  491. if array.get(ticks, i - 1) + (tickz * syminfo.mintick) <= high
  492. array.push(ticks, array.get(ticks, i - 1) + (tickz * syminfo.mintick))
  493. else
  494. break
  495.  
  496.  
  497. for i = 0 to array.size(ticks) - 1
  498. array.push(tpoLines, line.new(bar_index, array.get(ticks, i) ,
  499. bar_index + 1, array.get(ticks, i),
  500. color = tickLevels == true ? color.new(color.lime, 75) : na, xloc = xloc.bar_index))
  501. array.push(tpoLabels, label.new(first, array.get(ticks, i) , text = " A", xloc = xloc.bar_time,
  502. color = color.new(col, 100), textcolor = col, text_font_family = fonT, style = label.style_label_left))
  503.  
  504.  
  505.  
  506.  
  507.  
  508.  
  509.  
  510.  
  511. if timeCond and not finTim and ti == "Regular"
  512. or barstate.islast and ti == "Fixed Range"
  513. or timeCond and not finTim and ti == "Fixed Interval" and fixTime
  514.  
  515. calc = max - min
  516. var label ibav = label.new(bar_index, close, color = na, style = label.style_label_left, text_font_family = fonT)
  517. if array.size(ib) > 1
  518. for i = 0 to array.size(ib) - 1
  519. line.set_x2(array.get(ib, i), time)
  520. label.set_y(ibav, math.avg(line.get_y1(array.get(ib, 0)), line.get_y1(array.get(ib, 1))))
  521. label.set_x(ibav, bar_index + 2)
  522. label.set_text(ibav, "Initial Balance Range")
  523. label.set_textcolor(ibav, col3)
  524. label.set_color(ibav,color.new(color.white, 100))
  525. else
  526. label.set_textcolor(ibav, na)
  527.  
  528. if array.size(VA) > 0
  529. for i = 0 to array.size(VA) - 1
  530. label.delete(array.shift(VA))
  531.  
  532.  
  533. if array.size(val) > 0
  534. for i = 0 to array.size(val) - 1
  535. line.delete(array.shift(val))
  536.  
  537.  
  538. if array.size(tpoLines) > 0
  539. for i = 0 to array.size(tpoLines) - 1
  540. line.delete(array.shift(tpoLines))
  541.  
  542. if array.size(tpoLabels) > 0
  543. for i = 0 to array.size(tpoLabels) - 1
  544. label.delete(array.shift(tpoLabels))
  545. if array.size(SP) > 0
  546. for i = 0 to array.size(SP) - 1
  547. label.delete(array.shift(SP))
  548.  
  549. if array.size(pocL) > 0
  550. for i = 0 to array.size(pocL) - 1
  551. label.delete(array.shift(pocL))
  552.  
  553. if array.size(finChe) > 0
  554. array.clear(finChe)
  555.  
  556. if array.size(track) > 0
  557. array.push(ticks, array.get(track, array.size(track) - 1))
  558. for i = 1 to 500
  559. if array.get(ticks, i - 1) + (tickz * syminfo.mintick) <= max
  560. array.push(ticks, array.get(ticks, i - 1) + (tickz * syminfo.mintick))
  561. else
  562. break
  563. array.push(ticks2, array.get(track, array.size(track) - 1))
  564. for i = 1 to 500
  565. if array.get(ticks2, i - 1) - (tickz * syminfo.mintick) >= min
  566. array.push(ticks2, array.get(ticks2, i - 1) - (tickz * syminfo.mintick))
  567. else
  568. break
  569. for i = array.size(ticks2) - 1 to 0
  570.  
  571. array.push(tpoLines, line.new( first, array.get(ticks2, i),
  572.  
  573. last_bar_time,
  574. array.get(ticks2, i),
  575. color = tickLevels == true ? color.new(color.lime, 75) : na,
  576. xloc = xloc.bar_time
  577.  
  578. ))
  579.  
  580. array.push(tpoLabels, label.new( first, array.get(ticks2, i),
  581.  
  582. color = color.new(color.white, 100),
  583. textcolor = col,
  584. size = sz,
  585. style = label.style_label_left,
  586. xloc = xloc.bar_time ,
  587. text_font_family = fonT
  588. ))
  589. for i = 0 to array.size(ticks) - 1
  590. array.push(tpoLines, line.new( first, array.get(ticks, i),
  591.  
  592. last_bar_time,
  593. array.get(ticks, i),
  594. color = tickLevels == true ? color.new(color.lime, 75) : na,
  595. xloc = xloc.bar_time
  596.  
  597. ))
  598.  
  599. array.push(tpoLabels, label.new( first, array.get(ticks, i),
  600.  
  601. color = color.new(color.white, 100),
  602. textcolor = col,
  603. size = sz,
  604. style = label.style_label_left,
  605. xloc = xloc.bar_time,
  606. text_font_family = fonT
  607. ))
  608.  
  609. if array.size(tpoLines) > 1 and bar_index - firstBar < array.size(str)
  610.  
  611. levels = array.new_float()
  612. che = array.new_float(array.size(tpoLines), 0)
  613. for i = bar_index - firstBar to 0
  614. for x = 0 to array.size(tpoLines) - 1
  615. if line.get_y1(array.get(tpoLines, x)) <= high[i] and line.get_y1(array.get(tpoLines, x)) >= low[i]
  616. label.set_text(array.get(tpoLabels, x),
  617. text = label.get_text(array.get(tpoLabels, x)) + array.get(str, math.abs(bar_index - firstBar - i)))
  618. array.set(che, x, array.get(che, x) + 1)
  619.  
  620.  
  621. len = 0.0
  622. for x = 0 to array.size(tpoLabels) - 1
  623. len := math.max(len, array.get(che, x))
  624.  
  625. lenTrack = 0
  626.  
  627. for x = 0 to array.size(tpoLabels) - 1
  628.  
  629. if array.get(che, x) == len
  630. label.set_textcolor(array.get(tpoLabels, x), col2)
  631. lenTrack := x
  632. if bar_index - firstBar >= 4
  633.  
  634. line.set_color(array.get(tpoLines, x), color.new(col2, 75))
  635. line.set_width(array.get(tpoLines, x), 2)
  636. array.push(finChe, line.get_y1(array.get(tpoLines, x)))
  637. if array.size(finChe) == 1
  638. array.push(pocL, label.new(first, line.get_y1(array.get(tpoLines, x)), xloc = xloc.bar_time,
  639. color = color.new(col, 100), textcolor = col2, style = label.style_label_right, text_font_family = fonT, text = "POC", size = sz))
  640.  
  641.  
  642. break
  643.  
  644.  
  645.  
  646.  
  647.  
  648.  
  649. sum = array.new_float()
  650. sum1 = array.new_float()
  651. lin = array.new_float()
  652. lin1 = array.new_float()
  653. cheX = array.new_float()
  654. cheX1 = array.new_float()
  655.  
  656. if lenTrack > 0
  657. for x = lenTrack - 1 to 0
  658. array.push(sum , array.size(sum) == 0 ? array.get(che, x) : array.get(sum, array.size(sum) - 1) + array.get(che, x))
  659. array.push(lin, label.get_y(array.get(tpoLabels, x)))
  660. array.push(cheX, array.get(che, x))
  661. for x = lenTrack to array.size(che) - 1
  662. array.push(sum1, array.size(sum1) == 0 ? array.get(che, x) : array.get(sum1, array.size(sum1) - 1) + array.get(che, x))
  663. array.push(lin1, label.get_y(array.get(tpoLabels, x)))
  664. array.push(cheX1, array.get(che, x))
  665.  
  666.  
  667. miN = math.min(array.size(sum), array.size(sum1))
  668.  
  669.  
  670. for n = 0 to miN - 1
  671. if array.get(sum, n) + array.get(sum1, n) >= array.sum(che) * .7
  672. array.push(val,line.new(first , array.get(lin, n), time,
  673. array.get(lin, n), xloc = xloc.bar_time, color = color.new(col4, 75)))
  674.  
  675. array.push(val,line.new(first, array.get(lin1, n), time,
  676. array.get(lin1, n), xloc = xloc.bar_time, color = color.new(col4, 75)))
  677.  
  678. array.push(VA, label.new(first, line.get_y1(array.get(val, 0)), text = line.get_y1(array.get(val, 0)) > line.get_y1(array.get(val, 1)) ? "VAH" : "VAL",
  679. textcolor = col4, size = sz, color = color.new(color.white, 100), style = label.style_label_right, text_font_family = fonT, xloc = xloc.bar_time))
  680.  
  681. array.push(VA, label.new(first, line.get_y1(array.get(val, 1)), text = line.get_y1(array.get(val, 0)) > line.get_y1(array.get(val, 1)) ? "VAL" : "VAH",
  682. textcolor = col4, size = sz, color = color.new(color.white, 100), style = label.style_label_right, text_font_family = fonT, xloc = xloc.bar_time))
  683.  
  684.  
  685. break
  686.  
  687. if array.size(val) < 2
  688.  
  689. stop = 0
  690.  
  691. if miN == array.size(sum1)
  692.  
  693.  
  694. for n = 0 to array.size(cheX1) - 1
  695. if array.get(cheX1, n) >= math.round(len * .7)
  696. stop := n
  697. for n = 0 to array.size(sum) - 1
  698.  
  699. if array.get(sum, n) + array.get(sum1, stop) >= array.sum(che) * .7
  700.  
  701. array.push(val,line.new(first, array.get(lin, n), time,
  702. array.get(lin, n), xloc = xloc.bar_time, color = color.new(col4, 75)))
  703.  
  704. array.push(val,line.new(first, array.get(lin1, stop), time,
  705. array.get(lin1, stop), xloc = xloc.bar_time, color = color.new(col4, 75)))
  706.  
  707. array.push(VA, label.new(first, line.get_y1(array.get(val, 0)), text = line.get_y1(array.get(val, 0)) > line.get_y1(array.get(val, 1)) ? "VAH" : "VAL",
  708. textcolor = col4, size = sz, color = color.new(color.white, 100), text_font_family = fonT, style = label.style_label_right, xloc = xloc.bar_time))
  709.  
  710. array.push(VA, label.new(first, line.get_y1(array.get(val, 1)), text = line.get_y1(array.get(val, 0)) > line.get_y1(array.get(val, 1)) ? "VAL" : "VAH",
  711. textcolor = col4, size = sz, color = color.new(color.white, 100), text_font_family = fonT, style = label.style_label_right, xloc = xloc.bar_time))
  712.  
  713.  
  714.  
  715. break
  716.  
  717. else
  718.  
  719. for n = 0 to array.size(cheX) - 1
  720. if array.get(cheX, n) >= math.round(len * .7)
  721. stop := n
  722. for n = 0 to array.size(sum1) - 1
  723.  
  724. if array.get(sum, stop) + array.get(sum1, n) >= array.sum(che) * .7
  725.  
  726. array.push(val,line.new(first, array.get(lin1, n), time,
  727. array.get(lin1, n), xloc = xloc.bar_time, color = color.new(col4, 75)))
  728.  
  729. array.push(val,line.new(first, array.get(lin, stop), time,
  730. array.get(lin, stop), xloc = xloc.bar_time, color = color.new(col4, 75)))
  731.  
  732. array.push(VA, label.new(first, line.get_y1(array.get(val, 0)), text = line.get_y1(array.get(val, 0)) > line.get_y1(array.get(val, 1)) ? "VAH" : "VAL",
  733. textcolor = col4, size = sz, color = color.new(color.white, 100), text_font_family = fonT, style = label.style_label_right, xloc = xloc.bar_time))
  734.  
  735. array.push(VA, label.new(first, line.get_y1(array.get(val, 1)), text = line.get_y1(array.get(val, 0)) > line.get_y1(array.get(val, 1)) ? "VAL" : "VAH",
  736. textcolor = col4, size = sz, color = color.new(color.white, 100), text_font_family = fonT, style = label.style_label_right, xloc = xloc.bar_time))
  737.  
  738.  
  739.  
  740. break
  741.  
  742. if array.size(val) == 2 and array.size(pocL) > 0 and array.size(tpoLabels) > 0
  743. fil := linefill.new(array.get(val, 0), array.get(val, 1), color = color.new(col4, 90))
  744.  
  745. for i = 0 to array.size(tpoLabels) - 1
  746. if line.get_y1(array.get(val, 0)) > line.get_y2(array.get(val, 1))
  747. if label.get_y(array.get(tpoLabels, i)) <= line.get_y1(array.get(val, 0))
  748. and label.get_y(array.get(tpoLabels, i)) >= line.get_y1(array.get(val, 1))
  749. and label.get_y(array.get(tpoLabels, i)) != label.get_y(array.get(pocL, 0))
  750. label.set_textcolor(array.get(tpoLabels, i), col5)
  751.  
  752. else if label.get_y(array.get(tpoLabels, i)) == label.get_y(array.get(pocL, 0))
  753. label.set_textcolor(array.get(tpoLabels, i), col2)
  754.  
  755.  
  756. else
  757.  
  758. if label.get_y(array.get(tpoLabels, i)) >= line.get_y1(array.get(val, 0) )
  759. and label.get_y(array.get(tpoLabels, i)) <= line.get_y1(array.get(val, 1))
  760. and label.get_y(array.get(tpoLabels, i)) != label.get_y(array.get(pocL, 0))
  761. label.set_textcolor(array.get(tpoLabels, i), col5)
  762.  
  763. else if label.get_y(array.get(tpoLabels, i)) == label.get_y(array.get(pocL, 0))
  764. label.set_textcolor(array.get(tpoLabels, i), col2)
  765.  
  766.  
  767. for x = 0 to array.size(tpoLabels) - 1
  768. if str.length(label.get_text(array.get(tpoLabels, x))) == 2
  769. or str.length(label.get_text(array.get(tpoLabels, x))) == 5 and cond2(tpoLabels, x) == true
  770. or str.length(label.get_text(array.get(tpoLabels, x))) == 4 and cond(tpoLabels, x) == true
  771. label.set_textcolor(array.get(tpoLabels, x), col1)
  772. if bar_index - firstBar >= 4 and spShw == true
  773. line.set_color(array.get(tpoLines, x), color.new(col1, 75))
  774. array.push(SP, label.new(time, line.get_y1(array.get(tpoLines, x)), xloc = xloc.bar_time, color = color.new(col, 100),
  775. style = label.style_label_left, text = "SP", textcolor = col1, text_font_family = fonT))
  776.  
  777. if array.size(VA) == 2 and array.size(pocL) > 0
  778. if label.get_y(array.get(VA, 0)) == label.get_y(array.get(pocL, 0))
  779. label.set_x(array.get(VA, 0), first - timRound)
  780. if label.get_y(array.get(VA, 1)) == label.get_y(array.get(pocL, 0))
  781. label.set_x(array.get(VA, 1), first - timRound)
  782. if ti == "Regular" or ti == "Fixed Range"
  783. line.set_x1(j, first)
  784. line.set_x2(j, first)
  785. line.set_y1(j, max)
  786. line.set_y2(j, min)
  787. else
  788. if fixTime
  789. line.set_x1(j, first)
  790. line.set_x2(j, first)
  791. line.set_y1(j, max)
  792. line.set_y2(j, min)
  793.  
  794.  
  795. var line [] SPCopy = array.new_line()
  796. var line [] valCopy = array.new_line()
  797. var label [] tpoLabelsCopy = array.new_label()
  798. var line [] pocCopy = array.new_line()
  799. var line [] jCopy = array.new_line()
  800. var line [] ibBarCopy = array.new_line()
  801. var box [] bBox = array.new_box()
  802.  
  803.  
  804. tCnd = hour == str.tonumber(str.substring(timE, str.pos(timE, "-") + 1, str.length(timE) - 2))
  805. and minute == str.tonumber(str.substring(timE, str.pos(timE, "-") + 3))
  806.  
  807. if session.islastbar and barstate.isconfirmed
  808. and timeCond and ti == "Regular" and array.size(tpoLabels) > 0
  809. and showPre == true
  810. or tCnd and barstate.isconfirmed and timeCond and ti == "Fixed Interval"
  811. and array.size(tpoLabels) > 0 and showPre == true
  812.  
  813. if blackBox == true
  814. array.push(bBox, box.new(first, max, time, min, xloc = xloc.bar_time, bgcolor = #000000, border_color = na))
  815. if rang == true
  816.  
  817. array.push(jCopy, line.copy(j))
  818. array.push(ibBarCopy, line.copy(ibBar))
  819. if array.size(val) > 0 and distCalc2 != 0
  820. for i = 0 to array.size(val) - 1
  821. array.push(valCopy, line.copy(array.get(val, i)))
  822.  
  823. if array.size(tpoLabels) > 0
  824. for i = 0 to array.size(tpoLabels) - 1
  825. array.push(tpoLabelsCopy, label.copy(array.get(tpoLabels, i)))
  826. if label.get_y(array.get(tpoLabels, i)) == label.get_y(array.get(pocL, 0))
  827. array.push(pocCopy, line.copy(array.get(tpoLines, i)))
  828.  
  829. if array.size(SP) > 0 and distCalc != 0
  830. for i = 0 to array.size(SP) - 1
  831. array.push(SPCopy, line.new(first, label.get_y(array.get(SP, i)), time, label.get_y(array.get(SP, i)), xloc = xloc.bar_time, color = color.new(col1, 80)))
  832.  
  833.  
  834. if array.size(SPCopy) > 0
  835. for i = 0 to array.size(SPCopy) - 1
  836. if line.get_y1(array.get(SPCopy, i)) <= high and line.get_y1(array.get(SPCopy, i)) >= low
  837. line.delete(array.get(SPCopy, i))
  838. else
  839. if math.abs((close / line.get_y1(array.get(SPCopy, i))- 1)* 100) <= distCalc
  840. line.set_x2(array.get(SPCopy, i), time)
  841. else if math.abs((close / line.get_y1(array.get(SPCopy, i)) - 1)* 100) >= distCalc
  842. line.set_x2(array.get(SPCopy, i), line.get_x1(array.get(SPCopy, i)))
  843.  
  844. if array.size(valCopy) > 0
  845. for i = 0 to array.size(valCopy) - 1
  846. if line.get_y1(array.get(valCopy, i)) <= high and line.get_y1(array.get(valCopy, i)) >= low
  847. line.delete(array.get(valCopy, i))
  848. else if math.abs((close / line.get_y1(array.get(valCopy, i))- 1)* 100) <= distCalc2
  849. line.set_x2(array.get(valCopy, i), time)
  850. else if math.abs((close / line.get_y1(array.get(valCopy, i)) - 1)* 100) >= distCalc2
  851. line.set_x2(array.get(valCopy, i), line.get_x1(array.get(valCopy, i)))
  852.  
  853. if array.size(pocCopy) > 0
  854. for i = 0 to array.size(pocCopy) - 1
  855. if line.get_y1(array.get(pocCopy, i)) <= high and line.get_y1(array.get(pocCopy, i)) >= low
  856. line.delete(array.get(pocCopy, i))
  857. else if math.abs((close / line.get_y1(array.get(pocCopy, i))- 1)* 100) <= distCalc3
  858. line.set_x2(array.get(pocCopy, i), time)
  859. else if math.abs((close / line.get_y1(array.get(pocCopy, i)) - 1)* 100) >= distCalc3
  860. line.set_x2(array.get(pocCopy, i), line.get_x1(array.get(pocCopy, i)))
  861.  
  862.  
  863. if array.size(tpoLabelsCopy) > 500
  864. for i = 0 to array.size(tpoLabelsCopy) - 500
  865. label.delete(array.shift(tpoLabelsCopy))
  866. if array.size(ibBarCopy) > 1
  867. line.delete(array.shift(ibBarCopy))
  868. line.delete(array.shift(jCopy))
  869. if array.size(bBox) > 1
  870. box.delete(array.shift(bBox))
  871.  
  872.  
  873.  
  874. if warn == true
  875. var table tab = table.new(position.top_right, 1, 1, frame_color = color.white, frame_width = 1)
  876. table.cell(tab, 0, 0, text_size = size.small,
  877. text = "If Letters Aren't Appearing: Decrease the 'Ticks' Setting. \nIf Letters are Cluttered: Increase the 'Ticks' Setting\nFor Your Changes to Take Effect: Change the 'Auto Calculate Tick Levels? Custom?' Setting to 'Custom'",
  878. text_color = color.white, bgcolor = color.new(col3, 75))
  879.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement