xmd79

gtt1

Nov 22nd, 2021
1,076
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 72.64 KB | None | 0 0
  1. //@version=5
  2. indicator('Gann medians', overlay=true, format=format.price, precision=12, max_bars_back=300)
  3.  
  4.  
  5. method1 = input.string('Median', options=['EMA', 'Median', 'SMA'])
  6. length1 = input(12)
  7. mult1 = input.int(1, minval=0, maxval=1)
  8.  
  9. method2 = input.string('Median', options=['EMA', 'Median', 'SMA'])
  10. length2 = input(27)
  11. mult2 = input.int(1, minval=0, maxval=1)
  12.  
  13. method3 = input.string('Median', options=['EMA', 'Median', 'SMA'])
  14. length3 = input(56)
  15. mult3 = input.int(1, minval=0, maxval=1)
  16. //----
  17. Avg(x, length, method) =>
  18. sma_1 = ta.sma(x, length)
  19. ema_1 = ta.ema(x, length)
  20. percentile_linear_interpolation_1 = ta.percentile_linear_interpolation(x, length, 50)
  21. method == 'SMA' ? sma_1 : method == 'EMA' ? ema_1 : percentile_linear_interpolation_1
  22. //----
  23. a1 = ta.highest(length1) - math.max(close, open)
  24. b1 = math.min(close, open) - ta.lowest(length1)
  25. c1 = math.max(close, open) + a1 * mult1
  26. d1 = math.min(close, open) - b1 * mult1
  27.  
  28. a2 = ta.highest(length2) - math.max(close, open)
  29. b2 = math.min(close, open) - ta.lowest(length2)
  30. c2 = math.max(close, open) + a2 * mult2
  31. d2 = math.min(close, open) - b2 * mult2
  32.  
  33. a3 = ta.highest(length3) - math.max(close, open)
  34. b3 = math.min(close, open) - ta.lowest(length3)
  35. c3 = math.max(close, open) + a3 * mult3
  36. d3 = math.min(close, open) - b3 * mult3
  37. //----
  38. e1 = Avg(c1, length1, method1)
  39. f1 = Avg(d1, length1, method1)
  40. g1 = 0
  41. cross_1 = ta.cross(close, f1)
  42. g1 := ta.cross(close, e1) ? 1 : cross_1 ? 0 : nz(g1[1])
  43.  
  44. e2 = Avg(c2, length2, method2)
  45. f2 = Avg(d2, length2, method2)
  46. g2 = 0
  47. cross_2 = ta.cross(close, f2)
  48. g2 := ta.cross(close, e2) ? 1 : cross_2 ? 0 : nz(g2[1])
  49.  
  50. e3 = Avg(c3, length3, method3)
  51. f3 = Avg(d3, length3, method3)
  52. g3 = 0
  53. cross_3 = ta.cross(close, f3)
  54. g3 := ta.cross(close, e3) ? 1 : cross_3 ? 0 : nz(g3[1])
  55. //---
  56. hilo1 = g1 * f1 + (1 - g1) * e1
  57. css1 = g1 == 1 ? color.green : color.red
  58. plot(hilo1, color=css1, style=plot.style_line, show_last=1, linewidth=1, trackprice=true, transp=0)
  59.  
  60. hilo2 = g2 * f2 + (1 - g2) * e2
  61. css2 = g2 == 1 ? color.green : color.red
  62. plot(hilo2, color=css2, style=plot.style_line, show_last=1, linewidth=1, trackprice=true, transp=0)
  63.  
  64. hilo3 = g3 * f3 + (1 - g3) * e3
  65. css3 = g3 == 1 ? color.green : color.red
  66. plot(hilo3, color=css3, style=plot.style_line, show_last=1, linewidth=1, trackprice=true, transp=0)
  67.  
  68.  
  69. //end of this part
  70.  
  71.  
  72.  
  73. upperMult = input(title='Upper Deviation', defval=2)
  74. lowerMult = input(title='Lower Deviation', defval=-2)
  75.  
  76. useUpperDev = input(title='Use Upper Deviation', defval=true)
  77. useLowerDev = input(title='Use Lower Deviation', defval=true)
  78. showPearson = input(title='Show Pearson\'s R', defval=true)
  79. extendLines = input(title='Extend Lines', defval=false)
  80.  
  81. len = input(title='Count', defval=100)
  82. src = input(title='Source', defval=close)
  83.  
  84. extend = extendLines ? extend.right : extend.none
  85.  
  86. calcSlope(src, len) =>
  87. if not barstate.islast or len <= 1
  88. [float(na), float(na), float(na)]
  89. else
  90. sumX = 0.0
  91. sumY = 0.0
  92. sumXSqr = 0.0
  93. sumXY = 0.0
  94. for i = 0 to len - 1 by 1
  95. val = src[i]
  96. per = i + 1.0
  97. sumX := sumX + per
  98. sumY := sumY + val
  99. sumXSqr := sumXSqr + per * per
  100. sumXY := sumXY + val * per
  101. sumXY
  102. slope = (len * sumXY - sumX * sumY) / (len * sumXSqr - sumX * sumX)
  103. average = sumY / len
  104. intercept = average - slope * sumX / len + slope
  105. [slope, average, intercept]
  106.  
  107. [s, aLR, i] = calcSlope(src, len)
  108.  
  109. startPrice = i + s * (len - 1)
  110. endPrice = i
  111. var line baseLineLR = na
  112.  
  113. if na(baseLineLR) and not na(startPrice)
  114. baseLineLR := line.new(bar_index - len + 1, startPrice, bar_index, endPrice, width=4, extend=extend, color=color.red)
  115. baseLineLR
  116. else
  117. line.set_xy1(baseLineLR, bar_index - len + 1, startPrice)
  118. line.set_xy2(baseLineLR, bar_index, endPrice)
  119. na
  120.  
  121. calcDev(src, len, slope, average, intercept) =>
  122. upDev = 0.0
  123. dnDev = 0.0
  124. stdDevAcc = 0.0
  125. dsxx = 0.0
  126. dsyy = 0.0
  127. dsxy = 0.0
  128.  
  129. periods = len - 1
  130.  
  131. daY = intercept + slope * periods / 2
  132. val = intercept
  133.  
  134. for i = 0 to periods by 1
  135. price = high[i] - val
  136. if price > upDev
  137. upDev := price
  138. upDev
  139.  
  140. price := val - low[i]
  141. if price > dnDev
  142. dnDev := price
  143. dnDev
  144.  
  145. price := src[i]
  146. dxt = price - average
  147. dyt = val - daY
  148.  
  149. price := price - val
  150. stdDevAcc := stdDevAcc + price * price
  151. dsxx := dsxx + dxt * dxt
  152. dsyy := dsyy + dyt * dyt
  153. dsxy := dsxy + dxt * dyt
  154. val := val + slope
  155. val
  156.  
  157. stdDev = math.sqrt(stdDevAcc / (periods == 0 ? 1 : periods))
  158. pearsonR = dsxx == 0 or dsyy == 0 ? 0 : dsxy / math.sqrt(dsxx * dsyy)
  159. [stdDev, pearsonR, upDev, dnDev]
  160.  
  161. [stdDev, pearsonR, upDev, dnDev] = calcDev(src, len, s, aLR, i)
  162.  
  163. upperStartPrice = startPrice + (useUpperDev ? upperMult * stdDev : upDev)
  164. upperEndPrice = endPrice + (useUpperDev ? upperMult * stdDev : upDev)
  165. var line upper = na
  166.  
  167. lowerStartPrice = startPrice + (useLowerDev ? lowerMult * stdDev : -dnDev)
  168. lowerEndPrice = endPrice + (useLowerDev ? lowerMult * stdDev : -dnDev)
  169. var line lower = na
  170.  
  171. if na(upper) and not na(upperStartPrice)
  172. upper := line.new(bar_index - len + 1, upperStartPrice, bar_index, upperEndPrice, width=4, extend=extend, color=#0000ff)
  173. upper
  174. else
  175. line.set_xy1(upper, bar_index - len + 1, upperStartPrice)
  176. line.set_xy2(upper, bar_index, upperEndPrice)
  177. na
  178.  
  179. if na(lower) and not na(lowerStartPrice)
  180. lower := line.new(bar_index - len + 1, lowerStartPrice, bar_index, lowerEndPrice, width=4, extend=extend, color=#0000ff)
  181. lower
  182. else
  183. line.set_xy1(lower, bar_index - len + 1, lowerStartPrice)
  184. line.set_xy2(lower, bar_index, lowerEndPrice)
  185. na
  186.  
  187. // Pearson's R
  188. var label r = na
  189. transparent = color.new(color.white, 100)
  190. label.delete(r[1])
  191. if showPearson and not na(pearsonR)
  192. r := label.new(bar_index - len + 1, lowerStartPrice, str.tostring(pearsonR, '#.################'), color=transparent, textcolor=#0000ff, size=size.normal, style=label.style_label_up)
  193. r
  194. //end of this part
  195.  
  196.  
  197. testStartYear = input(2019, 'Backtest Start Year')
  198. testStartMonth = input(10, 'Backtest Start Month')
  199. testStartDay = input(20, 'Backtest Start Day')
  200. testStartHour = input(0, 'Backtest Start Hour')
  201. testStartMin = input(0, 'Backtest Start Minute')
  202. testPeriodStart = timestamp(testStartYear, testStartMonth, testStartDay, testStartHour, testStartMin)
  203. testStopYear = input(2099, 'Backtest Stop Year')
  204. testStopMonth = input(1, 'Backtest Stop Month')
  205. testStopDay = input(30, 'Backtest Stop Day')
  206. testPeriodStop = timestamp(testStopYear, testStopMonth, testStopDay, 0, 0)
  207. testPeriod() =>
  208. time >= testPeriodStart and time <= testPeriodStop ? true : false
  209.  
  210.  
  211. lenH = input.int(title='Length High', defval=20, minval=1)
  212. lenL = input.int(title='Length Low', defval=20, minval=1)
  213.  
  214. fun(src, len, isHigh, _style, _yloc, _color) =>
  215. p = nz(src[len])
  216. isFound = true
  217. for i = 0 to len * 2 by 1
  218. if isHigh and src[i] > p
  219. isFound := false
  220. isFound
  221. if not isHigh and src[i] < p
  222. isFound := false
  223. isFound
  224. if isFound and testPeriod()
  225. label.new(bar_index[len], p, str.tostring(p), style=_style, yloc=_yloc, color=_color)
  226. line.new(bar_index[len], p, bar_index, p, extend=extend.right, color=_color)
  227.  
  228.  
  229.  
  230. fun(high, lenH, true, label.style_label_down, yloc.abovebar, color.red)
  231. fun(low, lenL, false, label.style_label_up, yloc.belowbar, color.green)
  232.  
  233. //end of this part
  234.  
  235.  
  236.  
  237. price = input(defval=ohlc4)
  238.  
  239. // Strategy vars setup here
  240. Depth = input(56, title='Depth') // Depth
  241. Deviation = input(5, title='Deviation') // Deviation
  242.  
  243. // main logic
  244. // ZigZag
  245. lastlow = 0.0
  246. lasthigh = 0.0
  247. lastlow := nz(lastlow[1])
  248. lasthigh := nz(lasthigh[1])
  249.  
  250. data(x) =>
  251. d = request.security(syminfo.tickerid, timeframe.period, x, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
  252. d
  253. getLow(x, y, z, a) =>
  254. lastlow = y
  255. v = data(x)
  256. m = v == lastlow or data(z) - v > a * syminfo.mintick
  257. if v != lastlow
  258. lastlow := v
  259. lastlow
  260. if m
  261. v := 0.0
  262. v
  263. [v, lastlow]
  264. getHigh(x, y, z, a) =>
  265. lasthigh = y
  266. v = data(x)
  267. m = v == lasthigh or v - data(z) > a * syminfo.mintick
  268. if v != lasthigh
  269. lasthigh := v
  270. lasthigh
  271. if m
  272. v := 0.0
  273. v
  274. [v, lasthigh]
  275.  
  276. [v, e] = getLow(ta.lowest(Depth), lastlow, low, Deviation)
  277. lastlow := e
  278. zBB = v != 0.0
  279. [v1, ee1] = getHigh(ta.highest(Depth), lasthigh, high, Deviation)
  280. lasthigh := ee1
  281. zSS = v1 != 0.0
  282.  
  283. zigzagDirection = -1
  284. zigzagHigh = 0
  285. zigzagLow = 0
  286. zigzagDirection := zBB ? 0 : zSS ? 1 : nz(zigzagDirection[1], -1)
  287. virtualLow = zigzagLow[1] + 1
  288. if not zBB or zBB and zigzagDirection == zigzagDirection[1] and low > low[virtualLow]
  289. zigzagLow := nz(zigzagLow[1]) + 1
  290. zigzagLow
  291.  
  292. virtualHigh = zigzagHigh[1] + 1
  293. if not zSS or zSS and zigzagDirection == zigzagDirection[1] and high < high[virtualHigh]
  294. zigzagHigh := nz(zigzagHigh[1]) + 1
  295. zigzagHigh
  296. a = bar_index - zigzagLow
  297. b = bar_index - zigzagHigh
  298. var color c = na
  299. c := fixnan(a < b[1] ? color.lime : a > b[1] ? color.red : na)
  300. //barcolor(color=color.lime)
  301. line zigzag = line.new(bar_index - zigzagLow, low[zigzagLow], bar_index - zigzagHigh, high[zigzagHigh], color=c, style=line.style_solid, width=4)
  302. if zigzagDirection == zigzagDirection[1]
  303. line.delete(zigzag[1])
  304.  
  305. l = label.new(bar_index - zigzagHigh, na)
  306. label.set_text(l, 'Sell')
  307. label.set_color(l, color.red)
  308. label.set_yloc(l, yloc.abovebar)
  309. label.set_style(l, label.style_label_down)
  310. if zigzagDirection == zigzagDirection[1]
  311. label.delete(l[1])
  312.  
  313.  
  314.  
  315. l_b = label.new(bar_index - zigzagLow, na)
  316. label.set_text(l_b, 'Buy')
  317. label.set_color(l_b, color.green)
  318. label.set_yloc(l_b, yloc.belowbar)
  319. label.set_style(l_b, label.style_label_up)
  320. if zigzagDirection == zigzagDirection[1]
  321. label.delete(l_b[1])
  322.  
  323.  
  324. zzPrevHigh = zigzagHigh[1]
  325. zzPrevLow = zigzagLow[1]
  326. if not na(zzPrevHigh[1])
  327. zzPrevHigh := zzPrevHigh[1] + 1
  328. zzPrevHigh
  329.  
  330. if not na(zzPrevLow[1])
  331. zzPrevLow := zzPrevLow[1] + 1
  332. zzPrevLow
  333.  
  334. if zigzagDirection != zigzagDirection[1]
  335. if zigzagDirection == 1
  336. zzPrevHigh := zigzagHigh[1] + 1
  337. zzPrevHigh
  338. if zigzagDirection == 0
  339. zzPrevLow := zigzagLow[1] + 1
  340. zzPrevLow
  341.  
  342. //end of this part
  343.  
  344. // RSI Settings for user
  345. rsiSource = input(title='RSI Source', defval=close)
  346. rsiLength = input(title='RSI Length', defval=7)
  347. rsiOverbought = input.int(title='RSI Overbought', defval=70, minval=50, maxval=100)
  348. rsiOvesold = input.int(title='RSI Oversold', defval=30, minval=1, maxval=50)
  349.  
  350. // RSI value based on inbuilt RSI
  351. rsiValue = ta.rsi(rsiSource, rsiLength)
  352.  
  353. // Get the current state
  354. isOverbought = rsiValue >= rsiOverbought
  355. isOversold = rsiValue <= rsiOvesold
  356.  
  357. // State of the last extreme 0 for initialization, 1 = overbought, 2 = oversold
  358. var laststate = 0
  359.  
  360. // Highest and Lowest prices since the last state change
  361. var hh = low
  362. var ll = high
  363.  
  364. // Labels
  365. var label labelll = na
  366. var label labelhh = na
  367.  
  368. // Swing lines
  369. var line line_up = na
  370. var line line_down = na
  371.  
  372.  
  373. // We go from overbought straight to oversold NEW DRAWINGS CREATED HERE
  374. if laststate == 1 and isOversold
  375. ll := low
  376. labelll := label.new(bar_index, low, style=label.style_label_up, color=color.green, size=size.tiny)
  377. labelhh_low = label.get_x(labelhh)
  378. labelhh_pos = label.get_y(labelhh)
  379. line_down := line.new(bar_index, high, labelhh_low, labelhh_pos, width=2)
  380. line_down
  381.  
  382. // We go from oversold straight to overbought NEW DRAWINGS CREATED HERE
  383. if laststate == 2 and isOverbought
  384. hh := high
  385. labelhh := label.new(bar_index, high, style=label.style_label_down, color=color.red, size=size.tiny)
  386. labelll_low = label.get_x(labelll)
  387. labelll_pos = label.get_y(labelll)
  388. line_up := line.new(bar_index, high, labelll_low, labelll_pos, width=2)
  389. line_up
  390.  
  391.  
  392. // If we are overbought
  393. if isOverbought
  394. if high >= hh
  395. hh := high
  396. label.set_x(labelhh, bar_index)
  397. label.set_y(labelhh, high)
  398. line.set_x1(line_up, bar_index)
  399. line.set_y1(line_up, high)
  400. laststate := 1
  401. laststate
  402.  
  403. // If we are oversold
  404. if isOversold
  405. if low <= ll
  406. ll := low
  407. label.set_x(labelll, bar_index)
  408. label.set_y(labelll, low)
  409. line.set_x1(line_down, bar_index)
  410. line.set_y1(line_down, low)
  411. laststate := 2
  412. laststate
  413.  
  414.  
  415. // If last state was overbought and we are overbought
  416. if laststate == 1 and isOverbought
  417. if hh <= high
  418. hh := high
  419. label.set_x(labelhh, bar_index)
  420. label.set_y(labelhh, high)
  421. line.set_x1(line_up, bar_index)
  422. line.set_y1(line_up, high)
  423.  
  424. //If we are oversold and the last state was oversold, move the drawings to the lowest price
  425. if laststate == 2 and isOversold
  426. if low <= ll
  427. ll := low
  428. label.set_x(labelll, bar_index)
  429. label.set_y(labelll, low)
  430. line.set_x1(line_down, bar_index)
  431. line.set_y1(line_down, low)
  432.  
  433.  
  434. // If last state was overbought
  435. if laststate == 1
  436. if hh <= high
  437. hh := high
  438. label.set_x(labelhh, bar_index)
  439. label.set_y(labelhh, high)
  440. line.set_x1(line_up, bar_index)
  441. line.set_y1(line_up, high)
  442.  
  443. // If last stare was oversold
  444. if laststate == 2
  445. if ll >= low
  446. ll := low
  447. label.set_x(labelll, bar_index)
  448. label.set_y(labelll, low)
  449. line.set_x1(line_down, bar_index)
  450. line.set_y1(line_down, low)
  451.  
  452. //end of this part
  453.  
  454.  
  455.  
  456.  
  457. //study("momentum zigzag", overlay = true)
  458. lengthZZZ = input(10, title='High/Low length')
  459. hZZZ = ta.highest(high, lengthZZZ * 2 + 1)
  460. lZZZ = ta.lowest(low, lengthZZZ * 2 + 1)
  461. f_isMin(len) =>
  462. lZZZ == low[len]
  463. f_isMax(len) =>
  464. hZZZ == high[len]
  465.  
  466. var dirUp = false
  467. var lastLow = high * 100
  468. var lastHigh = 0.0
  469. var timeLow = bar_index
  470. var timeHigh = bar_index
  471. var line li = na
  472. f_drawLine() =>
  473. _li_color = dirUp ? color.gray : color.gray
  474. line.new(timeHigh - lengthZZZ, lastHigh, timeLow - lengthZZZ, lastLow, xloc.bar_index, color=_li_color, width=1)
  475.  
  476. if dirUp
  477. if f_isMin(lengthZZZ) and low[lengthZZZ] < lastLow
  478. lastLow := low[lengthZZZ]
  479. timeLow := bar_index
  480. line.delete(li)
  481. li := f_drawLine()
  482. li
  483.  
  484. if f_isMax(lengthZZZ) and high[lengthZZZ] > lastLow
  485. lastHigh := high[lengthZZZ]
  486. timeHigh := bar_index
  487. dirUp := false
  488. li := f_drawLine()
  489. li
  490.  
  491. if not dirUp
  492. if f_isMax(lengthZZZ) and high[lengthZZZ] > lastHigh
  493. lastHigh := high[lengthZZZ]
  494. timeHigh := bar_index
  495. line.delete(li)
  496. li := f_drawLine()
  497. li
  498. if f_isMin(lengthZZZ) and low[lengthZZZ] < lastHigh
  499. lastLow := low[lengthZZZ]
  500. timeLow := bar_index
  501. dirUp := true
  502. li := f_drawLine()
  503. if f_isMax(lengthZZZ) and high[lengthZZZ] > lastLow
  504. lastHigh := high[lengthZZZ]
  505. timeHigh := bar_index
  506. dirUp := false
  507. li := f_drawLine()
  508. li
  509.  
  510. //end of this part
  511.  
  512.  
  513. use_alt_series = input(defval=false, title='Use alternative source?')
  514. alt_src = input(defval=close, title='Alternative source:')
  515. hSR = use_alt_series ? alt_src : high
  516. lSR = use_alt_series ? alt_src : low
  517.  
  518. window = input(defval=14, title='lookback window :')
  519. percent_of_range_for_trade_zone = input(defval=15.0, title='Percent of the range to use for trade zone') * 0.01
  520.  
  521. short_term_top = ta.valuewhen(hSR >= ta.highest(hSR, window), hSR, 0)
  522. short_term_bot = ta.valuewhen(lSR <= ta.lowest(lSR, window), lSR, 0)
  523.  
  524. short_term_resist = ta.change(short_term_top) != 0 ? na : short_term_top
  525. short_term_suport = ta.change(short_term_bot) != 0 ? na : short_term_bot
  526.  
  527. short_term_resist_plot = plot(series=short_term_resist, title='STR', color=color.new(color.fuchsia, 0), linewidth=2, style=plot.style_linebr)
  528. short_term_suport_plot = plot(series=short_term_suport, title='STS', color=color.new(color.aqua, 0), linewidth=2, style=plot.style_linebr)
  529.  
  530. fill(short_term_suport_plot, short_term_resist_plot, color=color.new(color.aqua, 95), title=' Trade Zone ')
  531.  
  532. // Calculate entry zone:
  533. float short_term_resist_trade_limit = na
  534. float short_term_suport_trade_limit = na
  535.  
  536. range_1 = fixnan(short_term_resist) - fixnan(short_term_suport)
  537.  
  538. if not na(short_term_resist)
  539. if not na(short_term_resist_trade_limit[1])
  540. short_term_resist_trade_limit := short_term_resist_trade_limit[1]
  541. short_term_resist_trade_limit
  542. else
  543. short_term_resist_trade_limit := short_term_resist - range_1 * percent_of_range_for_trade_zone
  544. short_term_resist_trade_limit
  545.  
  546. if not na(short_term_suport)
  547. if not na(short_term_suport_trade_limit[1])
  548. short_term_suport_trade_limit := short_term_suport_trade_limit[1]
  549. short_term_suport_trade_limit
  550. else
  551. short_term_suport_trade_limit := short_term_suport + range_1 * percent_of_range_for_trade_zone
  552. short_term_suport_trade_limit
  553.  
  554. short_term_resist_trade_limit_plot = plot(series=short_term_resist_trade_limit, title='', color=color.new(color.red, 0), linewidth=1, style=plot.style_linebr)
  555. short_term_suport_trade_limit_plot = plot(series=short_term_suport_trade_limit, title='', color=color.new(color.yellow, 0), linewidth=1, style=plot.style_linebr)
  556.  
  557. //end of this part
  558.  
  559. lookback = input(defval=20, title='# of Candles to Look Back')
  560. srcAA = 'Close'
  561.  
  562. pivothigh_1 = ta.pivothigh(high, lookback, lookback)
  563. pivothigh_2 = ta.pivothigh(high, lookback, lookback)
  564. pivot_high = srcAA == 'Close' ? pivothigh_1 : pivothigh_2
  565. pivotlow_1 = ta.pivotlow(low, lookback, lookback)
  566. pivotlow_2 = ta.pivotlow(low, lookback, lookback)
  567. pivot_low = srcAA == 'Close' ? pivotlow_1 : pivotlow_2
  568.  
  569. valuewhen_9 = ta.valuewhen(pivot_high, high[lookback], 0)
  570. valuewhen_10 = ta.valuewhen(pivot_high, high[lookback], 0)
  571. plot_high = srcAA == 'Close' ? valuewhen_9 : valuewhen_10
  572. valuewhen_11 = ta.valuewhen(pivot_low, low[lookback], 0)
  573. valuewhen_12 = ta.valuewhen(pivot_low, low[lookback], 0)
  574. plot_low = srcAA == 'Close' ? valuewhen_11 : valuewhen_12
  575.  
  576. resistance = plot(plot_high, style=plot.style_line, title='Resistance Line', color=color.new(color.orange, 0), show_last=1, linewidth=2, trackprice=true)
  577. support = plot(plot_low, style=plot.style_line, title='Support Line', color=color.new(color.orange, 0), show_last=1, linewidth=2, trackprice=true)
  578.  
  579.  
  580.  
  581. //end of this part
  582.  
  583.  
  584.  
  585. // - INPUTS
  586. ShowPivots = input(true, title='Show Pivot Points')
  587. ShowHHLL = input(true, title='Show HH,LL,LH,HL markers on Pivots Points')
  588. left = input.int(5, minval=1, title='Pivot Length Left Hand Side')
  589. right = input.int(5, minval=1, title='Pivot Length Right Hand Side')
  590. //
  591.  
  592. var barCounter = 0
  593. barCounter := barCounter + 1
  594. f_draw_infopanel(_x, _y, _line, _text) =>
  595. _rep_text = ''
  596. if barstate.islast
  597. for _l = 0 to _line by 1
  598. _rep_text := _rep_text + '\n'
  599. _rep_text
  600. _rep_text := _rep_text + _text
  601. var label _la = na
  602. //a = label.get_text(_la)
  603. label.delete(_la)
  604. _la := label.new(x=_x, y=_y, text=_rep_text, xloc=xloc.bar_time, yloc=yloc.price, color=color.black, style=label.style_label_up, textcolor=color.silver, size=size.small)
  605. _la
  606.  
  607. // Determine pivots
  608. pvtLenL = left
  609. pvtLenR = right
  610.  
  611. // Get High and Low Pivot Points
  612. pvthi_ = ta.pivothigh(high, pvtLenL, pvtLenR)
  613. pvtlo_ = ta.pivotlow(low, pvtLenL, pvtLenR)
  614.  
  615. // Force Pivot completion before plotting.
  616. pvthi = pvthi_
  617. pvtlo = pvtlo_
  618.  
  619. // ||-----------------------------------------------------------------------------------------------------||
  620. // ||--- Higher Highs, Lower Highs, Higher Lows, Lower Lows -------------------------------------------||
  621. valuewhen_1 = ta.valuewhen(pvthi, high[pvtLenR], 1)
  622. valuewhen_2 = ta.valuewhen(pvthi, high[pvtLenR], 0)
  623. higherhigh = na(pvthi) ? na : valuewhen_1 < valuewhen_2 ? pvthi : na
  624. valuewhen_3 = ta.valuewhen(pvthi, high[pvtLenR], 1)
  625. valuewhen_4 = ta.valuewhen(pvthi, high[pvtLenR], 0)
  626. lowerhigh = na(pvthi) ? na : valuewhen_3 > valuewhen_4 ? pvthi : na
  627. valuewhen_5 = ta.valuewhen(pvtlo, low[pvtLenR], 1)
  628. valuewhen_6 = ta.valuewhen(pvtlo, low[pvtLenR], 0)
  629. higherlow = na(pvtlo) ? na : valuewhen_5 < valuewhen_6 ? pvtlo : na
  630. valuewhen_7 = ta.valuewhen(pvtlo, low[pvtLenR], 1)
  631. valuewhen_8 = ta.valuewhen(pvtlo, low[pvtLenR], 0)
  632. lowerlow = na(pvtlo) ? na : valuewhen_7 > valuewhen_8 ? pvtlo : na
  633.  
  634.  
  635. // If selected Display the HH/LL above/below candle.
  636. plotshape(ShowHHLL ? higherhigh : na, title='HH', location=location.abovebar, color=color.new(color.green, 0), text='HH', offset=-pvtLenR)
  637. plotshape(ShowHHLL ? higherlow : na, title='HL', location=location.belowbar, color=color.new(color.green, 0), text='HL', offset=-pvtLenR)
  638. plotshape(ShowHHLL ? lowerhigh : na, title='LH', location=location.abovebar, color=color.new(color.red, 0), text='LH', offset=-pvtLenR)
  639. plotshape(ShowHHLL ? lowerlow : na, title='LL', location=location.belowbar, color=color.new(color.red, 0), text='LL', offset=-pvtLenR)
  640.  
  641.  
  642. useColors = input(title='Fill with colors?', defval=true)
  643. isess = session.regular
  644. t = ticker.new(syminfo.prefix, syminfo.ticker, session=isess)
  645. igaps = barmerge.gaps_off
  646. yesterdayHigh = request.security(t, 'D', high[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
  647. yesterdayClose = request.security(t, 'D', close[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
  648. yesterdayLow = request.security(t, 'D', low[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on)
  649.  
  650.  
  651. // Plot the other time frame's data
  652. aH = timeframe.isintraday ? yesterdayHigh : na
  653.  
  654. cL = timeframe.isintraday ? yesterdayLow : na
  655.  
  656. up5on = input(true, title='5 Minute Opening Range High')
  657. down5on = input(true, title='5 Minute Opening Range Low')
  658.  
  659. is_newbar(res) =>
  660. ta.change(time(res)) != 0
  661.  
  662. adopt(r, s) =>
  663. request.security(syminfo.ticker, r, s)
  664.  
  665. high_range = ta.valuewhen(is_newbar('D'), high, 0)
  666. low_range = ta.valuewhen(is_newbar('D'), low, 0)
  667.  
  668. high_rangeL = ta.valuewhen(is_newbar('D'), high, 0)
  669. low_rangeL = ta.valuewhen(is_newbar('D'), low, 0)
  670.  
  671. up5 = up5on ? adopt('5', high_rangeL) : na
  672. down5 = down5on ? adopt('5', low_rangeL) : na
  673.  
  674.  
  675. bColor = #000000
  676. rColor = #ff0a02
  677. sColor = #008f0e
  678. pColor = #0900ff
  679. mColor = color.maroon
  680.  
  681.  
  682. myWidthMainLevels = input.int(title='Line width for Main levels', defval=1, minval=1)
  683. myStyle = plot.style_circles
  684.  
  685.  
  686. //plot(aH, title="H", color=#008f0e, linewidth=myWidthMainLevels, style=myStyle)
  687. //plot(cL, title="L", color=#ff0a02, linewidth=myWidthMainLevels, style=myStyle)
  688.  
  689. //plot(up5, title="UP", color=#000000, linewidth=myWidthMainLevels, style=myStyle)
  690. //plot(down5, title="DOWN", color=#000000, linewidth=myWidthMainLevels, style=myStyle)
  691.  
  692. //end of this part
  693.  
  694. //----- User inputs ---------------------
  695. Lookback1 = input.int(title='Lookback Left', defval=200, minval=1)
  696. Lookback2 = input.int(title='Lookback Right', defval=0, minval=0)
  697. VertLR = input(title='Show Vertical Left/Right', defval=true)
  698. VertHL = input(title='Show Vertical Highest/Lowest', defval=true)
  699. Count = input(title='Show Counts', defval=true)
  700. FullCount = input(title='Count All Bars', defval=false)
  701. Fibs = input(title='Show Fib Retrace Lines', defval=false)
  702. FibsExtHigh = input(title='Show Fib Ext Highs', defval=false)
  703. FibsExtLow = input(title='Show Fib Ext Lows', defval=false)
  704.  
  705.  
  706. //----- Main ---------------------
  707. // Get left and right endpoints. Though user input says "left" and "right", they are interchangeable.
  708. // The larger number is left, smaller number right.
  709. leftHL = math.max(Lookback1, Lookback2)
  710. rightHL = math.min(Lookback1, Lookback2)
  711. // Total num bars. Must be > 0 for highest() and lowest() to work. Add 1 to left bar, if needed.
  712. leftHL := leftHL - rightHL == 0 ? leftHL + 1 : leftHL
  713. lengthHL = leftHL - rightHL
  714.  
  715. // Highest price, looking back between the left/right endpoints
  716. highBack = ta.highest(high[rightHL], lengthHL)
  717. // Get # of bars back from present bar (offset).
  718. // NOTE: highestbars() returns a negative integer. Thus, subtract the right endpoint to get
  719. // offset from present (right-edge) bar
  720. highOffset = ta.highestbars(high[rightHL], lengthHL) - rightHL
  721.  
  722. // Lowest price, looking back
  723. lowBack = ta.lowest(low[rightHL], lengthHL)
  724. lowOffset = ta.lowestbars(low[rightHL], lengthHL) - rightHL
  725.  
  726. // Create a series of timestamps per bar. Needed to determine which bars are at the right edge,
  727. // While "n" starts at zero (left-edge bar) and counts up to the right-edge bar, this timestamp
  728. // (or tick) series counts the other way: max value at the left-edge, counting down to zero
  729. // at the right-edge.
  730. // This tick series is only valid while the indicator loads because "timenow" is the timestamp
  731. // of loading and "time" is the timestamp of a bar. The difference between the two timestamps
  732. // shrinks to zero as the righ-edge bar is processed. After loading, "timenow" and "time" are
  733. // the same value. Thus, "tick" always equals zero as new bars appear. But, for this indicator
  734. // this is sufficient behavior...
  735. tick = math.round((timenow - time) / ta.change(time)) // Each bar is a tick (float) in the timeline
  736. // Make a boolean mask for bars between left and right endpoints
  737. mask = FullCount ? true : tick < left and tick >= rightHL ? true : false
  738. // Determine the value of n at the left endpoint, used for visual counts of bars in mask
  739. nOffset = float(na)
  740. nOffset := FullCount ? 0 : tick == leftHL ? bar_index : nz(nOffset[1])
  741.  
  742. // Note: It would be nice to count between the highest/lowest bars, instead of left/right bars,
  743. // but this isn't possible because highOffset and lowOffset are moving around as the
  744. // indicator loads. Thus, "mask" isn't accurate...
  745.  
  746. //---- Plotting ---------------------
  747. // Horizontal Lines: Highest, Lowest dynamic lines
  748. // Params trackprice and offset make the horizontal line dynamic, adjusting to new highs/lows
  749. plot(highBack, title='Highest', color=color.new(color.red, 0), linewidth=2, trackprice=true, offset=-9999)
  750. plot(lowBack, title='Lowest', color=color.new(color.green, 0), linewidth=2, trackprice=true, offset=-9999)
  751.  
  752. // Veritcal Lines
  753. // Use barstate to paint/re-paint vertical lines, as new bars come into the data set.
  754. // islast - True for right most bar in data set. Use this to paint vertical bar, then push it back
  755. // in time with the offset parameter.
  756. // isrealtime - False while indicator loads. True for the right most bar, after loading.
  757. // isconfirmed - False while bar is not closed. True when close price appears.
  758. // isrealtime and isconfirmed - While indicator loads, ignore isconfirmed. After loading, isconfirmed
  759. // turns off the vertical line, as the bar closes. The next (new) bar is painted. This keeps
  760. // the vertical bar moving forward, as new bars appear, erasing the old (previous) vertical bar.
  761. VertLRShow = VertLR ? barstate.isrealtime and barstate.isconfirmed ? false : barstate.islast ? true : false : false
  762. // Can't use plot() with histogram/column because histbase can't accept "series" values
  763. bgcolor(VertLRShow ? color.gray : na, title='Vertical Left', offset=-leftHL + 1, transp=60)
  764. bgcolor(VertLRShow ? color.gray : na, title='Vertical Right', offset=-rightHL, transp=60)
  765. // Show vertical highest/lowest lines?
  766. VertHLShow = VertHL ? barstate.isrealtime and barstate.isconfirmed ? false : barstate.islast ? true : false : false
  767. bgcolor(VertHLShow ? color.red : na, title='Vertical Highest', offset=highOffset, transp=60)
  768. bgcolor(VertHLShow ? color.green : na, title='Vertical Lowest', offset=lowOffset, transp=60)
  769.  
  770. // Fib levels extension and retracement
  771. priceRange = highBack - lowBack
  772. plot(FibsExtHigh ? lowBack + 3.618 * priceRange : na, title='3.618', color=color.new(color.lime, 0), linewidth=2, trackprice=true, offset=-9999)
  773. plot(FibsExtHigh ? lowBack + 2.618 * priceRange : na, title='2.618', color=color.new(color.lime, 0), linewidth=2, trackprice=true, offset=-9999)
  774. plot(FibsExtHigh ? lowBack + 1.618 * priceRange : na, title='1.618', color=color.new(color.lime, 0), linewidth=2, trackprice=true, offset=-9999)
  775. plot(FibsExtHigh ? lowBack + 1.1 * priceRange : na, color=color.new(#88888800, 0), trackprice=true, offset=-9999, editable=false) // invisible line to work around pine plot bug
  776. plot(Fibs ? lowBack + 1.1 * priceRange : na, color=color.new(#88888800, 0), trackprice=true, offset=-9999, editable=false) // invisible line to work around pine plot bug
  777. plot(Fibs ? lowBack + 0.786 * priceRange : na, title='0.786', color=color.new(color.aqua, 0), linewidth=1, trackprice=true, offset=-9999)
  778. plot(Fibs ? lowBack + 0.618 * priceRange : na, title='0.618', color=color.new(color.orange, 0), linewidth=2, trackprice=true, offset=-9999)
  779. plot(Fibs ? lowBack + 0.50 * priceRange : na, title='0.5', color=color.new(color.yellow, 0), linewidth=2, trackprice=true, offset=-9999)
  780. plot(Fibs ? lowBack + 0.382 * priceRange : na, title='0.382', color=color.new(color.orange, 0), linewidth=2, trackprice=true, offset=-9999)
  781. plot(Fibs ? lowBack + 0.236 * priceRange : na, title='0.236', color=color.new(color.aqua, 0), linewidth=1, trackprice=true, offset=-9999)
  782. plot(Fibs ? highBack - 1.1 * priceRange : na, color=color.new(#88888800, 0), trackprice=true, offset=-9999, editable=false) // invisible line to work around pine plot bug
  783. plot(FibsExtLow ? highBack - 1.1 * priceRange : na, color=color.new(#88888800, 0), trackprice=true, offset=-9999, editable=false) // invisible line to work around pine plot bug
  784. plot(FibsExtLow ? highBack - 1.618 * priceRange : na, title='1.618', color=color.new(color.fuchsia, 0), linewidth=2, trackprice=true, offset=-9999)
  785. plot(FibsExtLow ? highBack - 2.618 * priceRange : na, title='2.618', color=color.new(color.fuchsia, 0), linewidth=2, trackprice=true, offset=-9999)
  786. plot(FibsExtLow ? highBack - 3.618 * priceRange : na, title='3.618', color=color.new(color.fuchsia, 0), linewidth=2, trackprice=true, offset=-9999)
  787.  
  788. // Lookback bar count
  789. countMod = mask ? (bar_index - nOffset) % 10 : na
  790. countInt = mask ? math.floor((bar_index - nOffset) / 10) % 10 : na
  791. plotshape(Count and countMod != 0 ? true : na, style=shape.circle, text='-', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
  792. plotshape(Count and countMod == 0 and countInt == 0 ? true : na, style=shape.circle, text='0', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
  793. plotshape(Count and countMod == 0 and countInt == 1 ? true : na, style=shape.circle, text='1', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
  794. plotshape(Count and countMod == 0 and countInt == 2 ? true : na, style=shape.circle, text='2', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
  795. plotshape(Count and countMod == 0 and countInt == 3 ? true : na, style=shape.circle, text='3', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
  796. plotshape(Count and countMod == 0 and countInt == 4 ? true : na, style=shape.circle, text='4', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
  797. plotshape(Count and countMod == 0 and countInt == 5 ? true : na, style=shape.circle, text='5', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
  798. plotshape(Count and countMod == 0 and countInt == 6 ? true : na, style=shape.circle, text='6', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
  799. plotshape(Count and countMod == 0 and countInt == 7 ? true : na, style=shape.circle, text='7', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
  800. plotshape(Count and countMod == 0 and countInt == 8 ? true : na, style=shape.circle, text='8', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
  801. plotshape(Count and countMod == 0 and countInt == 9 ? true : na, style=shape.circle, text='9', textcolor=color.new(color.gray, 0), color=color.new(#88888800, 0), location=location.bottom, size=size.auto, editable=false)
  802.  
  803. //end of this part
  804.  
  805.  
  806.  
  807. //
  808. // @author LonesomeTheBlue
  809. //
  810. //study("Pivot High Low Points", overlay=true)
  811. lb = input(6, title='Left Bars')
  812. rb = input(6, title='Right Bars')
  813.  
  814. mb = lb + rb + 1
  815.  
  816. highestbars_1 = ta.highestbars(mb)
  817. iff_1 = highestbars_1 == -lb ? high[lb] : na
  818. plot(not na(high[mb]) ? iff_1 : na, style=plot.style_cross, linewidth=3, color=color.new(color.blue, 0), offset=-lb)
  819. lowestbars_1 = ta.lowestbars(mb)
  820. iff_2 = lowestbars_1 == -lb ? low[lb] : na
  821. plot(not na(low[mb]) ? iff_2 : na, style=plot.style_cross, linewidth=3, color=color.new(color.blue, 0), offset=-lb)
  822.  
  823. //end of this part
  824.  
  825.  
  826.  
  827. //end of this part
  828.  
  829.  
  830. //study("VJ - Killer BS", overlay=true)
  831. //======================================================================
  832. //Jurij
  833. h_left = input(title='h left', defval=10)
  834. h_right = input(title='h right', defval=10)
  835. show_ptz = input(title='Show PTZ', defval=true)
  836. show_channel = input(title='Show channel', defval=true)
  837. //barCount = nz(barCount[1]) + 1
  838. //check history and realtime PTZ
  839. h_left_low = ta.lowest(h_left)
  840. h_left_high = ta.highest(h_left)
  841. newlow = low <= h_left_low
  842. newhigh = high >= h_left_high
  843. //channel_high = plot(show_channel ? h_left_low : 0, color=silver)
  844. //channel_low = plot (show_channel ? h_left_high : 0, color=silver)
  845. central_bar_low = low[h_right + 1]
  846. central_bar_high = high[h_right + 1]
  847. full_zone_low = ta.lowest(h_left + h_right + 1)
  848. full_zone_high = ta.highest(h_left + h_right + 1)
  849. central_bar_is_highest = central_bar_high >= full_zone_high
  850. central_bar_is_lowest = central_bar_low <= full_zone_low
  851. plotchar(central_bar_is_highest ? -1 : 0, offset=-h_right - 1, color=color.new(color.red, 0), text='Sell')
  852. plotchar(central_bar_is_lowest ? 1 : 0, offset=-h_right - 1, location=location.belowbar, color=color.new(color.green, 0), text='Buy')
  853. //plot(close)
  854.  
  855. //end of this part
  856.  
  857. //study(title="Peaks&Valleys", shorttitle="P&V", overlay=true)
  858. width = input(9)
  859. p = 0
  860. vc = 0
  861. for i = 0 to width * 2 by 1
  862. p := p + (i == width ? 0 : high[i] < high[width] ? 1 : 0)
  863. v := vc + (i == width ? 0 : low[i] > low[width] ? 1 : 0)
  864. v
  865. plotshape(p == width * 2, offset=-width, style=shape.labeldown)
  866. plotshape(vc == width * 2, offset=-width, style=shape.labelup, location=location.belowbar)
  867.  
  868. //end of this part
  869.  
  870. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  871. // © LonesomeTheBlue
  872.  
  873. //study("Double Zig Zag with HHLL", overlay = true, max_bars_back = 500)
  874. prdx1 = input.int(defval=8, title='ZigZag Period 1', minval=2, maxval=20)
  875. prdx2 = input.int(defval=20, title='ZigZag Period 2', minval=2, maxval=50)
  876. showzz = input.string(defval='Show Both', title='Show Zig Zags', options=['Show Zig Zag 1', 'Show Zig Zag 2', 'Show Both', 'Show None'])
  877. showhhll = input.string(defval='Show Both', title='Show HHLL', options=['Show HHLL 1', 'Show HHLL 2', 'Show Both', 'Show None'])
  878. upcol1 = input(defval=color.lime, title='Zig Zag 1 Up Color')
  879. dncol1 = input(defval=color.red, title='Zig Zag 1 Down Color')
  880. upcol2 = input(defval=color.blue, title='Zig Zag 2 Up Color')
  881. dncol2 = input(defval=color.purple, title='Zig Zag 2 Down Color')
  882. txtcol = input(defval=color.black, title='Text Color')
  883. zz1style = input.string(defval='Dashed', title='Zig Zag 1 Line Style', options=['Dashed', 'Dotted'])
  884. zz1width = input.int(defval=2, title='Zig zag 1 Line Width', minval=1, maxval=4)
  885. zz2width = input.int(defval=3, title='Zig zag 2 Line Width', minval=1, maxval=6)
  886.  
  887. float ph1x = ta.highestbars(high, prdx1) == 0 ? high : na
  888. float pl1x = ta.lowestbars(low, prdx1) == 0 ? low : na
  889. float ph2x = ta.highestbars(high, prdx2) == 0 ? high : na
  890. float pl2x = ta.lowestbars(low, prdx2) == 0 ? low : na
  891.  
  892. var dir1 = 0
  893. var dir2 = 0
  894. iff_3 = pl1x and na(ph1x) ? -1 : dir1
  895. dir1 := ph1x and na(pl1x) ? 1 : iff_3
  896. iff_4 = pl2x and na(ph2x) ? -1 : dir2
  897. dir2 := ph2x and na(pl2x) ? 1 : iff_4
  898.  
  899. var max_array_sizex = 10 // [5, 2] matrix
  900. var zigzag1 = array.new_float(0)
  901. var zigzag2 = array.new_float(0)
  902.  
  903. add_to_zigzagx(pointer, value, bindex) =>
  904. array.unshift(pointer, bindex)
  905. array.unshift(pointer, value)
  906. if array.size(pointer) > max_array_sizex
  907. array.pop(pointer)
  908. array.pop(pointer)
  909.  
  910. update_zigzagx(pointer, value, bindex, dir) =>
  911. if array.size(pointer) == 0
  912. add_to_zigzagx(pointer, value, bindex)
  913. else
  914. if dir == 1 and value > array.get(pointer, 0) or dir == -1 and value < array.get(pointer, 0)
  915. array.set(pointer, 0, value)
  916. array.set(pointer, 1, bindex)
  917. 0.
  918.  
  919. dir1changed = ta.change(dir1)
  920. if ph1x or pl1x
  921. if dir1changed
  922. add_to_zigzagx(zigzag1, dir1 == 1 ? ph1x : pl1x, bar_index)
  923. else
  924. update_zigzagx(zigzag1, dir1 == 1 ? ph1x : pl1x, bar_index, dir1)
  925.  
  926. dir2changed = ta.change(dir2)
  927. if ph2x or pl2x
  928. if dir2changed
  929. add_to_zigzagx(zigzag2, dir2 == 1 ? ph2x : pl2x, bar_index)
  930. else
  931. update_zigzagx(zigzag2, dir2 == 1 ? ph2x : pl2x, bar_index, dir2)
  932.  
  933. if array.size(zigzag1) >= 6
  934. var line zzline1 = na
  935. var label zzlabel1 = na
  936. float val = array.get(zigzag1, 0)
  937. int point = math.round(array.get(zigzag1, 1))
  938. if ta.change(val) or ta.change(point)
  939. float val1 = array.get(zigzag1, 2)
  940. int point1 = math.round(array.get(zigzag1, 3))
  941. if ta.change(val1) == 0 and ta.change(point1) == 0
  942. line.delete(zzline1)
  943. label.delete(zzlabel1)
  944. if showzz == 'Show Zig Zag 1' or showzz == 'Show Both'
  945. zzline1 := line.new(x1=point, y1=val, x2=point1, y2=val1, color=dir1 == 1 ? upcol1 : dncol1, width=zz1width, style=zz1style == 'Dashed' ? line.style_dashed : line.style_dotted)
  946. zzline1
  947. if showhhll == 'Show HHLL 1' or showhhll == 'Show Both'
  948. hhlltxt = dir1 == 1 ? array.get(zigzag1, 0) > array.get(zigzag1, 4) ? 'HH' : 'LH' : array.get(zigzag1, 0) < array.get(zigzag1, 4) ? 'LL' : 'HL'
  949. labelcol = dir1 == 1 ? array.get(zigzag1, 0) > array.get(zigzag1, 4) ? upcol1 : dncol1 : array.get(zigzag1, 0) < array.get(zigzag1, 4) ? dncol1 : upcol1
  950. zzlabel1 := label.new(x=point, y=val, text=hhlltxt, color=labelcol, textcolor=txtcol, style=dir1 == 1 ? label.style_label_down : label.style_label_up)
  951. zzlabel1
  952.  
  953. if array.size(zigzag2) >= 6
  954. var line zzline2 = na
  955. var label zzlabel2 = na
  956. float val = array.get(zigzag2, 0)
  957. int point = math.round(array.get(zigzag2, 1))
  958. if ta.change(val) or ta.change(point)
  959. float val1 = array.get(zigzag2, 2)
  960. int point1 = math.round(array.get(zigzag2, 3))
  961. if ta.change(val1) == 0 and ta.change(point1) == 0
  962. line.delete(zzline2)
  963. label.delete(zzlabel2)
  964. if showzz == 'Show Zig Zag 2' or showzz == 'Show Both'
  965. zzline2 := line.new(x1=point, y1=val, x2=point1, y2=val1, color=dir2 == 1 ? upcol2 : dncol2, width=zz2width)
  966. zzline2
  967. if showhhll == 'Show HHLL 2' or showhhll == 'Show Both'
  968. hhlltxt = dir2 == 1 ? array.get(zigzag2, 0) > array.get(zigzag2, 4) ? 'HH' : 'LH' : array.get(zigzag2, 0) < array.get(zigzag2, 4) ? 'LL' : 'HL'
  969. labelcol = dir2 == 1 ? array.get(zigzag2, 0) > array.get(zigzag2, 4) ? upcol2 : dncol2 : array.get(zigzag2, 0) < array.get(zigzag2, 4) ? dncol2 : upcol2
  970. zzlabel2 := label.new(x=point, y=val, text=hhlltxt, color=labelcol, textcolor=txtcol, style=dir2 == 1 ? label.style_label_down : label.style_label_up)
  971. zzlabel2
  972.  
  973.  
  974. //end of this part
  975.  
  976. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  977. // © GokhanGoksin
  978.  
  979. //study("ENGUL",shorttitle="engulf",overlay=true)
  980. x = input(title='çizgi/sağ uzat', defval=5)
  981. z = input(title='kaynak/seç/üst çizgi', defval=open)
  982. y = input(title='kaynak/seç/alt çizgi', defval=close)
  983. //****************************************************
  984. en = close[1] < open[1] and close > open[1] and low[1] > low
  985. plotshape(en, style=shape.arrowup, location=location.belowbar)
  986. //****************************************************** enguluf destek
  987. if en
  988. li = line.new(time[1], y[1], time + x * (time - time[1]), y[1], xloc=xloc.bar_time, color=color.red, width=2)
  989. li
  990.  
  991. if en
  992. label.new(time + x * (time - time[1]), y[1], text='\n' + str.tostring(y[1]), xloc=xloc.bar_time, style=label.style_none, size=size.normal, textcolor=color.white, yloc=yloc.price)
  993. //********************************************************************** direnç
  994. if en
  995. line.new(time[1], z[1], time + x * (time - time[1]), z[1], xloc=xloc.bar_time, color=color.blue, width=2)
  996. if en
  997. l = label.new(time + x * (time - time[1]), z[1], text='\n' + str.tostring(z[1]), xloc=xloc.bar_time, style=label.style_none, size=size.normal, textcolor=color.white, yloc=yloc.price)
  998. l
  999.  
  1000.  
  1001. //end of this part
  1002.  
  1003. // © weeklystockcharts
  1004.  
  1005. // Candle Type w/ only 3-1 Pine Script
  1006.  
  1007. //study("Candle Type w/only 3-1", overlay=true, precision=0)
  1008.  
  1009. // check for 3-1 inside + up buy
  1010. buyx = high[3] < high[2] and low[3] > low[2] and high[1] < high[2] and low[1] > low[2] and high > high[1] and high[1] <= high[2] and low[1] >= low[2] and not(low < low[1])
  1011. plotchar(buyx, title='Inside + Up Buy Label', text='Up', location=location.belowbar, color=color.new(#4CAF50, 0))
  1012.  
  1013. // check for 3-1 inside + dn sell
  1014. sellx = high[3] < high[2] and low[3] > low[2] and high[1] < high[2] and low[1] > low[2] and low < low[1] and low[1] >= low[2] and high[1] <= high[2] and not(high > high[1])
  1015. plotchar(sellx, title='Inside + Up Buy Label', text='Down', location=location.abovebar, color=color.new(color.red, 0))
  1016. //end of this part
  1017.  
  1018.  
  1019.  
  1020. //study("The system no.1", shorttitle="System no.1", overlay=true)
  1021.  
  1022. _length = input(title='Length', defval=21)
  1023. _offset = input(title='Offset', defval=0)
  1024.  
  1025. _smooth = input.int(title='WMA Length', defval=8, minval=1)
  1026.  
  1027.  
  1028. _source = close
  1029.  
  1030. _lsma = ta.linreg(_source, _length, _offset)
  1031. _lsmaS = ta.wma(_lsma, _smooth)
  1032. _lsmaC = ta.cross(_lsma, _lsmaS) ? (_lsma + _lsmaS) * 0.5 : na
  1033. //iscross() => _lsmaC
  1034. plot(_lsma, color=color.new(color.white, 0), linewidth=2)
  1035. plot(_lsmaS, color=color.new(#2299CC, 0), linewidth=2)
  1036. plotshape(_lsmaC, color=color.new(color.green, 0), style=shape.xcross)
  1037.  
  1038. //barcolor(iscross() ? yellow : na)
  1039.  
  1040. //coppock
  1041.  
  1042. wmaLength = input(title='WMA Length', defval=10)
  1043. longRoCLength = input(title='Long RoC Length', defval=14)
  1044. shortRoCLength = input(title='Short RoC Length', defval=11)
  1045.  
  1046. _crossoverMA = input.int(title='Crossover WMA Lenth', defval=5, minval=1)
  1047. _histogramMultiplier = input.float(title='Histogram Multiplier', defval=2)
  1048.  
  1049. _sourcec = close
  1050.  
  1051. _curve = ta.wma(ta.roc(_sourcec, longRoCLength) + ta.roc(_sourcec, shortRoCLength), wmaLength)
  1052. _curveWMA = ta.wma(_curve, _crossoverMA)
  1053.  
  1054. _h = (_curve - _curveWMA) * _histogramMultiplier
  1055.  
  1056. _curveWMAx = ta.cross(_curve, _curveWMA) ? (_curve + _curveWMA) * 0.5 : na
  1057.  
  1058. //final decision
  1059. check(x, y) =>
  1060. ta.cross(_curve[x], _curveWMA[x]) and ta.cross(_lsma[y], _lsmaS[y])
  1061. check00 = check(0, 0)
  1062. check01 = check(0, 1)
  1063. check02 = check(0, 2)
  1064. check10 = check(1, 0)
  1065. //check11 = check(1,1)
  1066. //check12 = check(1,2)
  1067. check20 = check(2, 0)
  1068. //check21 = check(2,1)
  1069. check03 = check(0, 3)
  1070. //check13 = check(1,3)
  1071. //check23 = check(2,3)
  1072. check30 = check(3, 0)
  1073. //check22 = check(2,2)
  1074. checkcross = check00 ? true : check01 ? true : check02 ? true : check10 ? true : check30 ? true : check20 ? true : check03 ? true : na
  1075.  
  1076.  
  1077.  
  1078. //checking value
  1079. mathcall = (math.abs(ta.lowest(_curve, 50)) + math.abs(ta.highest(_curve, 50))) * 0.3
  1080. highalert = ta.highest(_curve, 50) - mathcall
  1081. lowalert = ta.lowest(_curve, 50) + mathcall
  1082.  
  1083. // sell position
  1084. sellcheck = _curveWMA > _curve ? true : false
  1085. sellcheck1 = _lsma < _lsmaS ? true : false
  1086. sellcheck2 = _curve > highalert
  1087.  
  1088. SELLSIGNAL = checkcross and sellcheck and sellcheck1 and sellcheck2
  1089. barcolor(SELLSIGNAL ? color.yellow : na)
  1090.  
  1091. // buy position
  1092. buycheck = _curveWMA < _curve ? true : false
  1093. buycheck1 = _lsma > _lsmaS ? true : false
  1094. buycheck2 = _curve < lowalert
  1095.  
  1096. BUYSIGNAL = checkcross and buycheck and buycheck1 and buycheck2
  1097. barcolor(BUYSIGNAL ? color.blue : na)
  1098.  
  1099. //end of this part
  1100.  
  1101. //
  1102. //@author BillionaireLau
  1103. //
  1104.  
  1105. //study("Key price levels", overlay=true)
  1106. lbc = input.int(15, title='Number of bars searching backward', minval=1)
  1107. rbc = input.int(15, title='Number of bars searching forward', minval=1)
  1108.  
  1109. showsupres = input(true, title='Show Support/Resistance')
  1110. changebarcol = input(true, title='Change Bar Color')
  1111. mbc = lbc + rbc + 1
  1112.  
  1113. highestbars_2 = ta.highestbars(high, mbc) // Pivot High
  1114. iff_5 = highestbars_2 == -lbc ? high[lbc] : na
  1115. phc = not na(high[mbc]) ? iff_5 : na
  1116. lowestbars_2 = ta.lowestbars(low, mbc) // Pivot Low
  1117. iff_6 = lowestbars_2 == -lbc ? low[lbc] : na
  1118. plc = not na(low[mbc]) ? iff_6 : na
  1119.  
  1120. hlc = int(na)
  1121. iff_7 = plc ? -1 : na // Trend direction
  1122. hlc := phc ? 1 : iff_7
  1123. zz = float(na)
  1124. iff_8 = plc ? plc : na // similar to zigzag but may have multiple highs/lows
  1125. zz := phc ? phc : iff_8
  1126. valuewhen_13 = ta.valuewhen(hlc, hlc, 1)
  1127. valuewhen_14 = ta.valuewhen(zz, zz, 1)
  1128. zz := plc and hlc == -1 and valuewhen_13 == -1 and plc > valuewhen_14 ? na : zz
  1129. valuewhen_15 = ta.valuewhen(hlc, hlc, 1)
  1130. valuewhen_16 = ta.valuewhen(zz, zz, 1)
  1131. zz := phc and hlc == 1 and valuewhen_15 == 1 and phc < valuewhen_16 ? na : zz
  1132.  
  1133. valuewhen_17 = ta.valuewhen(hlc, hlc, 1)
  1134. valuewhen_18 = ta.valuewhen(zz, zz, 1)
  1135. hlc := hlc == -1 and valuewhen_17 == 1 and zz > valuewhen_18 ? na : hlc
  1136. valuewhen_19 = ta.valuewhen(hlc, hlc, 1)
  1137. valuewhen_20 = ta.valuewhen(zz, zz, 1)
  1138. hlc := hlc == 1 and valuewhen_19 == -1 and zz < valuewhen_20 ? na : hlc
  1139. zz := na(hlc) ? na : zz
  1140.  
  1141. findprevious() => // finds previous three points (b, c, d, e)
  1142. ehl = hlc == 1 ? -1 : 1
  1143. loc1 = 0.0
  1144. loc2 = 0.0
  1145. loc3 = 0.0
  1146. loc4 = 0.0
  1147. xx = 0
  1148. for x = 1 to 1000 by 1
  1149. if hlc[x] == ehl and not na(zz[x])
  1150. loc1 := zz[x]
  1151. xx := x + 1
  1152. break
  1153. ehl := hlc
  1154. for x = xx to 1000 by 1
  1155. if hlc[x] == ehl and not na(zz[x])
  1156. loc2 := zz[x]
  1157. xx := x + 1
  1158. break
  1159. ehl := hlc == 1 ? -1 : 1
  1160. for x = xx to 1000 by 1
  1161. if hlc[x] == ehl and not na(zz[x])
  1162. loc3 := zz[x]
  1163. xx := x + 1
  1164. break
  1165. ehl := hlc
  1166. for x = xx to 1000 by 1
  1167. if hlc[x] == ehl and not na(zz[x])
  1168. loc4 := zz[x]
  1169. break
  1170. [loc1, loc2, loc3, loc4]
  1171.  
  1172. axx = float(na)
  1173. bxx = float(na)
  1174. cxx = float(na)
  1175. dxx = float(na)
  1176. exx = float(na)
  1177. if not na(hlc)
  1178. [loc1, loc2, loc3, loc4] = findprevious()
  1179. axx := zz
  1180. bxx := loc1
  1181. cxx := loc2
  1182. dxx := loc3
  1183. exx := loc4
  1184. exx
  1185.  
  1186. _hh = zz and axx > bxx and axx > cxx and cxx > bxx and cxx > dxx
  1187. _ll = zz and axx < bxx and axx < cxx and cxx < bxx and cxx < dxx
  1188. _hl = zz and (axx >= cxx and bxx > cxx and bxx > dxx and dxx > cxx and dxx > exx or axx < bxx and axx > cxx and bxx < dxx)
  1189. _lh = zz and (axx <= cxx and bxx < cxx and bxx < dxx and dxx < cxx and dxx < exx or axx > bxx and axx < cxx and bxx > dxx)
  1190.  
  1191.  
  1192. //Lows
  1193. if _ll
  1194. label.new(bar_index[lbc], na, str.tostring(low[lbc], '####.##'), color=color.lime, textcolor=color.lime, style=label.style_none, yloc=yloc.belowbar)
  1195. if _hl
  1196. label.new(bar_index[lbc], na, str.tostring(low[lbc], '####.##'), color=color.lime, textcolor=color.lime, style=label.style_none, yloc=yloc.belowbar)
  1197.  
  1198. //Highs
  1199. if _lh
  1200. label.new(bar_index[lbc], na, str.tostring(high[lbc], '####.##'), color=color.red, textcolor=color.red, style=label.style_none, yloc=yloc.abovebar)
  1201. if _hh
  1202. label.new(bar_index[lbc], na, str.tostring(high[lbc], '####.##'), color=color.red, textcolor=color.red, style=label.style_none, yloc=yloc.abovebar)
  1203.  
  1204.  
  1205.  
  1206.  
  1207.  
  1208.  
  1209. res = float(na)
  1210. sup = float(na)
  1211. res := _lh ? zz : res[1]
  1212. sup := _hl ? zz : sup[1]
  1213.  
  1214. trend = int(na)
  1215. iff_9 = close < sup ? -1 : nz(trend[1])
  1216. trend := close > res ? 1 : iff_9
  1217.  
  1218. res := trend == 1 and _hh or trend == -1 and _lh ? zz : res
  1219. sup := trend == 1 and _hl or trend == -1 and _ll ? zz : sup
  1220.  
  1221. //plot(showsupres ? res : na, title="Resistance", color=na(res) ? na : color.red, linewidth=2, style=plot.style_circles, offset=-lb)
  1222. //plot(showsupres ? sup : na, title="Support", color=na(sup) ? na : color.blue, linewidth=2, style=plot.style_circles, offset=-lb)
  1223.  
  1224.  
  1225. //end of this part
  1226.  
  1227. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  1228. // © ownsov
  1229.  
  1230. //study(title="OS HiLo Tracking", shorttitle="OS HiLo Tracking", overlay=true, precision=6)
  1231.  
  1232.  
  1233. // HiLo inputs
  1234. high_activate = input(title='Track Previous High', defval=true)
  1235. high_input = input(title='Days', defval=3)
  1236. low_activate = input(title='Track Previous Low', defval=true)
  1237. low_input = input(title='Days', defval=3)
  1238.  
  1239. // HiLo definitions
  1240. daily_hh = nz(ta.highest(high, high_input)[1])
  1241. daily_ll = nz(ta.lowest(low, low_input)[1])
  1242.  
  1243. // HH and LL crossovers
  1244. HHXO = ta.crossover(close, daily_hh)
  1245. LLXO = ta.crossover(daily_ll, close)
  1246.  
  1247. // alerts
  1248.  
  1249. i_HHXO = input(false, 'Alert Highest High crossovers')
  1250. i_LLXO = input(false, 'Alert Lowest Low crossovers')
  1251. i_repaint = input(true, 'Allow Repainting')
  1252.  
  1253. // alert entries only generate entries when allowed in inputs
  1254. enterHHXO = i_HHXO and HHXO and (i_repaint or barstate.isconfirmed)
  1255. enterLLXO = i_LLXO and LLXO and (i_repaint or barstate.isconfirmed)
  1256.  
  1257.  
  1258. // alert plots only when the compound condition is met
  1259. if enterHHXO
  1260. alert('Price crossing up last Highest High (HH is ' + str.tostring(daily_hh, '#.00)'))
  1261. else if enterLLXO
  1262. alert('Price crossing down last Lowest Low (LL is ' + str.tostring(daily_ll, '#.00)'))
  1263.  
  1264. //
  1265.  
  1266. // plot HiLo horizontal line
  1267. plot(high_activate ? daily_hh : na, title='Previous Highest High', trackprice=true, offset=-9999, color=color.new(color.blue, 0))
  1268. plot(low_activate ? daily_ll : na, title='Previous Lowest Low', trackprice=true, offset=-9999, color=color.new(color.blue, 0))
  1269.  
  1270.  
  1271. labeltime = time + time - time[13]
  1272.  
  1273. // previous daily high label
  1274. ldaily_hh = label.new(labeltime, daily_hh, 'H (' + str.tostring(high_input) + ') = ' + str.tostring(daily_hh, '#.##'), color=high_activate ? color.new(color.blue, 40) : na, textcolor=high_activate ? color.white : na, textalign=text.align_center, style=label.style_label_center, xloc=xloc.bar_time)
  1275. label.delete(ldaily_hh[1])
  1276.  
  1277. f_printhh(_texthh) =>
  1278. // Create label on the first bar.
  1279. var _labelhh = label.new(bar_index, na, _texthh, xloc.bar_index, yloc.price, color(na), label.style_none, color.gray, size.normal, text.align_left)
  1280. // On next bars, update the label's x and y position, and the text it displays.
  1281. label.set_xy(_labelhh, bar_index, ta.highest(10)[1])
  1282. label.set_text(_labelhh, _texthh)
  1283.  
  1284. // previous daily low label
  1285. ldaily_ll = label.new(labeltime, daily_ll, 'L (' + str.tostring(low_input) + ') = ' + str.tostring(daily_ll, '#.##'), color=low_activate ? color.new(color.blue, 40) : na, textcolor=low_activate ? color.white : na, textalign=text.align_center, style=label.style_label_center, xloc=xloc.bar_time)
  1286. label.delete(ldaily_ll[1])
  1287.  
  1288. f_printll(_textll) =>
  1289. // Create label on the first bar.
  1290. var _labelll = label.new(bar_index, na, _textll, xloc.bar_index, yloc.price, color(na), label.style_none, color.gray, size.normal, text.align_left)
  1291. // On next bars, update the label's x and y position, and the text it displays.
  1292. label.set_xy(_labelll, bar_index, ta.lowest(10)[1])
  1293. label.set_text(_labelll, _textll)
  1294.  
  1295. //end of this part
  1296.  
  1297.  
  1298. //@version=5
  1299. //indicator(title='Order Blocks', overlay=true, max_bars_back=1000)
  1300.  
  1301. // Input options
  1302. sensitivity = input.int(title='Sensitivity', defval=26, minval=5, maxval=100, group='BASIC SETTINGS')
  1303.  
  1304. bearishLLColour = input.color(title='Bearish OB Colour', defval=color.rgb(255, 0, 0, 80), group='STYLES')
  1305. bullishLLColour = input.color(title='Bullish OB Colour', defval=color.rgb(0, 255, 0, 80), group='STYLES')
  1306.  
  1307.  
  1308. // tracking for entries
  1309. var int lastDownIndex = 0
  1310. var float lastDown = 0
  1311. var float lastDownClose = 0
  1312. var float lastDownLow = 0
  1313. var float lastDownOpen = 0
  1314.  
  1315. var int lastUpIndex = 0
  1316. var float lastUp = 0
  1317. var float lastUpLow = 0
  1318. var float lastUpHigh = 0
  1319. var float lastUpClose = 0
  1320. var int longModeIndex = 0
  1321. var float lastUpOpen = 0
  1322.  
  1323. // structure
  1324. var int structureLowIndex = 0
  1325. float structureLow = 1000000
  1326.  
  1327. // drawings
  1328. var longBoxes = array.new_box()
  1329. var shortBoxes = array.new_box()
  1330.  
  1331.  
  1332. // load levels
  1333. var int lastLongIndex = 0
  1334. var int lastShortIndex = 0
  1335. var bool lastShortIndex_EL = 0
  1336.  
  1337. // stop run detection
  1338. var box last_bull = na
  1339. var box last_bear = na
  1340.  
  1341. var color barc = color.red
  1342. var color obarc = color.white
  1343. barc := color.red
  1344.  
  1345.  
  1346. // get the lowest point in the range
  1347. structureLow := ta.lowest(low, sensitivity)[1]
  1348.  
  1349. // bearish break of structure
  1350. if ta.crossunder(low, structureLow)
  1351. // add short bos
  1352. if high > lastUpHigh
  1353. lastUpHigh := high
  1354. lastUpHigh
  1355. if bar_index - lastUpIndex < 4000
  1356.  
  1357. // update structure high
  1358. for p = 1 to bar_index - lastUpIndex by 1
  1359. if high[p] > lastUpHigh
  1360. lastUpHigh := high[p]
  1361. lastUpHigh
  1362.  
  1363. last_bear := box.new(left=lastUpIndex, top=lastUpHigh, bottom=lastUpLow, right=lastUpIndex, bgcolor=lastShortIndex == lastUpIndex ? color.rgb(0, 0, 0, 100) : bearishLLColour, border_color=bearishLLColour, extend=extend.right)
  1364. array.push(shortBoxes, last_bear)
  1365.  
  1366.  
  1367.  
  1368. // bullish break of structure?
  1369. if array.size(shortBoxes) > 0
  1370. for i = array.size(shortBoxes) - 1 to 0 by 1
  1371. box = array.get(shortBoxes, i)
  1372. top = box.get_top(box)
  1373. bottom = box.get_bottom(box)
  1374. left = box.get_left(box)
  1375. if high > top and close > open and bar_index != lastLongIndex
  1376. // remove the short box
  1377. box.delete(box)
  1378. array.remove(shortBoxes, i)
  1379. // calculate LL bottom
  1380. LLBottom = low < lastDownLow ? low : lastDownLow
  1381. // ok to darw
  1382. if bar_index - lastDownIndex < 4000
  1383.  
  1384. // update structure low
  1385. for p = 1 to bar_index - lastDownIndex by 1
  1386. if low[p] < LLBottom
  1387. LLBottom := low[p]
  1388. LLBottom
  1389.  
  1390. //
  1391. last_bull := box.new(left=lastDownIndex, top=lastDown, bottom=LLBottom, right=lastDownIndex, bgcolor=lastLongIndex == lastDownIndex ? color.rgb(0, 0, 0, 100) : lastShortIndex_EL == true ? color.rgb(0, 255, 0, 80) : bullishLLColour, border_color=lastLongIndex == lastDownIndex ? color.rgb(0, 0, 0, 100) : bullishLLColour, extend=extend.right)
  1392. array.push(longBoxes, last_bull)
  1393.  
  1394. lastLongIndex := bar_index
  1395. lastLongIndex
  1396.  
  1397. // remove LL if close below
  1398. if array.size(longBoxes) > 0
  1399. for i = array.size(longBoxes) - 1 to 0 by 1
  1400. lbox = array.get(longBoxes, i)
  1401. bottom = box.get_bottom(lbox)
  1402. top = box.get_top(lbox)
  1403. if close < bottom
  1404. array.remove(longBoxes, i)
  1405. box.delete(lbox)
  1406.  
  1407. // record last up and down candles
  1408. if close < open
  1409. lastDown := high
  1410. lastDownClose := close
  1411. lastDownOpen := open
  1412. lastDownLow := low
  1413. lastDownIndex := bar_index
  1414. lastDownIndex
  1415.  
  1416. if close > open
  1417. lastUp := close
  1418. lastUpIndex := bar_index
  1419. lastUpOpen := open
  1420. lastUpLow := low
  1421. lastUpClose := close
  1422. lastUpHigh := high
  1423. lastUpHigh
  1424.  
  1425. //end of this part
  1426.  
  1427.  
  1428. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  1429. // © pmk07
  1430. //
  1431. // Acknowledgements/Reference:
  1432. //
  1433. // @rumpypumpydumpy - Higher Order Pivots
  1434. // https://www.tradingview.com/v/x2LlRvBe/
  1435. //
  1436. // @MarkMiddleton2020 - Order Blocks
  1437. // https://www.tradingview.com/v/GecN34Qq/
  1438. //
  1439. //@version=5
  1440.  
  1441. //indicator(title='Order Blocks', overlay=true)
  1442.  
  1443. bool pv2_sv = input.bool (true, title='Plot 2nd order pivots')
  1444. bool msb_sv = input.bool (true, title='Plot MSB lines')
  1445. bool box_sv = input.bool (true, title='Plot Orderblocks')
  1446. bool m_sv = input.bool (true, title='Plot Breakerblocks')
  1447. bool range_sv = input.bool (true, title='Plot Range')
  1448. bool range_eq_sv = input.bool (true, title='Plot Range 0.5 Line')
  1449. bool range_q_sv = input.bool (true, title='Plot Range 0.25 and 0.75 Lines')
  1450. bool log_sv = input.bool (true, title='Use Log Scale')
  1451. bool msb_a_sv = input.bool (true, title='Alert MSB')
  1452. bool ob_a_sv = input.bool (true, title='Alert Orderblock test')
  1453. bool bb_a_sv = input.bool (true, title='Alert Breakerblock test')
  1454. bool r_a_sv = input.bool (true, title='Alert New Range')
  1455. bool rt_a_sv = input.bool (true, title='Alert Range test')
  1456. color u_s = input.color (color.rgb(192, 192, 192, 80), title='Untested Supply Color')
  1457. color t_s = input.color (color.rgb(255, 0, 0, 80), title='Tested Supply Color')
  1458. color u_d = input.color (color.rgb(192, 192, 192, 80), title='Untested Demand Color')
  1459. color t_d = input.color (color.rgb(0, 255, 0, 80), title='Tested Demand Color')
  1460. color u_b = input.color (color.rgb(192, 192, 192, 80), title='Untested Breaker Color')
  1461. color t_b = input.color (color.new(color.blue, 80), title='Tested Breaker Color')
  1462.  
  1463. var float[] pvh1_price = array.new_float (30, na) // high
  1464. var int[] pvh1_time = array.new_int (30, na)
  1465. var float[] pvl1_price = array.new_float (30, na) // low
  1466. var int[] pvl1_time = array.new_int (30, na)
  1467. var float[] pvh2_price = array.new_float (10, na) // higher high
  1468. var int[] pvh2_time = array.new_int (10, na)
  1469. var float[] pvl2_price = array.new_float (10, na) // lower low
  1470. var int[] pvl2_time = array.new_int (10, na)
  1471. var float htcmrll_price = na // high that created most recent ll
  1472. var int htcmrll_time = na
  1473. var float ltcmrhh_price = na // low that created most recent hh
  1474. var int ltcmrhh_time = na
  1475. var box[] long_boxes = array.new_box() // orderblocks
  1476. var box[] short_boxes = array.new_box()
  1477. var box[] m_long_boxes = array.new_box() // breakerblocks
  1478. var box[] m_short_boxes = array.new_box()
  1479. var line[] bull_bos_lines = array.new_line() // MSB lines
  1480. var line[] bear_bos_lines = array.new_line()
  1481. var line[] range_h_lines = array.new_line() // Range lines
  1482. var line[] range_25_lines = array.new_line()
  1483. var line[] range_m_lines = array.new_line()
  1484. var line[] range_75_lines = array.new_line()
  1485. var line[] range_l_lines = array.new_line()
  1486. var label[] la_ph2 = array.new_label() // 2nd order pivots
  1487. var label[] la_pl2 = array.new_label()
  1488. var float temp_pv_0 = na
  1489. var float temp_pv_1 = na
  1490. var float temp_pv_2 = na
  1491. var int temp_time = na
  1492. var float last_range_h = na
  1493. var float last_range_l = na
  1494. var line range_m = na
  1495. var line range_25 = na
  1496. var line range_75 = na
  1497. var float box_top = na
  1498. var float box_bottom = na
  1499. var int h_a_time = 0
  1500. var int l_a_time = 0
  1501. var int mh_a_time = 0
  1502. var int ml_a_time = 0
  1503. var int rh_a_time = 0
  1504. var int rl_a_time = 0
  1505. bool pvh = high < high[1] and high[1] > high[2]
  1506. bool pvl = low > low[1] and low[1] < low[2]
  1507. int pv1_time = bar_index[1]
  1508. float pv1_high = high[1]
  1509. float pv1_low = low[1]
  1510. bool new_ph_2nd = false
  1511. bool new_pl_2nd = false
  1512. string alert = na
  1513.  
  1514. if barstate.isconfirmed
  1515. if pvh
  1516. array.pop(pvh1_price)
  1517. array.pop(pvh1_time)
  1518. array.unshift(pvh1_price, pv1_high)
  1519. array.unshift(pvh1_time, pv1_time)
  1520. if array.size(pvh1_price) > 2
  1521. temp_pv_0 := array.get(pvh1_price, 0)
  1522. temp_pv_1 := array.get(pvh1_price, 1)
  1523. temp_pv_2 := array.get(pvh1_price, 2)
  1524. if temp_pv_0 < temp_pv_1 and temp_pv_1 > temp_pv_2
  1525. array.pop(pvh2_price)
  1526. array.pop(pvh2_time)
  1527. array.unshift(pvh2_price, temp_pv_1)
  1528. array.unshift(pvh2_time, array.get(pvh1_time, 1))
  1529. new_ph_2nd := true
  1530. if temp_pv_1 > array.get(pvh2_price, 1)
  1531. for i = 0 to array.size(pvl2_time) - 1 by 1
  1532. temp_ltcmrhh_time = array.get(pvl2_time, i)
  1533. if temp_ltcmrhh_time < array.get(pvh2_time, 0)
  1534. ltcmrhh_price := array.get(pvl2_price, i)
  1535. ltcmrhh_time := temp_ltcmrhh_time
  1536. break
  1537. if temp_pv_0 < ltcmrhh_price
  1538. if msb_sv
  1539. array.push(bear_bos_lines, line.new(x1=ltcmrhh_time, y1=ltcmrhh_price, x2=bar_index, y2=ltcmrhh_price, color=color.green, width=2))
  1540. box_top := array.get(pvh2_price, 0)
  1541. box_bottom := math.max(low[bar_index - array.get(pvh2_time, 0)], low[bar_index - array.get(pvh2_time, 0) + 1])
  1542. array.push(short_boxes, box.new(left=array.get(pvh2_time, 0), top=box_top, right=bar_index, bottom=box_bottom, bgcolor= box_sv ? u_s : na , border_color=na, extend=extend.right))
  1543. if msb_a_sv
  1544. alert := alert + 'Bearish MSB @ ' + str.tostring(ltcmrhh_price) + '\n' + 'New Supply Zone : '+ str.tostring(box_top) + ' - ' + str.tostring(box_bottom) + '\n'
  1545. ltcmrhh_price := na
  1546. if pvl
  1547. array.pop(pvl1_price)
  1548. array.pop(pvl1_time)
  1549. array.unshift(pvl1_price, pv1_low)
  1550. array.unshift(pvl1_time, pv1_time)
  1551. if array.size(pvl1_price) > 2
  1552. temp_pv_0 := array.get(pvl1_price, 0)
  1553. temp_pv_1 := array.get(pvl1_price, 1)
  1554. temp_pv_2 := array.get(pvl1_price, 2)
  1555. if temp_pv_0 > temp_pv_1 and temp_pv_1 < temp_pv_2
  1556. array.pop(pvl2_price)
  1557. array.pop(pvl2_time)
  1558. array.unshift(pvl2_price, temp_pv_1)
  1559. array.unshift(pvl2_time, array.get(pvl1_time, 1))
  1560. new_pl_2nd := true
  1561. if temp_pv_1 < array.get(pvl2_price, 1)
  1562. for i = 0 to array.size(pvh2_time) - 1 by 1
  1563. temp_htcmrll_time = array.get(pvh2_time, i)
  1564. if temp_htcmrll_time < array.get(pvl2_time, 0)
  1565. htcmrll_price := array.get(pvh2_price, i)
  1566. htcmrll_time := temp_htcmrll_time
  1567. break
  1568. if temp_pv_0 > htcmrll_price
  1569. if msb_sv
  1570. array.push(bull_bos_lines, line.new(x1=htcmrll_time, y1=htcmrll_price, x2=bar_index, y2=htcmrll_price, color=color.red, width=2))
  1571. box_top := math.min(high[bar_index - array.get(pvl2_time, 0)], high[bar_index - array.get(pvl2_time, 0) + 1])
  1572. box_bottom := array.get(pvl2_price, 0)
  1573. array.push(long_boxes, box.new(left=array.get(pvl2_time, 0), top=box_top, right=bar_index, bottom=box_bottom, bgcolor= box_sv ? u_d : na, border_color=na, extend=extend.right))
  1574. if msb_a_sv
  1575. alert := alert + 'Bullish MSB @ ' + str.tostring(htcmrll_price) + '\n' + 'New Demand Zone : '+ str.tostring(box_bottom) + ' - ' + str.tostring(box_top) + '\n'
  1576. htcmrll_price := na
  1577. if array.size(short_boxes) > 0
  1578. for i = array.size(short_boxes) - 1 to 0 by 1
  1579. tbox = array.get(short_boxes, i)
  1580. top = box.get_top(tbox)
  1581. bottom = box.get_bottom(tbox)
  1582. ago = box.get_left(tbox)
  1583. if array.get(pvh1_price, 0) > bottom
  1584. if box_sv
  1585. box.set_bgcolor(tbox, t_s)
  1586. if ob_a_sv and close < bottom
  1587. if array.get(pvh1_time, 0) != h_a_time
  1588. h_a_time := array.get(pvh1_time, 0)
  1589. alert := alert + 'Supply Zone Test @ ' + str.tostring(array.get(pvh1_price, 0)) + ' (age = ' + str.tostring(bar_index-ago) + ' bars) \n'
  1590. if array.get(pvl1_price, 0) > top
  1591. if m_sv
  1592. box.set_bgcolor(tbox, u_b)
  1593. array.push(m_long_boxes, tbox)
  1594. else
  1595. box.delete(tbox)
  1596. array.remove(short_boxes, i)
  1597. if msb_sv
  1598. line.delete(array.get(bear_bos_lines, i))
  1599. array.remove(bear_bos_lines, i)
  1600. if array.size(long_boxes) > 0
  1601. for i = array.size(long_boxes) - 1 to 0 by 1
  1602. lbox = array.get(long_boxes, i)
  1603. top = box.get_top(lbox)
  1604. bottom = box.get_bottom(lbox)
  1605. ago = box.get_left(lbox)
  1606. if array.get(pvl1_price, 0) < top
  1607. if box_sv
  1608. box.set_bgcolor(lbox, t_d)
  1609. if ob_a_sv and close > top
  1610. if array.get(pvl1_time, 0) != l_a_time
  1611. l_a_time := array.get(pvl1_time, 0)
  1612. alert := alert + 'Demand Zone Test @ ' + str.tostring(array.get(pvl1_price, 0)) + ' (age = ' + str.tostring(bar_index-ago) + ' bars) \n'
  1613. if array.get(pvh1_price, 0) < bottom
  1614. if m_sv
  1615. box.set_bgcolor(lbox, u_b)
  1616. array.push(m_short_boxes, lbox)
  1617. else
  1618. box.delete(lbox)
  1619. array.remove(long_boxes, i)
  1620. if msb_sv
  1621. line.delete(array.get(bull_bos_lines, i))
  1622. array.remove(bull_bos_lines, i)
  1623. if array.size(m_short_boxes) > 0
  1624. for i = array.size(m_short_boxes) - 1 to 0 by 1
  1625. tbox = array.get(m_short_boxes, i)
  1626. top = box.get_top(tbox)
  1627. bottom = box.get_bottom(tbox)
  1628. ago = box.get_left(tbox)
  1629. if array.get(pvh1_price, 0) > bottom
  1630. box.set_bgcolor(tbox, t_b)
  1631. if bb_a_sv and close < bottom
  1632. if array.get(pvh1_time, 0) != mh_a_time
  1633. mh_a_time := array.get(pvh1_time, 0)
  1634. alert := alert + 'Breakerblock Test Up @ ' + str.tostring(array.get(pvh1_price, 0)) + ' (age = ' + str.tostring(bar_index-ago) + ' bars) \n'
  1635. if array.get(pvl1_price, 0) > top
  1636. box.delete(tbox)
  1637. array.remove(m_short_boxes, i)
  1638. if array.size(m_long_boxes) > 0
  1639. for i = array.size(m_long_boxes) - 1 to 0 by 1
  1640. lbox = array.get(m_long_boxes, i)
  1641. top = box.get_top(lbox)
  1642. bottom = box.get_bottom(lbox)
  1643. ago = box.get_left(lbox)
  1644. if array.get(pvl1_price, 0) < top
  1645. box.set_bgcolor(lbox, t_b)
  1646. if bb_a_sv and close > top
  1647. if array.get(pvl1_time, 0) != ml_a_time
  1648. ml_a_time := array.get(pvl1_time, 0)
  1649. alert := alert + 'Breakerblock Test Down @ ' + str.tostring(array.get(pvl1_price, 0)) + ' (age = ' + str.tostring(bar_index-ago) + ' bars) \n'
  1650. if array.get(pvh1_price, 0) < bottom
  1651. box.delete(lbox)
  1652. array.remove(m_long_boxes, i)
  1653. if range_sv and (new_ph_2nd or new_pl_2nd) and (array.get(pvh2_price, 0) < array.get(pvh2_price, 1) and array.get(pvl2_price, 0) > array.get(pvl2_price, 1) and array.get(pvh2_price, 0) > array.get(pvl2_price, 1) and array.get(pvl2_price, 0) < array.get(pvh2_price, 1)) and (array.get(pvl2_price, 1) > nz(last_range_h) or na(last_range_l)? true : (array.get(pvh2_price, 1) < last_range_l))
  1654. temp_time := math.min(array.get(pvh2_time, 1), array.get(pvl2_time, 1))
  1655. last_range_h := array.get(pvh2_price, 1)
  1656. last_range_l := array.get(pvl2_price, 1)
  1657. temp_pv_0 := log_sv ? math.exp((math.log(last_range_h) + math.log(last_range_l))/2) : (last_range_h + last_range_l)/2
  1658. temp_pv_1 := log_sv ? math.exp((math.log(last_range_h) + math.log(temp_pv_0))/2) : (last_range_h + temp_pv_0)/2
  1659. temp_pv_2 := log_sv ? math.exp((math.log(last_range_l) + math.log(temp_pv_0))/2) : (last_range_l + temp_pv_0)/2
  1660. array.push(range_h_lines, line.new(x1=temp_time, y1=last_range_h, x2=bar_index, y2=last_range_h, color=color.gray, width=1, extend=extend.right))
  1661. array.push(range_l_lines, line.new(x1=temp_time, y1=last_range_l, x2=bar_index, y2=last_range_l, color=color.gray, width=1, extend=extend.right))
  1662. if range_eq_sv
  1663. array.push(range_m_lines, line.new(x1=temp_time, y1=temp_pv_0, x2=bar_index, y2=temp_pv_0, color=color.gray, width=1, extend=extend.right))
  1664. if range_q_sv
  1665. array.push(range_25_lines, line.new(x1=temp_time, y1=temp_pv_1, x2=bar_index, y2=temp_pv_1, style=line.style_dashed, color=color.gray, width=1, extend=extend.right))
  1666. array.push(range_75_lines, line.new(x1=temp_time, y1=temp_pv_2, x2=bar_index, y2=temp_pv_2, style=line.style_dashed, color=color.gray, width=1, extend=extend.right))
  1667. if r_a_sv
  1668. alert := alert + 'New Range : ' + str.tostring(last_range_h) + ' - ' + str.tostring(last_range_l) + '. Mean = ' + str.tostring(temp_pv_0) + '\n'
  1669. if array.size(range_h_lines) > 0
  1670. for i = array.size(range_h_lines) - 1 to 0 by 1
  1671. range_h = array.get(range_h_lines, i)
  1672. top = line.get_y1(range_h)
  1673. range_l = array.get(range_l_lines, i)
  1674. bottom = line.get_y1(range_l)
  1675. temp_time := line.get_x1(range_h)
  1676. if array.get(pvh1_price, 0) > top
  1677. if rt_a_sv and close < top
  1678. if array.get(pvh1_time, 0) != rh_a_time
  1679. rh_a_time := array.get(pvh1_time, 0)
  1680. alert := alert + 'Range High Test @ ' + str.tostring(array.get(pvh1_price, 0)) + ' \n'
  1681. if array.get(pvl1_price, 0) < bottom
  1682. if rt_a_sv and close > bottom
  1683. if array.get(pvl1_time, 0) != rl_a_time
  1684. rl_a_time := array.get(pvl1_time, 0)
  1685. alert := alert + 'Range Low Test @ ' + str.tostring(array.get(pvl1_price, 0)) + ' \n'
  1686. if range_eq_sv
  1687. range_m := array.get(range_m_lines, i)
  1688. if range_q_sv
  1689. range_25 := array.get(range_25_lines, i)
  1690. range_75 := array.get(range_75_lines, i)
  1691. if array.get(pvh1_price, 0) < bottom or array.get(pvl1_price, 0) > top
  1692. line.delete(range_h)
  1693. array.remove(range_h_lines, i)
  1694. line.delete(range_l)
  1695. array.remove(range_l_lines, i)
  1696. if range_eq_sv
  1697. line.delete(range_m)
  1698. array.remove(range_m_lines, i)
  1699. if range_q_sv
  1700. line.delete(range_25)
  1701. array.remove(range_25_lines, i)
  1702. line.delete(range_75)
  1703. array.remove(range_75_lines, i)
  1704. last_range_h := na
  1705. last_range_l := na
  1706. if pv2_sv
  1707. if new_ph_2nd
  1708. array.push(la_ph2, label.new(x = array.get(pvh2_time, 0), y = array.get(pvh2_price, 0), xloc = xloc.bar_index, style = label.style_label_down, color = #770000FF, size = size.tiny))
  1709. if new_pl_2nd
  1710. array.push(la_pl2, label.new(x = array.get(pvl2_time, 0), y = array.get(pvl2_price, 0), xloc = xloc.bar_index, style = label.style_label_up, color = #007700FF, size = size.tiny))
  1711.  
  1712. alert := not na(alert) ? (alert + 'Current price = ' + str.tostring(close) + '\n') : na
  1713. exec = not na(alert) ? true : false
  1714. if exec==true
  1715. alert(alert, alert.freq_once_per_bar_close)
  1716.  
  1717.  
  1718. //end of this part
  1719.  
  1720.  
Advertisement
Add Comment
Please, Sign In to add comment