xmd79

hack1

Oct 2nd, 2021
1,233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 50.14 KB | None | 0 0
  1. //@version=4
  2. study("Gann medians", overlay = true, format=format.price, precision=12, max_bars_back=300)
  3.  
  4.  
  5. method1 = input("Median", options=["EMA", "Median", "SMA"])
  6. length1 = input(12)
  7. mult1 = input(1, minval=0, maxval=1)
  8.  
  9. method2 = input("Median", options=["EMA", "Median", "SMA"])
  10. length2 = input(27)
  11. mult2 = input(1, minval=0, maxval=1)
  12.  
  13. method3 = input("Median", options=["EMA", "Median", "SMA"])
  14. length3 = input(56)
  15. mult3 = input(1, minval=0, maxval=1)
  16. //----
  17. Avg(x, length, method) =>
  18. sma_1 = sma(x, length)
  19. ema_1 = ema(x, length)
  20. percentile_linear_interpolation_1 = percentile_linear_interpolation(x, length, 50)
  21. method == "SMA" ? sma_1 :
  22. method == "EMA" ? ema_1 : percentile_linear_interpolation_1
  23. //----
  24. a1 = highest(length1) - max(close, open)
  25. b1 = min(close, open) - lowest(length1)
  26. c1 = max(close, open) + a1 * mult1
  27. d1 = min(close, open) - b1 * mult1
  28.  
  29. a2 = highest(length2) - max(close, open)
  30. b2 = min(close, open) - lowest(length2)
  31. c2 = max(close, open) + a2 * mult2
  32. d2 = min(close, open) - b2 * mult2
  33.  
  34. a3 = highest(length3) - max(close, open)
  35. b3 = min(close, open) - lowest(length3)
  36. c3 = max(close, open) + a3 * mult3
  37. d3 = min(close, open) - b3 * mult3
  38. //----
  39. e1 = Avg(c1, length1, method1)
  40. f1 = Avg(d1, length1, method1)
  41. g1 = 0
  42. cross_1 = cross(close, f1)
  43. g1 := cross(close, e1) ? 1 : cross_1 ? 0 : nz(g1[1])
  44.  
  45. e2 = Avg(c2, length2, method2)
  46. f2 = Avg(d2, length2, method2)
  47. g2 = 0
  48. cross_2 = cross(close, f2)
  49. g2 := cross(close, e2) ? 1 : cross_2 ? 0 : nz(g2[1])
  50.  
  51. e3 = Avg(c3, length3, method3)
  52. f3 = Avg(d3, length3, method3)
  53. g3 = 0
  54. cross_3 = cross(close, f3)
  55. g3 := cross(close, e3) ? 1 : cross_3 ? 0 : nz(g3[1])
  56. //---
  57. hilo1 = g1 * f1 + (1 - g1) * e1
  58. css1 = g1 == 1 ? color.green : color.red
  59. plot(hilo1, color=css1, style=plot.style_line, show_last=1, linewidth=1, transp=0, trackprice=true)
  60.  
  61. hilo2 = g2 * f2 + (1 - g2) * e2
  62. css2 = g2 == 1 ? color.green : color.red
  63. plot(hilo2, color=css2, style=plot.style_line, show_last=1, linewidth=1, transp=0, trackprice=true)
  64.  
  65. hilo3 = g3 * f3 + (1 - g3) * e3
  66. css3 = g3 == 1 ? color.green : color.red
  67. plot(hilo3, color=css3, style=plot.style_line, show_last=1, linewidth=1, transp=0, trackprice=true)
  68.  
  69.  
  70. //end of this part
  71.  
  72.  
  73.  
  74. upperMult = input(title="Upper Deviation", defval=2)
  75. lowerMult = input(title="Lower Deviation", defval=-2)
  76.  
  77. useUpperDev = input(title="Use Upper Deviation", defval=true)
  78. useLowerDev = input(title="Use Lower Deviation", defval=true)
  79. showPearson = input(title="Show Pearson's R", defval=true)
  80. extendLines = input(title="Extend Lines", defval=false)
  81.  
  82. len = input(title="Count", defval=100)
  83. src = input(title="Source", defval=close)
  84.  
  85. extend = extendLines ? extend.right : extend.none
  86.  
  87. calcSlope(src, len) =>
  88. if not barstate.islast or len <= 1
  89. [float(na), float(na), float(na)]
  90. else
  91. sumX = 0.0
  92. sumY = 0.0
  93. sumXSqr = 0.0
  94. sumXY = 0.0
  95. for i = 0 to len - 1
  96. val = src[i]
  97. per = i + 1.0
  98. sumX := sumX + per
  99. sumY := sumY + val
  100. sumXSqr := sumXSqr + per * per
  101. sumXY := sumXY + val * per
  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. else
  116. line.set_xy1(baseLineLR, bar_index - len + 1, startPrice)
  117. line.set_xy2(baseLineLR, bar_index, endPrice)
  118. na
  119.  
  120. calcDev(src, len, slope, average, intercept) =>
  121. upDev = 0.0
  122. dnDev = 0.0
  123. stdDevAcc = 0.0
  124. dsxx = 0.0
  125. dsyy = 0.0
  126. dsxy = 0.0
  127.  
  128. periods = len - 1
  129.  
  130. daY = intercept + (slope * periods) / 2
  131. val = intercept
  132.  
  133. for i = 0 to periods
  134. price = high[i] - val
  135. if (price > upDev)
  136. upDev := price
  137.  
  138. price := val - low[i]
  139. if (price > dnDev)
  140. dnDev := price
  141.  
  142. price := src[i]
  143. dxt = price - average
  144. dyt = val - daY
  145.  
  146. price := price - val
  147. stdDevAcc := stdDevAcc + price * price
  148. dsxx := dsxx + dxt * dxt
  149. dsyy := dsyy + dyt * dyt
  150. dsxy := dsxy + dxt * dyt
  151. val := val + slope
  152.  
  153. stdDev = sqrt(stdDevAcc / (periods == 0 ? 1 : periods))
  154. pearsonR = dsxx == 0 or dsyy == 0 ? 0 : dsxy / sqrt(dsxx * dsyy)
  155. [stdDev, pearsonR, upDev, dnDev]
  156.  
  157. [stdDev, pearsonR, upDev, dnDev] = calcDev(src, len, s, aLR, i)
  158.  
  159. upperStartPrice = startPrice + (useUpperDev ? upperMult * stdDev : upDev)
  160. upperEndPrice = endPrice + (useUpperDev ? upperMult * stdDev : upDev)
  161. var line upper = na
  162.  
  163. lowerStartPrice = startPrice + (useLowerDev ? lowerMult * stdDev : -dnDev)
  164. lowerEndPrice = endPrice + (useLowerDev ? lowerMult * stdDev : -dnDev)
  165. var line lower = na
  166.  
  167. if na(upper) and not na(upperStartPrice)
  168. upper := line.new(bar_index - len + 1, upperStartPrice, bar_index, upperEndPrice, width=4, extend=extend, color=#0000ff)
  169. else
  170. line.set_xy1(upper, bar_index - len + 1, upperStartPrice)
  171. line.set_xy2(upper, bar_index, upperEndPrice)
  172. na
  173.  
  174. if na(lower) and not na(lowerStartPrice)
  175. lower := line.new(bar_index - len + 1, lowerStartPrice, bar_index, lowerEndPrice, width=4, extend=extend, color=#0000ff)
  176. else
  177. line.set_xy1(lower, bar_index - len + 1, lowerStartPrice)
  178. line.set_xy2(lower, bar_index, lowerEndPrice)
  179. na
  180.  
  181. // Pearson's R
  182. var label r = na
  183. transparent = color.new(color.white, 100)
  184. label.delete(r[1])
  185. if showPearson and not na(pearsonR)
  186. r := label.new(bar_index - len + 1, lowerStartPrice, tostring(pearsonR, "#.################"), color=transparent, textcolor=#0000ff, size=size.normal, style=label.style_labelup)
  187. //end of this part
  188.  
  189.  
  190. testStartYear = input(2019, "Backtest Start Year")
  191. testStartMonth = input(10, "Backtest Start Month")
  192. testStartDay = input(20, "Backtest Start Day")
  193. testStartHour = input(0, "Backtest Start Hour")
  194. testStartMin = input(0, "Backtest Start Minute")
  195. testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,testStartHour,testStartMin)
  196. testStopYear = input(2099, "Backtest Stop Year")
  197. testStopMonth = input(1, "Backtest Stop Month")
  198. testStopDay = input(30, "Backtest Stop Day")
  199. testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)
  200. testPeriod() =>
  201. time >= testPeriodStart and time <= testPeriodStop ? true : false
  202.  
  203.  
  204. lenH = input(title='Length High', type=input.integer, defval=20, minval=1)
  205. lenL = input(title='Length Low', type=input.integer, defval=20, minval=1)
  206.  
  207. fun(src, len, isHigh, _style, _yloc, _color) =>
  208. p = nz(src[len])
  209. isFound = true
  210. for i = 0 to len * 2
  211. if isHigh and src[i] > p
  212. isFound := false
  213. if not isHigh and src[i] < p
  214. isFound := false
  215. if isFound and testPeriod()
  216. label.new(bar_index[len], p, tostring(p), style=_style, yloc=_yloc, color=_color)
  217. line.new(bar_index[len], p, bar_index, p, extend=extend.right, color=_color)
  218.  
  219.  
  220.  
  221. fun(high, lenH, true, label.style_labeldown, yloc.abovebar, color.red)
  222. fun(low, lenL, false, label.style_labelup, yloc.belowbar, color.green)
  223.  
  224. //end of this part
  225.  
  226.  
  227.  
  228. price = input(type=input.source, defval=ohlc4)
  229.  
  230. // Strategy vars setup here
  231. Depth = input(56, title="Depth") // Depth
  232. Deviation = input(5, title="Deviation") // Deviation
  233.  
  234. // main logic
  235. // ZigZag
  236. lastlow = 0.0, lasthigh = 0.0
  237. lastlow := nz(lastlow[1])
  238. lasthigh := nz(lasthigh[1])
  239.  
  240. data(x) =>
  241. d = security(syminfo.tickerid, timeframe.period, x, gaps = barmerge.gaps_off, lookahead = barmerge.lookahead_on)
  242. d
  243. getLow(x, y, z, a) =>
  244. lastlow = y
  245. v = data(x)
  246. m = v==lastlow or data(z) - v > a*syminfo.mintick
  247. if v!=lastlow
  248. lastlow := v
  249. if m
  250. v := 0.0
  251. [v,lastlow]
  252. getHigh(x, y, z, a) =>
  253. lasthigh = y
  254. v = data(x)
  255. m = v==lasthigh or v - data(z) > a*syminfo.mintick
  256. if v!=lasthigh
  257. lasthigh := v
  258. if m
  259. v := 0.0
  260. [v,lasthigh]
  261.  
  262. [v,e] = getLow(lowest(Depth), lastlow, low, Deviation)
  263. lastlow := e
  264. zBB = v != 0.0
  265. [v1,ee1] = getHigh(highest(Depth), lasthigh, high, Deviation)
  266. lasthigh := ee1
  267. zSS = v1 != 0.0
  268.  
  269. zigzagDirection = -1
  270. zigzagHigh = 0
  271. zigzagLow = 0
  272. zigzagDirection := zBB ? 0 : zSS ? 1 : nz(zigzagDirection[1], -1)
  273. virtualLow = zigzagLow[1] + 1
  274. if not zBB or (zBB and zigzagDirection == zigzagDirection[1] and low > low[virtualLow])
  275. zigzagLow := nz(zigzagLow[1]) + 1
  276.  
  277. virtualHigh = zigzagHigh[1] + 1
  278. if not zSS or (zSS and zigzagDirection == zigzagDirection[1] and high < high[virtualHigh])
  279. zigzagHigh := nz(zigzagHigh[1]) + 1
  280. a=bar_index-zigzagLow
  281. b=bar_index-zigzagHigh
  282. var color c = na, c := fixnan(a < b[1] ? color.lime : a > b[1] ? color.red : na)
  283. //barcolor(color=color.lime)
  284. line zigzag = line.new(bar_index-zigzagLow, low[zigzagLow], bar_index-zigzagHigh, high[zigzagHigh], color=c, style=line.style_solid, width=4)
  285. if (zigzagDirection == zigzagDirection[1])
  286. line.delete(zigzag[1])
  287.  
  288. l = label.new(bar_index-zigzagHigh, na)
  289. label.set_text(l, "Sell")
  290. label.set_color(l, color.red)
  291. label.set_yloc(l, yloc.abovebar)
  292. label.set_style(l, label.style_labeldown)
  293. if (zigzagDirection == zigzagDirection[1])
  294. label.delete(l[1])
  295.  
  296.  
  297.  
  298. l_b = label.new(bar_index-zigzagLow, na)
  299. label.set_text(l_b, "Buy")
  300. label.set_color(l_b, color.green)
  301. label.set_yloc(l_b, yloc.belowbar)
  302. label.set_style(l_b, label.style_labelup)
  303. if (zigzagDirection == zigzagDirection[1])
  304. label.delete(l_b[1])
  305.  
  306.  
  307. zzPrevHigh = zigzagHigh[1]
  308. zzPrevLow = zigzagLow[1]
  309. if not na(zzPrevHigh[1])
  310. zzPrevHigh := zzPrevHigh[1] + 1
  311.  
  312. if not na(zzPrevLow[1])
  313. zzPrevLow := zzPrevLow[1] + 1
  314.  
  315. if zigzagDirection != zigzagDirection[1]
  316. if zigzagDirection == 1
  317. zzPrevHigh := zigzagHigh[1] + 1
  318. if zigzagDirection == 0
  319. zzPrevLow := zigzagLow[1] + 1
  320.  
  321. //end of this part
  322.  
  323. // RSI Settings for user
  324. rsiSource = input(title="RSI Source", type=input.source, defval=close)
  325. rsiLength = input(title="RSI Length", type=input.integer, defval=7)
  326. rsiOverbought = input(title="RSI Overbought", type=input.integer, defval=70, minval=50, maxval=100)
  327. rsiOvesold = input(title="RSI Oversold", type=input.integer, defval=30, minval=1, maxval=50)
  328.  
  329. // RSI value based on inbuilt RSI
  330. rsiValue = rsi(rsiSource, rsiLength)
  331.  
  332. // Get the current state
  333. isOverbought = rsiValue >= rsiOverbought
  334. isOversold = rsiValue <= rsiOvesold
  335.  
  336. // State of the last extreme 0 for initialization, 1 = overbought, 2 = oversold
  337. var laststate = 0
  338.  
  339. // Highest and Lowest prices since the last state change
  340. var hh = low
  341. var ll = high
  342.  
  343. // Labels
  344. var label labelll = na
  345. var label labelhh = na
  346.  
  347. // Swing lines
  348. var line line_up = na
  349. var line line_down = na
  350.  
  351.  
  352. // We go from overbought straight to oversold NEW DRAWINGS CREATED HERE
  353. if(laststate == 1 and isOversold)
  354. ll := low
  355. labelll := label.new(bar_index, low, style=label.style_label_up, color=color.green, size=size.tiny)
  356. labelhh_low = label.get_x(labelhh)
  357. labelhh_pos = label.get_y(labelhh)
  358. line_down := line.new(bar_index, high, labelhh_low, labelhh_pos, width=2)
  359.  
  360. // We go from oversold straight to overbought NEW DRAWINGS CREATED HERE
  361. if(laststate == 2 and isOverbought)
  362. hh := high
  363. labelhh := label.new(bar_index, high, style=label.style_label_down, color=color.red, size=size.tiny)
  364. labelll_low = label.get_x(labelll)
  365. labelll_pos = label.get_y(labelll)
  366. line_up := line.new(bar_index, high, labelll_low, labelll_pos, width=2)
  367.  
  368.  
  369. // If we are overbought
  370. if(isOverbought)
  371. if(high >= hh)
  372. hh := high
  373. label.set_x(labelhh, bar_index)
  374. label.set_y(labelhh, high)
  375. line.set_x1(line_up, bar_index)
  376. line.set_y1(line_up, high)
  377. laststate := 1
  378.  
  379. // If we are oversold
  380. if(isOversold)
  381. if(low <= ll)
  382. ll := low
  383. label.set_x(labelll, bar_index)
  384. label.set_y(labelll, low)
  385. line.set_x1(line_down, bar_index)
  386. line.set_y1(line_down, low)
  387. laststate := 2
  388.  
  389.  
  390. // If last state was overbought and we are overbought
  391. if(laststate == 1 and isOverbought)
  392. if(hh <= high)
  393. hh := high
  394. label.set_x(labelhh, bar_index)
  395. label.set_y(labelhh, high)
  396. line.set_x1(line_up, bar_index)
  397. line.set_y1(line_up, high)
  398.  
  399. //If we are oversold and the last state was oversold, move the drawings to the lowest price
  400. if(laststate == 2 and isOversold)
  401. if(low <= ll)
  402. ll := low
  403. label.set_x(labelll, bar_index)
  404. label.set_y(labelll, low)
  405. line.set_x1(line_down, bar_index)
  406. line.set_y1(line_down, low)
  407.  
  408.  
  409. // If last state was overbought
  410. if(laststate == 1)
  411. if(hh <= high)
  412. hh := high
  413. label.set_x(labelhh, bar_index)
  414. label.set_y(labelhh, high)
  415. line.set_x1(line_up, bar_index)
  416. line.set_y1(line_up, high)
  417.  
  418. // If last stare was oversold
  419. if(laststate == 2)
  420. if(ll >= low)
  421. ll := low
  422. label.set_x(labelll, bar_index)
  423. label.set_y(labelll, low)
  424. line.set_x1(line_down, bar_index)
  425. line.set_y1(line_down, low)
  426.  
  427. //end of this part
  428.  
  429.  
  430.  
  431.  
  432. //@version=4
  433. //study("momentum zigzag", overlay = true)
  434. lengthZZZ = input(10, title = "High/Low length")
  435. hZZZ = highest(high, lengthZZZ * 2 + 1)
  436. lZZZ = lowest(low, lengthZZZ * 2 + 1)
  437. f_isMin(len) =>
  438. lZZZ == low[len]
  439. f_isMax(len) =>
  440. hZZZ == high[len]
  441.  
  442. var dirUp = false
  443. var lastLow = high * 100
  444. var lastHigh = 0.0
  445. var timeLow = bar_index
  446. var timeHigh = bar_index
  447. var line li = na
  448. f_drawLine() =>
  449. _li_color = dirUp ? color.gray : color.gray
  450. line.new(
  451. timeHigh - lengthZZZ, lastHigh,
  452. timeLow - lengthZZZ, lastLow,
  453. xloc.bar_index, color=_li_color, width=1
  454. )
  455.  
  456. if dirUp
  457. if (f_isMin(lengthZZZ) and low[lengthZZZ] < lastLow)
  458. lastLow := low[lengthZZZ]
  459. timeLow := bar_index
  460. line.delete(li)
  461. li := f_drawLine()
  462.  
  463. if (f_isMax(lengthZZZ) and high[lengthZZZ] > lastLow)
  464. lastHigh := high[lengthZZZ]
  465. timeHigh := bar_index
  466. dirUp := false
  467. li := f_drawLine()
  468.  
  469. if not dirUp
  470. if (f_isMax(lengthZZZ) and high[lengthZZZ] > lastHigh)
  471. lastHigh := high[lengthZZZ]
  472. timeHigh := bar_index
  473. line.delete(li)
  474. li := f_drawLine()
  475. if f_isMin(lengthZZZ) and low[lengthZZZ] < lastHigh
  476. lastLow := low[lengthZZZ]
  477. timeLow := bar_index
  478. dirUp := true
  479. li := f_drawLine()
  480. if (f_isMax(lengthZZZ) and high[lengthZZZ] > lastLow)
  481. lastHigh := high[lengthZZZ]
  482. timeHigh := bar_index
  483. dirUp := false
  484. li := f_drawLine()
  485.  
  486. //end of this part
  487.  
  488.  
  489. use_alt_series = input(defval=false, title='Use alternative source?')
  490. alt_src = input(defval=close, title='Alternative source:')
  491. hSR = use_alt_series ? alt_src : high
  492. lSR = use_alt_series ? alt_src : low
  493.  
  494. window = input(defval=14, title='lookback window :', type=input.integer)
  495. percent_of_range_for_trade_zone = input(defval=15.0, title='Percent of the range to use for trade zone', type=input.float) * 0.01
  496.  
  497. short_term_top = valuewhen(hSR >= highest(hSR, window), hSR, 0)
  498. short_term_bot = valuewhen(lSR <= lowest(lSR, window), lSR, 0)
  499.  
  500. short_term_resist = change(short_term_top) != 0 ? na : short_term_top
  501. short_term_suport = change(short_term_bot) != 0 ? na : short_term_bot
  502.  
  503. short_term_resist_plot = plot(series=short_term_resist, title='STR', color=color.fuchsia, linewidth=2, style=plot.style_linebr, transp=0)
  504. short_term_suport_plot = plot(series=short_term_suport, title='STS', color=color.aqua, linewidth=2, style=plot.style_linebr, transp=0)
  505.  
  506. fill(short_term_suport_plot,short_term_resist_plot, color=color.aqua, transp=95, title=" Trade Zone ")
  507.  
  508. // Calculate entry zone:
  509. float short_term_resist_trade_limit = na
  510. float short_term_suport_trade_limit = na
  511.  
  512. range = fixnan(short_term_resist) - fixnan(short_term_suport)
  513.  
  514. if not na(short_term_resist)
  515. if not na(short_term_resist_trade_limit[1])
  516. short_term_resist_trade_limit := short_term_resist_trade_limit[1]
  517. else
  518. short_term_resist_trade_limit := short_term_resist - range * percent_of_range_for_trade_zone
  519.  
  520. if not na(short_term_suport)
  521. if not na(short_term_suport_trade_limit[1])
  522. short_term_suport_trade_limit := short_term_suport_trade_limit[1]
  523. else
  524. short_term_suport_trade_limit := short_term_suport + range * percent_of_range_for_trade_zone
  525.  
  526. short_term_resist_trade_limit_plot = plot(series=short_term_resist_trade_limit, title='', color=color.red, linewidth=1, style=plot.style_linebr, transp=0)
  527. short_term_suport_trade_limit_plot = plot(series=short_term_suport_trade_limit, title='', color=color.yellow, linewidth=1, style=plot.style_linebr, transp=0)
  528.  
  529. //end of this part
  530.  
  531. lookback = input(defval=20, title="# of Candles to Look Back", type=input.integer)
  532. srcAA = "Close"
  533.  
  534. pivot_high = iff(srcAA == "Close", pivothigh(high, lookback, lookback), pivothigh(high, lookback, lookback))
  535. pivot_low = iff(srcAA == "Close", pivotlow(low, lookback, lookback), pivotlow(low, lookback, lookback))
  536.  
  537. plot_high = iff(srcAA == "Close", valuewhen(pivot_high, high[lookback], 0), valuewhen(pivot_high, high[lookback], 0))
  538. plot_low = iff(srcAA == "Close", valuewhen(pivot_low, low[lookback], 0), valuewhen(pivot_low, low[lookback], 0))
  539.  
  540. resistance = plot(plot_high, style=plot.style_line, title="Resistance Line", color=color.orange, show_last=1, linewidth=2, trackprice=true)
  541. support = plot(plot_low, style=plot.style_line, title="Support Line", color=color.orange, show_last=1, linewidth=2, trackprice=true)
  542.  
  543.  
  544.  
  545. //end of this part
  546.  
  547.  
  548.  
  549. // - INPUTS
  550. ShowPivots = input(true, title="Show Pivot Points")
  551. ShowHHLL = input(true, title="Show HH,LL,LH,HL markers on Pivots Points")
  552. left = input(5, minval=1, title="Pivot Length Left Hand Side")
  553. right = input(5, minval=1, title="Pivot Length Right Hand Side")
  554. //
  555.  
  556. var barCounter = 0
  557. barCounter := barCounter + 1
  558. f_draw_infopanel(_x, _y, _line, _text)=>
  559. _rep_text = ""
  560. if barstate.islast
  561. for _l = 0 to _line
  562. _rep_text := _rep_text + "\n"
  563. _rep_text := _rep_text + _text
  564. var label _la = na
  565. //a = label.get_text(_la)
  566. label.delete(_la)
  567. _la := label.new(
  568. x=_x, y=_y,
  569. text=_rep_text, xloc=xloc.bar_time, yloc=yloc.price,
  570. color=color.black, style=label.style_labelup, textcolor=color.silver, size=size.small)
  571.  
  572. // Determine pivots
  573. pvtLenL = left
  574. pvtLenR = right
  575.  
  576. // Get High and Low Pivot Points
  577. pvthi_ = pivothigh(high, pvtLenL, pvtLenR)
  578. pvtlo_ = pivotlow(low, pvtLenL, pvtLenR)
  579.  
  580. // Force Pivot completion before plotting.
  581. pvthi = pvthi_
  582. pvtlo = pvtlo_
  583.  
  584. // ||-----------------------------------------------------------------------------------------------------||
  585. // ||--- Higher Highs, Lower Highs, Higher Lows, Lower Lows -------------------------------------------||
  586. valuewhen_1 = valuewhen(pvthi, high[pvtLenR], 1)
  587. valuewhen_2 = valuewhen(pvthi, high[pvtLenR], 0)
  588. higherhigh = na(pvthi) ? na : valuewhen_1 < valuewhen_2 ? pvthi : na
  589. valuewhen_3 = valuewhen(pvthi, high[pvtLenR], 1)
  590. valuewhen_4 = valuewhen(pvthi, high[pvtLenR], 0)
  591. lowerhigh = na(pvthi) ? na : valuewhen_3 > valuewhen_4 ? pvthi : na
  592. valuewhen_5 = valuewhen(pvtlo, low[pvtLenR], 1)
  593. valuewhen_6 = valuewhen(pvtlo, low[pvtLenR ], 0)
  594. higherlow = na(pvtlo) ? na : valuewhen_5 < valuewhen_6 ? pvtlo : na
  595. valuewhen_7 = valuewhen(pvtlo, low[pvtLenR], 1)
  596. valuewhen_8 = valuewhen(pvtlo, low[pvtLenR ], 0)
  597. lowerlow = na(pvtlo) ? na : valuewhen_7 > valuewhen_8 ? pvtlo : na
  598.  
  599.  
  600. // If selected Display the HH/LL above/below candle.
  601. plotshape(ShowHHLL ? higherhigh : na, title='HH', location=location.abovebar, color=color.green, text="HH", offset=-pvtLenR)
  602. plotshape(ShowHHLL ? higherlow : na, title='HL', location=location.belowbar, color=color.green, text="HL", offset=-pvtLenR)
  603. plotshape(ShowHHLL ? lowerhigh : na, title='LH', location=location.abovebar, color=color.red, text="LH", offset=-pvtLenR)
  604. plotshape(ShowHHLL ? lowerlow : na, title='LL', location=location.belowbar, color=color.red, text="LL", offset=-pvtLenR)
  605.  
  606.  
  607. useColors = input(title="Fill with colors?",defval=true)
  608. isess = session.regular
  609. t = tickerid(syminfo.prefix, syminfo.ticker, session=isess)
  610. igaps = barmerge.gaps_off
  611. yesterdayHigh = security(t,"D",high[1],gaps=igaps, lookahead=barmerge.lookahead_on)
  612. yesterdayClose = security(t,"D",close[1],gaps=igaps, lookahead=barmerge.lookahead_on)
  613. yesterdayLow = security(t,"D",low[1],gaps=igaps, lookahead=barmerge.lookahead_on)
  614.  
  615.  
  616. // Plot the other time frame's data
  617. aH= timeframe.isintraday ? yesterdayHigh : na
  618.  
  619. cL= timeframe.isintraday ? yesterdayLow: na
  620.  
  621. up5on = input(true, title="5 Minute Opening Range High")
  622. down5on = input(true, title="5 Minute Opening Range Low")
  623.  
  624. is_newbar(res) => change(time(res)) != 0
  625.  
  626. adopt(r, s) => security(syminfo.ticker, r, s)
  627.  
  628. high_range = valuewhen(is_newbar('D'),high,0)
  629. low_range = valuewhen(is_newbar('D'),low,0)
  630.  
  631. high_rangeL = valuewhen(is_newbar('D'),high,0)
  632. low_rangeL = valuewhen(is_newbar('D'),low,0)
  633.  
  634. up5 =up5on ? adopt('5', high_rangeL): na
  635. down5 =down5on ? adopt('5', low_rangeL): na
  636.  
  637.  
  638. bColor = #000000
  639. rColor = #ff0a02
  640. sColor = #008f0e
  641. pColor =#0900ff
  642. mColor =color.maroon
  643.  
  644.  
  645. myWidthMainLevels = input(title="Line width for Main levels", type=input.integer, defval=1, minval=1)
  646. myStyle = plot.style_circles
  647.  
  648.  
  649. //plot(aH, title="H", color=#008f0e, linewidth=myWidthMainLevels, style=myStyle)
  650. //plot(cL, title="L", color=#ff0a02, linewidth=myWidthMainLevels, style=myStyle)
  651.  
  652. //plot(up5, title="UP", color=#000000, linewidth=myWidthMainLevels, style=myStyle)
  653. //plot(down5, title="DOWN", color=#000000, linewidth=myWidthMainLevels, style=myStyle)
  654.  
  655. //end of this part
  656.  
  657. //----- User inputs ---------------------
  658. Lookback1 = input(title="Lookback Left", type=input.integer, defval=200, minval=1)
  659. Lookback2 = input(title="Lookback Right", type=input.integer, defval=0, minval=0)
  660. VertLR = input(title="Show Vertical Left/Right", type=input.bool, defval=true)
  661. VertHL = input(title="Show Vertical Highest/Lowest", type=input.bool, defval=true)
  662. Count = input(title="Show Counts", type=input.bool, defval=true)
  663. FullCount = input(title="Count All Bars", type=input.bool, defval=false)
  664. Fibs = input(title="Show Fib Retrace Lines", type=input.bool, defval=false)
  665. FibsExtHigh = input(title="Show Fib Ext Highs", type=input.bool, defval=false)
  666. FibsExtLow = input(title="Show Fib Ext Lows", type=input.bool, defval=false)
  667.  
  668.  
  669. //----- Main ---------------------
  670. // Get left and right endpoints. Though user input says "left" and "right", they are interchangeable.
  671. // The larger number is left, smaller number right.
  672. leftHL = max(Lookback1, Lookback2)
  673. rightHL = min(Lookback1, Lookback2)
  674. // Total num bars. Must be > 0 for highest() and lowest() to work. Add 1 to left bar, if needed.
  675. leftHL := leftHL - rightHL == 0 ? leftHL + 1 : leftHL
  676. lengthHL = leftHL - rightHL
  677.  
  678. // Highest price, looking back between the left/right endpoints
  679. highBack = highest(high[rightHL], lengthHL)
  680. // Get # of bars back from present bar (offset).
  681. // NOTE: highestbars() returns a negative integer. Thus, subtract the right endpoint to get
  682. // offset from present (right-edge) bar
  683. highOffset = highestbars(high[rightHL], lengthHL) - rightHL
  684.  
  685. // Lowest price, looking back
  686. lowBack = lowest(low[rightHL], lengthHL)
  687. lowOffset = lowestbars(low[rightHL], lengthHL) - rightHL
  688.  
  689. // Create a series of timestamps per bar. Needed to determine which bars are at the right edge,
  690. // While "n" starts at zero (left-edge bar) and counts up to the right-edge bar, this timestamp
  691. // (or tick) series counts the other way: max value at the left-edge, counting down to zero
  692. // at the right-edge.
  693. // This tick series is only valid while the indicator loads because "timenow" is the timestamp
  694. // of loading and "time" is the timestamp of a bar. The difference between the two timestamps
  695. // shrinks to zero as the righ-edge bar is processed. After loading, "timenow" and "time" are
  696. // the same value. Thus, "tick" always equals zero as new bars appear. But, for this indicator
  697. // this is sufficient behavior...
  698. tick = round((timenow - time) / change(time)) // Each bar is a tick (float) in the timeline
  699. // Make a boolean mask for bars between left and right endpoints
  700. mask = FullCount ? true : tick < left and tick >= rightHL ? true : false
  701. // Determine the value of n at the left endpoint, used for visual counts of bars in mask
  702. nOffset = float(na)
  703. nOffset := FullCount ? 0 : tick == leftHL ? bar_index : nz(nOffset[1])
  704.  
  705. // Note: It would be nice to count between the highest/lowest bars, instead of left/right bars,
  706. // but this isn't possible because highOffset and lowOffset are moving around as the
  707. // indicator loads. Thus, "mask" isn't accurate...
  708.  
  709. //---- Plotting ---------------------
  710. // Horizontal Lines: Highest, Lowest dynamic lines
  711. // Params trackprice and offset make the horizontal line dynamic, adjusting to new highs/lows
  712. plot(highBack, title="Highest", color=color.red, linewidth=2, trackprice=true, offset=-9999)
  713. plot(lowBack, title="Lowest", color=color.green, linewidth=2, trackprice=true, offset=-9999)
  714.  
  715. // Veritcal Lines
  716. // Use barstate to paint/re-paint vertical lines, as new bars come into the data set.
  717. // islast - True for right most bar in data set. Use this to paint vertical bar, then push it back
  718. // in time with the offset parameter.
  719. // isrealtime - False while indicator loads. True for the right most bar, after loading.
  720. // isconfirmed - False while bar is not closed. True when close price appears.
  721. // isrealtime and isconfirmed - While indicator loads, ignore isconfirmed. After loading, isconfirmed
  722. // turns off the vertical line, as the bar closes. The next (new) bar is painted. This keeps
  723. // the vertical bar moving forward, as new bars appear, erasing the old (previous) vertical bar.
  724. VertLRShow = VertLR ? barstate.isrealtime and barstate.isconfirmed ? false :
  725. barstate.islast ? true : false : false
  726. // Can't use plot() with histogram/column because histbase can't accept "series" values
  727. bgcolor(VertLRShow ? color.gray : na, title="Vertical Left", transp=60, offset=-leftHL + 1)
  728. bgcolor(VertLRShow ? color.gray : na, title="Vertical Right", transp=60, offset=-rightHL)
  729. // Show vertical highest/lowest lines?
  730. VertHLShow = VertHL ? barstate.isrealtime and barstate.isconfirmed ? false :
  731. barstate.islast ? true : false : false
  732. bgcolor(VertHLShow ? color.red : na, title="Vertical Highest", transp=60, offset=highOffset)
  733. bgcolor(VertHLShow ? color.green : na, title="Vertical Lowest", transp=60, offset=lowOffset)
  734.  
  735. // Fib levels extension and retracement
  736. priceRange = highBack - lowBack
  737. plot(FibsExtHigh ? lowBack + 3.618 * priceRange : na, title="3.618", color=color.lime, linewidth=2, trackprice=true, offset=-9999)
  738. plot(FibsExtHigh ? lowBack + 2.618 * priceRange : na, title="2.618", color=color.lime, linewidth=2, trackprice=true, offset=-9999)
  739. plot(FibsExtHigh ? lowBack + 1.618 * priceRange : na, title="1.618", color=color.lime, linewidth=2, trackprice=true, offset=-9999)
  740. plot(FibsExtHigh ? lowBack + 1.1 * priceRange : na, color=#88888800, trackprice=true, offset=-9999, editable=false) // invisible line to work around pine plot bug
  741. plot(Fibs ? lowBack + 1.1 * priceRange : na, color=#88888800, trackprice=true, offset=-9999, editable=false) // invisible line to work around pine plot bug
  742. plot(Fibs ? lowBack + 0.786 * priceRange : na, title="0.786", color=color.aqua, linewidth=1, trackprice=true, offset=-9999)
  743. plot(Fibs ? lowBack + 0.618 * priceRange : na, title="0.618", color=color.orange, linewidth=2, trackprice=true, offset=-9999)
  744. plot(Fibs ? lowBack + 0.50 * priceRange : na, title="0.5", color=color.yellow, linewidth=2, trackprice=true, offset=-9999)
  745. plot(Fibs ? lowBack + 0.382 * priceRange : na, title="0.382", color=color.orange, linewidth=2, trackprice=true, offset=-9999)
  746. plot(Fibs ? lowBack + 0.236 * priceRange : na, title="0.236", color=color.aqua, linewidth=1, trackprice=true, offset=-9999)
  747. plot(Fibs ? highBack - 1.1 * priceRange : na, color=#88888800, trackprice=true, offset=-9999, editable=false) // invisible line to work around pine plot bug
  748. plot(FibsExtLow ? highBack - 1.1 * priceRange : na, color=#88888800, trackprice=true, offset=-9999, editable=false) // invisible line to work around pine plot bug
  749. plot(FibsExtLow ? highBack - 1.618 * priceRange : na, title="1.618", color=color.fuchsia, linewidth=2, trackprice=true, offset=-9999)
  750. plot(FibsExtLow ? highBack - 2.618 * priceRange : na, title="2.618", color=color.fuchsia, linewidth=2, trackprice=true, offset=-9999)
  751. plot(FibsExtLow ? highBack - 3.618 * priceRange : na, title="3.618", color=color.fuchsia, linewidth=2, trackprice=true, offset=-9999)
  752.  
  753. // Lookback bar count
  754. countMod = mask ? (bar_index - nOffset) % 10 : na
  755. countInt = mask ? floor((bar_index - nOffset) / 10) % 10 : na
  756. plotshape(Count and countMod != 0 ? true : na, style=shape.circle, text="-", textcolor=color.gray, color=#88888800, location=location.bottom, size=size.auto, editable=false)
  757. plotshape(Count and countMod == 0 and countInt == 0 ? true : na, style=shape.circle, text="0", textcolor=color.gray, color=#88888800, location=location.bottom, size=size.auto, editable=false)
  758. plotshape(Count and countMod == 0 and countInt == 1 ? true : na, style=shape.circle, text="1", textcolor=color.gray, color=#88888800, location=location.bottom, size=size.auto, editable=false)
  759. plotshape(Count and countMod == 0 and countInt == 2 ? true : na, style=shape.circle, text="2", textcolor=color.gray, color=#88888800, location=location.bottom, size=size.auto, editable=false)
  760. plotshape(Count and countMod == 0 and countInt == 3 ? true : na, style=shape.circle, text="3", textcolor=color.gray, color=#88888800, location=location.bottom, size=size.auto, editable=false)
  761. plotshape(Count and countMod == 0 and countInt == 4 ? true : na, style=shape.circle, text="4", textcolor=color.gray, color=#88888800, location=location.bottom, size=size.auto, editable=false)
  762. plotshape(Count and countMod == 0 and countInt == 5 ? true : na, style=shape.circle, text="5", textcolor=color.gray, color=#88888800, location=location.bottom, size=size.auto, editable=false)
  763. plotshape(Count and countMod == 0 and countInt == 6 ? true : na, style=shape.circle, text="6", textcolor=color.gray, color=#88888800, location=location.bottom, size=size.auto, editable=false)
  764. plotshape(Count and countMod == 0 and countInt == 7 ? true : na, style=shape.circle, text="7", textcolor=color.gray, color=#88888800, location=location.bottom, size=size.auto, editable=false)
  765. plotshape(Count and countMod == 0 and countInt == 8 ? true : na, style=shape.circle, text="8", textcolor=color.gray, color=#88888800, location=location.bottom, size=size.auto, editable=false)
  766. plotshape(Count and countMod == 0 and countInt == 9 ? true : na, style=shape.circle, text="9", textcolor=color.gray, color=#88888800, location=location.bottom, size=size.auto, editable=false)
  767.  
  768. //end of this part
  769.  
  770.  
  771.  
  772. //@version=4
  773. //
  774. // @author LonesomeTheBlue
  775. //
  776. //study("Pivot High Low Points", overlay=true)
  777. lb = input(6, title="Left Bars")
  778. rb = input(6, title="Right Bars")
  779.  
  780. mb = lb + rb + 1
  781.  
  782. plot(iff(not na(high[mb]), iff(highestbars(mb) == -lb, high[lb], na), na), style=plot.style_cross, linewidth=3, color=color.blue, offset=-lb)
  783. plot(iff(not na(low[mb]), iff(lowestbars(mb) == -lb, low[lb], na), na), style=plot.style_cross, linewidth=3, color=color.blue, offset=-lb)
  784.  
  785. //end of this part
  786.  
  787.  
  788.  
  789. //end of this part
  790.  
  791.  
  792. //@version=4
  793. //study("VJ - Killer BS", overlay=true)
  794. //======================================================================
  795. //Jurij
  796. h_left = input(title="h left", type=input.integer, defval=10)
  797. h_right = input(title="h right", type=input.integer, defval=10)
  798. show_ptz = input(title="Show PTZ", type=input.bool, defval=true)
  799. show_channel = input(title="Show channel", type=input.bool, defval=true)
  800. //barCount = nz(barCount[1]) + 1
  801. //check history and realtime PTZ
  802. h_left_low = lowest(h_left)
  803. h_left_high = highest(h_left)
  804. newlow = low <= h_left_low
  805. newhigh = high >= h_left_high
  806. //channel_high = plot(show_channel ? h_left_low : 0, color=silver)
  807. //channel_low = plot (show_channel ? h_left_high : 0, color=silver)
  808. central_bar_low = low[h_right + 1]
  809. central_bar_high = high[h_right + 1]
  810. full_zone_low = lowest(h_left + h_right + 1)
  811. full_zone_high = highest(h_left + h_right + 1)
  812. central_bar_is_highest = central_bar_high >= full_zone_high
  813. central_bar_is_lowest = central_bar_low <= full_zone_low
  814. plotchar(central_bar_is_highest ? -1 : 0, offset=-h_right - 1, color=color.red, text="Sell")
  815. plotchar(central_bar_is_lowest ? 1 : 0, offset=-h_right - 1, location=location.belowbar, color=color.green, text="Buy")
  816. //plot(close)
  817.  
  818. //end of this part
  819.  
  820. //@version=4
  821. //study(title="Peaks&Valleys", shorttitle="P&V", overlay=true)
  822. width = input(9)
  823. p = 0
  824. vc = 0
  825. for i = 0 to width * 2 by 1
  826. p := p + (i == width ? 0 : high[i] < high[width] ? 1 : 0)
  827. v := vc + (i == width ? 0 : low[i] > low[width] ? 1 : 0)
  828. v
  829. plotshape(p == width * 2, offset=-width, style=shape.labeldown)
  830. plotshape(vc == width * 2, offset=-width, style=shape.labelup, location=location.belowbar)
  831.  
  832. //end of this part
  833.  
  834. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  835. // © LonesomeTheBlue
  836.  
  837. //@version=4
  838. //study("Double Zig Zag with HHLL", overlay = true, max_bars_back = 500)
  839. prdx1 = input(defval = 8, title="ZigZag Period 1", minval = 2, maxval = 20)
  840. prdx2 = input(defval = 20, title="ZigZag Period 2", minval = 2, maxval = 50)
  841. showzz = input(defval = "Show Both", title = "Show Zig Zags", options = ["Show Zig Zag 1", "Show Zig Zag 2", "Show Both", "Show None"])
  842. showhhll = input(defval = "Show Both", title = "Show HHLL", options = ["Show HHLL 1", "Show HHLL 2", "Show Both", "Show None"])
  843. upcol1 = input(defval = color.lime, title = "Zig Zag 1 Up Color")
  844. dncol1 = input(defval = color.red, title = "Zig Zag 1 Down Color")
  845. upcol2 = input(defval = color.blue, title = "Zig Zag 2 Up Color")
  846. dncol2 = input(defval = color.purple, title = "Zig Zag 2 Down Color")
  847. txtcol = input(defval = color.black, title = "Text Color")
  848. zz1style = input(defval = "Dashed", title = "Zig Zag 1 Line Style", options = ["Dashed", "Dotted"])
  849. zz1width = input(defval = 2, title = "Zig zag 1 Line Width", minval = 1, maxval = 4)
  850. zz2width = input(defval = 3, title = "Zig zag 2 Line Width", minval = 1, maxval = 6)
  851.  
  852. float ph1x = highestbars(high, prdx1) == 0 ? high : na
  853. float pl1x = lowestbars(low, prdx1) == 0 ? low : na
  854. float ph2x = highestbars(high, prdx2) == 0 ? high : na
  855. float pl2x = lowestbars(low, prdx2) == 0 ? low : na
  856.  
  857. var dir1 = 0
  858. var dir2 = 0
  859. dir1 := iff(ph1x and na(pl1x), 1, iff(pl1x and na(ph1x), -1, dir1))
  860. dir2 := iff(ph2x and na(pl2x), 1, iff(pl2x and na(ph2x), -1, dir2))
  861.  
  862. var max_array_sizex = 10 // [5, 2] matrix
  863. var zigzag1 = array.new_float(0)
  864. var zigzag2 = array.new_float(0)
  865.  
  866. add_to_zigzagx(pointer, value, bindex)=>
  867. array.unshift(pointer, bindex)
  868. array.unshift(pointer, value)
  869. if array.size(pointer) > max_array_sizex
  870. array.pop(pointer)
  871. array.pop(pointer)
  872.  
  873. update_zigzagx(pointer, value, bindex, dir)=>
  874. if array.size(pointer) == 0
  875. add_to_zigzagx(pointer, value, bindex)
  876. else
  877. if (dir == 1 and value > array.get(pointer, 0)) or (dir == -1 and value < array.get(pointer, 0))
  878. array.set(pointer, 0, value)
  879. array.set(pointer, 1, bindex)
  880. 0.
  881.  
  882. dir1changed = change(dir1)
  883. if ph1x or pl1x
  884. if dir1changed
  885. add_to_zigzagx(zigzag1, dir1 == 1 ? ph1x : pl1x, bar_index)
  886. else
  887. update_zigzagx(zigzag1, dir1 == 1 ? ph1x : pl1x, bar_index, dir1)
  888.  
  889. dir2changed = change(dir2)
  890. if ph2x or pl2x
  891. if dir2changed
  892. add_to_zigzagx(zigzag2, dir2 == 1 ? ph2x : pl2x, bar_index)
  893. else
  894. update_zigzagx(zigzag2, dir2 == 1 ? ph2x : pl2x, bar_index, dir2)
  895.  
  896. if array.size(zigzag1) >= 6
  897. var line zzline1 = na
  898. var label zzlabel1 = na
  899. float val = array.get(zigzag1, 0)
  900. int point = round(array.get(zigzag1, 1))
  901. if change(val) or change(point)
  902. float val1 = array.get(zigzag1, 2)
  903. int point1 = round(array.get(zigzag1, 3))
  904. if change(val1) == 0 and change(point1) == 0
  905. line.delete(zzline1)
  906. label.delete(zzlabel1)
  907. if showzz == "Show Zig Zag 1" or showzz == "Show Both"
  908. 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)
  909. if showhhll == "Show HHLL 1" or showhhll == "Show Both"
  910. hhlltxt = dir1 == 1 ? array.get(zigzag1, 0) > array.get(zigzag1, 4) ? "HH" : "LH" : array.get(zigzag1, 0) < array.get(zigzag1, 4) ? "LL" : "HL"
  911. labelcol = dir1 == 1 ? array.get(zigzag1, 0) > array.get(zigzag1, 4) ? upcol1 : dncol1 : array.get(zigzag1, 0) < array.get(zigzag1, 4) ? dncol1 : upcol1
  912. zzlabel1 := label.new(x = point, y = val, text = hhlltxt, color = labelcol, textcolor = txtcol, style = dir1 == 1 ? label.style_label_down : label.style_label_up)
  913.  
  914. if array.size(zigzag2) >= 6
  915. var line zzline2 = na
  916. var label zzlabel2 = na
  917. float val = array.get(zigzag2, 0)
  918. int point = round(array.get(zigzag2, 1))
  919. if change(val) or change(point)
  920. float val1 = array.get(zigzag2, 2)
  921. int point1 = round(array.get(zigzag2, 3))
  922. if change(val1) == 0 and change(point1) == 0
  923. line.delete(zzline2)
  924. label.delete(zzlabel2)
  925. if showzz == "Show Zig Zag 2" or showzz == "Show Both"
  926. zzline2 := line.new(x1 = point, y1 = val, x2 = point1, y2 = val1, color = dir2 == 1 ? upcol2 : dncol2, width = zz2width)
  927. if showhhll == "Show HHLL 2" or showhhll == "Show Both"
  928. hhlltxt = dir2 == 1 ? array.get(zigzag2, 0) > array.get(zigzag2, 4) ? "HH" : "LH" : array.get(zigzag2, 0) < array.get(zigzag2, 4) ? "LL" : "HL"
  929. labelcol = dir2 == 1 ? array.get(zigzag2, 0) > array.get(zigzag2, 4) ? upcol2 : dncol2 : array.get(zigzag2, 0) < array.get(zigzag2, 4) ? dncol2 : upcol2
  930. zzlabel2 := label.new(x = point, y = val, text = hhlltxt, color = labelcol, textcolor = txtcol, style = dir2 == 1 ? label.style_label_down : label.style_label_up)
  931.  
  932.  
  933. //end of this part
  934.  
  935. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  936. // © GokhanGoksin
  937.  
  938. //@version=4
  939. //study("ENGUL",shorttitle="engulf",overlay=true)
  940. x=input(title="çizgi/sağ uzat",type=input.integer,defval=5)
  941. z=input(title="kaynak/seç/üst çizgi",type=input.source,defval=open)
  942. y=input(title="kaynak/seç/alt çizgi",type=input.source,defval=close)
  943. //****************************************************
  944. en=close[1]<open[1] and close>open[1] and low[1] >low
  945. plotshape(en,style=shape.arrowup,location=location.belowbar)
  946. //****************************************************** enguluf destek
  947. if en
  948. li =line.new(time[1],y[1],time+x*(time-time[1]),y[1],xloc=xloc.bar_time,color=color.red,width=2)
  949.  
  950. if en
  951. label.new(time+x*(time-time[1]),y[1],text="\n"+tostring(y[1]),xloc=xloc.bar_time,
  952. style=label.style_none,size=size.normal,textcolor=color.white,yloc=yloc.price)
  953. //********************************************************************** direnç
  954. if en
  955. line.new(time[1],z[1],time+x*(time-time[1]),z[1],xloc=xloc.bar_time,color=color.blue,width=2)
  956. if en
  957. l=label.new(time+x*(time-time[1]),z[1],text="\n"+tostring(z[1]),xloc=xloc.bar_time,
  958. style=label.style_none,size=size.normal,textcolor=color.white,yloc=yloc.price)
  959.  
  960.  
  961. //end of this part
  962.  
  963. // © weeklystockcharts
  964.  
  965. // @version=4
  966. // Candle Type w/ only 3-1 Pine Script
  967.  
  968. //study("Candle Type w/only 3-1", overlay=true, precision=0)
  969.  
  970. // check for 3-1 inside + up buy
  971. 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])
  972. plotchar(buyx, title="Inside + Up Buy Label", text ="Up", location=location.belowbar, color=#4CAF50)
  973.  
  974. // check for 3-1 inside + dn sell
  975. 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])
  976. plotchar(sellx, title="Inside + Up Buy Label", text ="Down", location=location.abovebar, color=color.red)
  977. //end of this part
  978.  
  979.  
  980. //@version=4
  981.  
  982. //study("The system no.1", shorttitle="System no.1", overlay=true)
  983.  
  984. _length = input(title="Length", type=input.integer, defval=21)
  985. _offset = input(title="Offset", type=input.integer, defval=0)
  986.  
  987. _smooth = input(title="WMA Length", type=input.integer, defval=8, minval=1)
  988.  
  989.  
  990. _source = close
  991.  
  992. _lsma = linreg(_source, _length, _offset)
  993. _lsmaS = wma(_lsma, _smooth)
  994. _lsmaC = cross(_lsma, _lsmaS) ? (_lsma + _lsmaS) * 0.5 : na
  995. //iscross() => _lsmaC
  996. plot(_lsma, color=color.white, linewidth=2)
  997. plot(_lsmaS, color=#2299CC, linewidth=2)
  998. plotshape(_lsmaC, color=color.green, style=shape.xcross)
  999.  
  1000. //barcolor(iscross() ? yellow : na)
  1001.  
  1002. //coppock
  1003.  
  1004. wmaLength = input(title="WMA Length", type=input.integer, defval=10)
  1005. longRoCLength = input(title="Long RoC Length", type=input.integer, defval=14)
  1006. shortRoCLength = input(title="Short RoC Length", type=input.integer, defval=11)
  1007.  
  1008. _crossoverMA = input(title="Crossover WMA Lenth", defval=5, minval=1)
  1009. _histogramMultiplier = input(title="Histogram Multiplier", defval=2, type=input.float)
  1010.  
  1011. _sourcec = close
  1012.  
  1013. _curve = wma(roc(_sourcec, longRoCLength) + roc(_sourcec, shortRoCLength), wmaLength)
  1014. _curveWMA = wma(_curve, _crossoverMA)
  1015.  
  1016. _h = (_curve - _curveWMA) * _histogramMultiplier
  1017.  
  1018. _curveWMAx = cross(_curve, _curveWMA) ? (_curve + _curveWMA) * 0.5 : na
  1019.  
  1020. //final decision
  1021. check(x, y) =>
  1022. cross(_curve[x], _curveWMA[x]) and cross(_lsma[y], _lsmaS[y])
  1023. check00 = check(0, 0)
  1024. check01 = check(0, 1)
  1025. check02 = check(0, 2)
  1026. check10 = check(1, 0)
  1027. //check11 = check(1,1)
  1028. //check12 = check(1,2)
  1029. check20 = check(2, 0)
  1030. //check21 = check(2,1)
  1031. check03 = check(0, 3)
  1032. //check13 = check(1,3)
  1033. //check23 = check(2,3)
  1034. check30 = check(3, 0)
  1035. //check22 = check(2,2)
  1036. checkcross = check00 ? true : check01 ? true : check02 ? true :
  1037. check10 ? true : check30 ? true : check20 ? true : check03 ? true : na
  1038.  
  1039.  
  1040.  
  1041. //checking value
  1042. mathcall = (abs(lowest(_curve, 50)) + abs(highest(_curve, 50))) * 0.3
  1043. highalert = highest(_curve, 50) - mathcall
  1044. lowalert = lowest(_curve, 50) + mathcall
  1045.  
  1046. // sell position
  1047. sellcheck = _curveWMA > _curve ? true : false
  1048. sellcheck1 = _lsma < _lsmaS ? true : false
  1049. sellcheck2 = _curve > highalert
  1050.  
  1051. SELLSIGNAL = checkcross and sellcheck and sellcheck1 and sellcheck2
  1052. barcolor(SELLSIGNAL ? color.yellow : na)
  1053.  
  1054. // buy position
  1055. buycheck = _curveWMA < _curve ? true : false
  1056. buycheck1 = _lsma > _lsmaS ? true : false
  1057. buycheck2 = _curve < lowalert
  1058.  
  1059. BUYSIGNAL = checkcross and buycheck and buycheck1 and buycheck2
  1060. barcolor(BUYSIGNAL ? color.blue : na)
  1061.  
  1062. //end of this part
  1063.  
  1064. //
  1065. //@author BillionaireLau
  1066. //
  1067. //@version=4
  1068.  
  1069. //study("Key price levels", overlay=true)
  1070. lbc = input(15, title="Number of bars searching backward", minval=1)
  1071. rbc = input(15, title="Number of bars searching forward", minval=1)
  1072.  
  1073. showsupres = input(true, title="Show Support/Resistance")
  1074. changebarcol = input(true, title="Change Bar Color")
  1075. mbc = lbc + rbc + 1
  1076.  
  1077. phc = iff(not na(high[mbc]), iff(highestbars(high, mbc) == -lbc, high[lbc], na), na) // Pivot High
  1078. plc = iff(not na(low[mbc]), iff(lowestbars(low, mbc) == -lbc, low[lbc], na), na) // Pivot Low
  1079.  
  1080. hlc = int(na)
  1081. hlc := iff(phc, 1, iff(plc, -1, na)) // Trend direction
  1082. zz = float(na)
  1083. zz := iff(phc, phc, iff(plc, plc, na)) // similar to zigzag but may have multiple highs/lows
  1084. zz := iff(plc and hlc == -1 and valuewhen(hlc, hlc, 1) == -1 and plc > valuewhen(zz, zz, 1), na, zz)
  1085. zz := iff(phc and hlc == 1 and valuewhen(hlc, hlc, 1) == 1 and phc < valuewhen(zz, zz, 1), na, zz)
  1086.  
  1087. hlc := iff(hlc == -1 and valuewhen(hlc, hlc, 1) == 1 and zz > valuewhen(zz, zz, 1), na, hlc)
  1088. hlc := iff(hlc == 1 and valuewhen(hlc, hlc, 1) == -1 and zz < valuewhen(zz, zz, 1), na, hlc)
  1089. zz := iff(na(hlc), na, zz)
  1090.  
  1091. findprevious() => // finds previous three points (b, c, d, e)
  1092. ehl = iff(hlc == 1, -1, 1)
  1093. loc1 = 0.0
  1094. loc2 = 0.0
  1095. loc3 = 0.0
  1096. loc4 = 0.0
  1097. xx = 0
  1098. for x = 1 to 1000 by 1
  1099. if hlc[x] == ehl and not na(zz[x])
  1100. loc1 := zz[x]
  1101. xx := x + 1
  1102. break
  1103. ehl := hlc
  1104. for x = xx to 1000 by 1
  1105. if hlc[x] == ehl and not na(zz[x])
  1106. loc2 := zz[x]
  1107. xx := x + 1
  1108. break
  1109. ehl := iff(hlc == 1, -1, 1)
  1110. for x = xx to 1000 by 1
  1111. if hlc[x] == ehl and not na(zz[x])
  1112. loc3 := zz[x]
  1113. xx := x + 1
  1114. break
  1115. ehl := hlc
  1116. for x = xx to 1000 by 1
  1117. if hlc[x] == ehl and not na(zz[x])
  1118. loc4 := zz[x]
  1119. break
  1120. [loc1, loc2, loc3, loc4]
  1121.  
  1122. axx = float(na)
  1123. bxx = float(na)
  1124. cxx = float(na)
  1125. dxx = float(na)
  1126. exx = float(na)
  1127. if not na(hlc)
  1128. [loc1, loc2, loc3, loc4] = findprevious()
  1129. axx := zz
  1130. bxx := loc1
  1131. cxx := loc2
  1132. dxx := loc3
  1133. exx := loc4
  1134. exx
  1135.  
  1136. _hh = zz and axx > bxx and axx > cxx and cxx > bxx and cxx > dxx
  1137. _ll = zz and axx < bxx and axx < cxx and cxx < bxx and cxx < dxx
  1138. _hl = zz and
  1139. (axx >= cxx and bxx > cxx and bxx > dxx and dxx > cxx and dxx > exx or axx < bxx and axx > cxx and bxx < dxx)
  1140. _lh = zz and
  1141. (axx <= cxx and bxx < cxx and bxx < dxx and dxx < cxx and dxx < exx or axx > bxx and axx < cxx and bxx > dxx)
  1142.  
  1143.  
  1144. //Lows
  1145. if _ll
  1146. label.new(bar_index[lbc], na,tostring(low[lbc], "####.##"),color=color.lime,textcolor=color.lime,style=label.style_none, yloc=yloc.belowbar)
  1147. if _hl
  1148. label.new(bar_index[lbc], na,tostring(low[lbc], "####.##"),color=color.lime,textcolor=color.lime,style=label.style_none, yloc=yloc.belowbar)
  1149.  
  1150. //Highs
  1151. if _lh
  1152. label.new(bar_index[lbc], na, tostring(high[lbc], "####.##"),color=color.red,textcolor=color.red,style=label.style_none, yloc=yloc.abovebar)
  1153. if _hh
  1154. label.new(bar_index[lbc], na, tostring(high[lbc], "####.##"),color=color.red,textcolor=color.red,style=label.style_none, yloc=yloc.abovebar)
  1155.  
  1156.  
  1157.  
  1158.  
  1159.  
  1160.  
  1161. res = float(na)
  1162. sup = float(na)
  1163. res := iff(_lh, zz, res[1])
  1164. sup := iff(_hl, zz, sup[1])
  1165.  
  1166. trend = int(na)
  1167. trend := iff(close > res, 1, iff(close < sup, -1, nz(trend[1])))
  1168.  
  1169. res := iff(trend == 1 and _hh or trend == -1 and _lh, zz, res)
  1170. sup := iff(trend == 1 and _hl or trend == -1 and _ll, zz, sup)
  1171.  
  1172. //plot(showsupres ? res : na, title="Resistance", color=na(res) ? na : color.red, linewidth=2, style=plot.style_circles, offset=-lb)
  1173. //plot(showsupres ? sup : na, title="Support", color=na(sup) ? na : color.blue, linewidth=2, style=plot.style_circles, offset=-lb)
  1174.  
  1175.  
  1176. //end of this part
  1177.  
  1178. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  1179. // © ownsov
  1180.  
  1181. //@version=4
  1182. //study(title="OS HiLo Tracking", shorttitle="OS HiLo Tracking", overlay=true, precision=6)
  1183.  
  1184.  
  1185. // HiLo inputs
  1186. high_activate = input(title='Track Previous High', type=input.bool, defval = true)
  1187. high_input = input(title='Days', type=input.integer, defval = 3)
  1188. low_activate = input(title='Track Previous Low', type=input.bool, defval = true)
  1189. low_input = input(title='Days', type=input.integer, defval = 3)
  1190.  
  1191. // HiLo definitions
  1192. daily_hh = nz(highest(high,high_input)[1])
  1193. daily_ll = nz(lowest(low,low_input)[1])
  1194.  
  1195. // HH and LL crossovers
  1196. HHXO=crossover(close, daily_hh)
  1197. LLXO=crossover(daily_ll, close)
  1198.  
  1199. // alerts
  1200.  
  1201. i_HHXO = input(false, "Alert Highest High crossovers")
  1202. i_LLXO = input(false, "Alert Lowest Low crossovers")
  1203. i_repaint = input(true, "Allow Repainting")
  1204.  
  1205. // alert entries only generate entries when allowed in inputs
  1206. enterHHXO = i_HHXO and HHXO and (i_repaint or barstate.isconfirmed)
  1207. enterLLXO = i_LLXO and LLXO and (i_repaint or barstate.isconfirmed)
  1208.  
  1209.  
  1210. // alert plots only when the compound condition is met
  1211. if enterHHXO
  1212. alert("Price crossing up last Highest High (HH is " + tostring(daily_hh, "#.00)"))
  1213. else if enterLLXO
  1214. alert("Price crossing down last Lowest Low (LL is " + tostring(daily_ll, "#.00)"))
  1215.  
  1216. //
  1217.  
  1218. // plot HiLo horizontal line
  1219. plot(high_activate ? daily_hh : na,title = 'Previous Highest High', trackprice=true, offset=-9999, color= color.blue)
  1220. plot(low_activate ? daily_ll : na,title = 'Previous Lowest Low', trackprice=true, offset=-9999, color= color.blue)
  1221.  
  1222.  
  1223. labeltime = time + (time-time[13])
  1224.  
  1225. // previous daily high label
  1226. ldaily_hh = label.new(labeltime, daily_hh, "H (" +tostring(high_input) + ") = " + tostring(daily_hh, "#.##"),
  1227. color = high_activate ? color.new(color.blue,40) : na,
  1228. textcolor = high_activate ? color.white : na,
  1229. textalign = text.align_center,
  1230. style = label.style_label_center,
  1231. xloc = xloc.bar_time)
  1232. label.delete (ldaily_hh[1])
  1233.  
  1234. f_printhh(_texthh) =>
  1235. // Create label on the first bar.
  1236. 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)
  1237. // On next bars, update the label's x and y position, and the text it displays.
  1238. label.set_xy(_labelhh, bar_index, highest(10)[1])
  1239. label.set_text(_labelhh, _texthh)
  1240.  
  1241. // previous daily low label
  1242. ldaily_ll = label.new(labeltime, daily_ll, "L (" +tostring(low_input) + ") = " + tostring(daily_ll, "#.##"),
  1243. color = low_activate ? color.new(color.blue,40) : na,
  1244. textcolor = low_activate ? color.white : na,
  1245. textalign = text.align_center,
  1246. style = label.style_label_center,
  1247. xloc = xloc.bar_time)
  1248. label.delete (ldaily_ll[1])
  1249.  
  1250. f_printll(_textll) =>
  1251. // Create label on the first bar.
  1252. 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)
  1253. // On next bars, update the label's x and y position, and the text it displays.
  1254. label.set_xy(_labelll, bar_index, lowest(10)[1])
  1255. label.set_text(_labelll, _textll)
  1256.  
  1257. //end of this part
  1258.  
  1259.  
Advertisement
Add Comment
Please, Sign In to add comment