xmd79

Gann medians MA targets

May 24th, 2023 (edited)
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 19.95 KB | None | 0 0
  1. //@version=5
  2. indicator("Gaann medians MA targets", overlay=true, max_bars_back=500, max_lines_count=500, max_labels_count=500)
  3.  
  4. // Inputs
  5. method1 = input.string('Median', options=['EMA', 'Median', 'SMA'])
  6. length1 = input(56)
  7. mult1 = input.int(1, minval=0, maxval=1)
  8.  
  9. method2 = input.string('Median', options=['EMA', 'Median', 'SMA'])
  10. length2 = input(100)
  11. mult2 = input.int(1, minval=0, maxval=1)
  12.  
  13. method3 = input.string('Median', options=['EMA', 'Median', 'SMA'])
  14. length3 = input(200)
  15. mult3 = input.int(1, minval=0, maxval=1)
  16.  
  17. // Calculation of medians
  18. Avg(x, length, method) =>
  19. sma_1 = ta.sma(x, length)
  20. ema_1 = ta.ema(x, length)
  21. percentile_linear_interpolation_1 = ta.percentile_linear_interpolation(x, length, 50)
  22. method == 'SMA' ? sma_1 : method == 'EMA' ? ema_1 : percentile_linear_interpolation_1
  23.  
  24. a1 = ta.highest(length1) - math.max(close, open)
  25. b1 = math.min(close, open) - ta.lowest(length1)
  26. c1 = math.max(close, open) + a1 * mult1
  27. d1 = math.min(close, open) - b1 * mult1
  28.  
  29. a2 = ta.highest(length2) - math.max(close, open)
  30. b2 = math.min(close, open) - ta.lowest(length2)
  31. c2 = math.max(close, open) + a2 * mult2
  32. d2 = math.min(close, open) - b2 * mult2
  33.  
  34. a3 = ta.highest(length3) - math.max(close, open)
  35. b3 = math.min(close, open) - ta.lowest(length3)
  36. c3 = math.max(close, open) + a3 * mult3
  37. d3 = math.min(close, open) - b3 * mult3
  38.  
  39. // Calculation of volume
  40. volLength = input.int(20, minval=1, title='Volume Length')
  41. volMultiplier = input.float(1.0, title='Volume Multiplier')
  42.  
  43. volAvg = ta.sma(volume, volLength) * volMultiplier
  44.  
  45. // Calculation of signals and liquidity levels
  46. e1 = Avg(c1, length1, method1)
  47. f1 = Avg(d1, length1, method1)
  48. gx1 = 0
  49. cross_1 = ta.cross(close, f1)
  50. gx1 := ta.cross(close, e1) ? 1 : cross_1 ? 0 : nz(gx1[1])
  51.  
  52. e2 = Avg(c2, length2, method2)
  53. f2 = Avg(d2, length2, method2)
  54. gx2 = 0
  55. cross_2 = ta.cross(close, f2)
  56. gx2 := ta.cross(close, e2) ? 1 : cross_2 ? 0 : nz(gx2[1])
  57.  
  58. e3 = Avg(c3, length3, method3)
  59. f3 = Avg(d3, length3, method3)
  60. gx3 = 0
  61. cross_3 = ta.cross(close, f3)
  62. gx3 := ta.cross(close, e3) ? 1 : cross_3 ? 0 : nz(gx3[1])
  63.  
  64. // Calculation of liquidity levels with volume
  65. hilo1 = gx1 * f1 + (1 - gx1) * e1
  66. css1 = gx1 == 1 ? color.green : color.red
  67. plot(hilo1, color=css1, style=plot.style_line, show_last=1, linewidth=1, trackprice=true, transp=0)
  68.  
  69. hilo2 = gx2 * f2 + (1 - gx2) * e2
  70. css2 = gx2 == 1 ? color.green : color.red
  71. plot(hilo2, color=css2, style=plot.style_line, show_last=1, linewidth=1, trackprice=true, transp=0)
  72.  
  73. hilo3 = gx3 * f3 + (1 - gx3) * e3
  74. css3 = gx3 == 1 ? color.green : color.red
  75. plot(hilo3, color=css3, style=plot.style_line, show_last=1, linewidth=1, trackprice=true, transp=0)
  76.  
  77.  
  78. //end of the code
  79.  
  80. //@version=5
  81.  
  82. //indicator(title='HiLo Activator', overlay=true)
  83. length = input.int(3, minval=1)
  84. displace = input.int(0, minval=0)
  85. highsma = ta.sma(high, length)
  86. lowsma = ta.sma(low, length)
  87. iff_1 = close < lowsma[displace] ? -1 : 0
  88. swing = close > highsma[displace] ? 1 : iff_1
  89. mah = ta.highest(high, length)
  90. mal = ta.lowest(low, length)
  91. var stop = 0.0
  92. iff_2 = swing == -1 ? mah : stop[1]
  93. stop := swing == 1 ? mal : iff_2
  94.  
  95. linecolor = stop < low ? color.green : color.red
  96. plot(stop, show_last=1, linewidth=1, trackprice=true, transp=0)
  97.  
  98. //end of this part
  99.  
  100. //study(title="TrapTrading (Study)", overlay=true)
  101. // input
  102. counterTrend = input(defval=false, title='Trade Mode (ON: Counter Trend OFF: Trend Following)')
  103. len1 = input.int(defval=20, title='Period (1-200)', minval=1, maxval=200)
  104. multiple = input(defval=0.7, title='Multiple')
  105.  
  106. m1 = close - close[len1]
  107. lowest_1 = ta.lowest(math.abs(m1), len1)
  108. highest_1 = ta.highest(math.abs(m1), len1)
  109. controlPoint = counterTrend ? lowest_1 == math.abs(m1) : highest_1 == math.abs(m1)
  110. baseLine = ta.valuewhen(controlPoint, math.avg(close, close[len1]), 0)
  111.  
  112. // trap line
  113. atr = ta.valuewhen(controlPoint, ta.highest(math.max(math.max(ta.atr(len1), ta.atr(len1 * 2)), ta.atr(len1 * 3)), len1), 0)
  114. line1Up = baseLine + atr * multiple
  115. line2Up = baseLine + atr * 2 * multiple
  116. line3Up = baseLine + atr * 3 * multiple
  117. line4Up = baseLine + atr * 4 * multiple
  118. line5Up = baseLine + atr * 5 * multiple
  119. line6Up = baseLine + atr * 6 * multiple
  120. line7Up = baseLine + atr * 7 * multiple
  121. line8Up = baseLine + atr * 8 * multiple
  122. line9Up = baseLine + atr * 9 * multiple
  123. line10Up = baseLine + atr * 10 * multiple
  124. line1Down = baseLine - atr * multiple
  125. line2Down = baseLine - atr * 2 * multiple
  126. line3Down = baseLine - atr * 3 * multiple
  127. line4Down = baseLine - atr * 4 * multiple
  128. line5Down = baseLine - atr * 5 * multiple
  129. line6Down = baseLine - atr * 6 * multiple
  130. line7Down = baseLine - atr * 7 * multiple
  131. line8Down = baseLine - atr * 8 * multiple
  132. line9Down = baseLine - atr * 9 * multiple
  133. line10Down = baseLine - atr * 10 * multiple
  134.  
  135. // draw
  136. //barcolor(controlPoint ? color.yellow : close >= baseLine ? color.teal : color.red, title="Candle Color")
  137.  
  138.  
  139. // find which bar is 5 days away from the current time
  140. milliseconds_in_5days = 1000 * 60 * 60 * 24 * 1 // millisecs * secs * min * hours * days
  141. leftborder = timenow - time < milliseconds_in_5days // true or na when false
  142. rightborder = barstate.islast
  143.  
  144.  
  145. plot(baseLine, title='Base Line', color=color.new(color.purple, 0), linewidth=1, style=plot.style_stepline, show_last=1, linewidth=1, trackprice=true, transp=0)
  146. //plot(leftborder?line1Up:na, title="1Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  147. //plot(leftborder?line2Up:na, title="2Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  148. //plot(leftborder?line3Up:na, title="3Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  149. //plot(leftborder?line4Up:na, title="4Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  150. //plot(leftborder?line5Up:na, title="5Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  151. //plot(leftborder?line6Up:na, title="6Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  152. //plot(leftborder?line7Up:na, title="7Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  153. //plot(leftborder?line8Up:na, title="8Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  154. //plot(leftborder?line9Up:na, title="9Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  155. //plot(leftborder?line10Up:na, title="10Up Line", color=color.red, linewidth=1, style=plot.style_stepline, transp=0)
  156. //plot(leftborder?line1Down:na, title="1Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  157. //plot(leftborder?line2Down:na, title="2Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  158. //plot(leftborder?line3Down:na, title="3Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  159. //plot(leftborder?line4Down:na, title="4Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  160. //plot(leftborder?line5Down:na, title="5Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  161. //plot(leftborder?line6Down:na, title="6Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  162. //plot(leftborder?line7Down:na, title="7Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  163. //plot(leftborder?line8Down:na, title="8Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  164. //plot(leftborder?line9Down:na, title="9Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  165. //plot(leftborder?line10Down:na, title="10Down Line", color=color.green, linewidth=1, style=plot.style_stepline, transp=0)
  166.  
  167. //end of this part
  168.  
  169. upperMult = input(title='Upper Deviation', defval=2)
  170. lowerMult = input(title='Lower Deviation', defval=-2)
  171.  
  172. useUpperDev = input(title='Use Upper Deviation', defval=true)
  173. useLowerDev = input(title='Use Lower Deviation', defval=true)
  174. showPearson = input(title='Show Pearson\'s R', defval=true)
  175. extendLines = input(title='Extend Lines', defval=false)
  176.  
  177. len = input(title='Count', defval=100)
  178. src = input(title='Source', defval=close)
  179.  
  180. extend = extendLines ? extend.right : extend.none
  181.  
  182. calcSlope(src, len) =>
  183. if not barstate.islast or len <= 1
  184. [float(na), float(na), float(na)]
  185. else
  186. sumX = 0.0
  187. sumY = 0.0
  188. sumXSqr = 0.0
  189. sumXY = 0.0
  190. for i = 0 to len - 1 by 1
  191. val = src[i]
  192. per = i + 1.0
  193. sumX += per
  194. sumY += val
  195. sumXSqr += per * per
  196. sumXY += val * per
  197. sumXY
  198. slope = (len * sumXY - sumX * sumY) / (len * sumXSqr - sumX * sumX)
  199. average = sumY / len
  200. intercept = average - slope * sumX / len + slope
  201. [slope, average, intercept]
  202.  
  203. [s, aLR, i] = calcSlope(src, len)
  204.  
  205. startPrice = i + s * (len - 1)
  206. endPrice = i
  207. var line baseLineLR = na
  208.  
  209. if na(baseLineLR) and not na(startPrice)
  210. baseLineLR := line.new(bar_index - len + 1, startPrice, bar_index, endPrice, width=4, extend=extend, color=color.red)
  211. baseLineLR
  212. else
  213. line.set_xy1(baseLineLR, bar_index - len + 1, startPrice)
  214. line.set_xy2(baseLineLR, bar_index, endPrice)
  215. na
  216.  
  217. calcDev(src, len, slope, average, intercept) =>
  218. upDev = 0.0
  219. dnDev = 0.0
  220. stdDevAcc = 0.0
  221. dsxx = 0.0
  222. dsyy = 0.0
  223. dsxy = 0.0
  224.  
  225. periods = len - 1
  226.  
  227. daY = intercept + slope * periods / 2
  228. val = intercept
  229.  
  230. for i = 0 to periods by 1
  231. price = high[i] - val
  232. if price > upDev
  233. upDev := price
  234. upDev
  235.  
  236. price := val - low[i]
  237. if price > dnDev
  238. dnDev := price
  239. dnDev
  240.  
  241. price := src[i]
  242. dxt = price - average
  243. dyt = val - daY
  244.  
  245. price -= val
  246. stdDevAcc += price * price
  247. dsxx += dxt * dxt
  248. dsyy += dyt * dyt
  249. dsxy += dxt * dyt
  250. val += slope
  251. val
  252.  
  253. stdDev = math.sqrt(stdDevAcc / (periods == 0 ? 1 : periods))
  254. pearsonR = dsxx == 0 or dsyy == 0 ? 0 : dsxy / math.sqrt(dsxx * dsyy)
  255. [stdDev, pearsonR, upDev, dnDev]
  256.  
  257. [stdDev, pearsonR, upDev, dnDev] = calcDev(src, len, s, aLR, i)
  258.  
  259. upperStartPrice = startPrice + (useUpperDev ? upperMult * stdDev : upDev)
  260. upperEndPrice = endPrice + (useUpperDev ? upperMult * stdDev : upDev)
  261. var line upper = na
  262.  
  263. lowerStartPrice = startPrice + (useLowerDev ? lowerMult * stdDev : -dnDev)
  264. lowerEndPrice = endPrice + (useLowerDev ? lowerMult * stdDev : -dnDev)
  265. var line lower = na
  266.  
  267. if na(upper) and not na(upperStartPrice)
  268. upper := line.new(bar_index - len + 1, upperStartPrice, bar_index, upperEndPrice, width=4, extend=extend, color=#0000ff)
  269. upper
  270. else
  271. line.set_xy1(upper, bar_index - len + 1, upperStartPrice)
  272. line.set_xy2(upper, bar_index, upperEndPrice)
  273. na
  274.  
  275. if na(lower) and not na(lowerStartPrice)
  276. lower := line.new(bar_index - len + 1, lowerStartPrice, bar_index, lowerEndPrice, width=4, extend=extend, color=#0000ff)
  277. lower
  278. else
  279. line.set_xy1(lower, bar_index - len + 1, lowerStartPrice)
  280. line.set_xy2(lower, bar_index, lowerEndPrice)
  281. na
  282.  
  283. // Pearson's R
  284. var label r = na
  285. transparent = color.new(color.white, 100)
  286. label.delete(r[1])
  287. if showPearson and not na(pearsonR)
  288. r := label.new(bar_index - len + 1, lowerStartPrice, str.tostring(pearsonR, '#.################'), color=transparent, textcolor=#0000ff, size=size.normal, style=label.style_label_up)
  289. r
  290. //end of this part
  291.  
  292. //@version=5
  293. //indicator("MTF SR with Angle, Square of 9, Phi, Golden Ratio, and Pi", overlay=true)
  294.  
  295. // Define input variables
  296. //src = input(close, title="Source")
  297. res = input("D", title="Resolution")
  298.  
  299. // Define time frames
  300. tf1 = res == "1D" ? "D" : res == "1W" ? "W" : res == "1M" ? "M" : na
  301. tf2 = res == "1D" ? "W" : res == "1W" ? "M" : res == "1M" ? "3M" : na
  302. tf3 = res == "1D" ? "M" : res == "1W" ? "3M" : res == "1M" ? "6M" : na
  303. tf4 = res == "1D" ? "3M" : res == "1W" ? "6M" : res == "1M" ? "12M" : na
  304.  
  305. // Define support and resistance levels
  306. sr1 = request.security(syminfo.tickerid, tf1, high[1])
  307. sr2 = request.security(syminfo.tickerid, tf2, high[1])
  308. sr3 = request.security(syminfo.tickerid, tf3, high[1])
  309. sr4 = request.security(syminfo.tickerid, tf4, high[1])
  310. sup1 = request.security(syminfo.tickerid, tf1, low[1])
  311. sup2 = request.security(syminfo.tickerid, tf2, low[1])
  312. sup3 = request.security(syminfo.tickerid, tf3, low[1])
  313. sup4 = request.security(syminfo.tickerid, tf4, low[1])
  314.  
  315. // Draw support and resistance levels
  316. plot(sr1, color=color.yellow, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
  317. plot(sr2, color=color.orange, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
  318. plot(sr3, color=color.red, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
  319. plot(sr4, color=color.maroon, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
  320. plot(sup1, color=color.yellow, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
  321. plot(sup2, color=color.orange, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
  322. plot(sup3, color=color.red, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
  323. plot(sup4, color=color.maroon, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
  324.  
  325. // Calculate 45 degree angle from lowest low
  326. lowestLow = ta.lowest(low, 100)
  327. angle = math.atan((lowestLow - lowestLow[1]) / (time - time[1])) * 180 / math.acos(-1)
  328.  
  329. plot(lowestLow, color=color.green, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
  330. plot(lowestLow + (ta.highest(high, 100) - lowestLow) * math.tan(angle), color=color.green, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
  331.  
  332. // Calculate Square of 9 levels
  333. squareOf9 = 1.414 * math.sqrt(math.abs(close - close[1])) + close[1]
  334. plot(squareOf9, color=color.blue, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
  335.  
  336. // Calculate Phi, Golden Ratio, and Pi levels
  337. phi = close * 0.618 + close[1] * 0.382
  338. goldenRatio = close * 1.618 - close[1] * 0.618
  339. pi = close * 3.14 / 100
  340.  
  341. plot(phi, color=color.purple, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
  342. plot(goldenRatio, color=color.fuchsia, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
  343. plot(pi, color=color.aqua, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
  344.  
  345. // Calculate 3, 6, 9 algo levels
  346. three = close * 1.03
  347. six = close * 1.06
  348. nine = close * 1.09
  349.  
  350. plot(three, color=color.orange, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
  351. plot(six, color=color.orange, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
  352. plot(nine, color=color.orange, style=plot.style_line, linewidth=1, show_last=1, trackprice=true, transp=0)
  353.  
  354. //end of this part
  355.  
  356. // © Julien_Eche
  357.  
  358. //@version=5
  359. //indicator(title="Ultimate Trend Channel", shorttitle="Ultimate Trend Channel", overlay=true)
  360.  
  361. // User inputs for defining length of each group
  362. len_group1 = input(title="Length 1", defval=220)
  363. len_group2 = input(title="Length 2", defval=252)
  364. len_group3 = input(title="Length 3", defval=315)
  365. len_group4 = input(title="Length 4", defval=378)
  366. len_group5 = input(title="Length 5", defval=441)
  367. len_group6 = input(title="Length 6", defval=504)
  368. len_group7 = input(title="Length 7", defval=567)
  369. len_group8 = input(title="Length 8", defval=630)
  370. len_group9 = input(title="Length 9", defval=693)
  371. len_group10 = input(title="Length 10", defval=756)
  372. len_group11 = input(title="Length 11", defval=882)
  373. len_group12 = input(title="Length 12", defval=1008)
  374. len_group13 = input(title="Length 13", defval=1134)
  375. len_group14 = input(title="Length 14", defval=1260)
  376. len_group15 = input(title="Length 15", defval=1449)
  377. len_group16 = input(title="Length 16", defval=1638)
  378. len_group17 = input(title="Length 17", defval=1827)
  379. len_group18 = input(title="Length 18", defval=2016)
  380. len_group19 = input(title="Length 19", defval=2331)
  381. len_group20 = input(title="Length 20", defval=2646)
  382. len_group21 = input(title="Length 21", defval=2961)
  383.  
  384. mult = 1.0
  385. //src = close
  386.  
  387. // Function for calculating upper band
  388. upperBand(src, length) =>
  389. ta.linreg(src, length, 0) + mult * ta.stdev(src, length)
  390.  
  391. // Function for calculating lower band
  392. lowerBand(src, length) =>
  393. ta.linreg(src, length, 0) - mult * ta.stdev(src, length)
  394.  
  395. // Calculation of upper and lower bands for each group
  396. upperband1 = upperBand(src, len_group1)
  397. lowerband1 = lowerBand(src, len_group1)
  398. upperband2 = upperBand(src, len_group2)
  399. lowerband2 = lowerBand(src, len_group2)
  400. upperband3 = upperBand(src, len_group3)
  401. lowerband3 = lowerBand(src, len_group3)
  402. upperband4 = upperBand(src, len_group4)
  403. lowerband4 = lowerBand(src, len_group4)
  404. upperband5 = upperBand(src, len_group5)
  405. lowerband5 = lowerBand(src, len_group5)
  406. upperband6 = upperBand(src, len_group6)
  407. lowerband6 = lowerBand(src, len_group6)
  408. upperband7 = upperBand(src, len_group7)
  409. lowerband7 = lowerBand(src, len_group7)
  410. upperband8 = upperBand(src, len_group8)
  411. lowerband8 = lowerBand(src, len_group8)
  412. upperband9 = upperBand(src, len_group9)
  413. lowerband9 = lowerBand(src, len_group9)
  414. upperband10 = upperBand(src, len_group10)
  415. lowerband10 = lowerBand(src, len_group10)
  416. upperband11 = upperBand(src, len_group11)
  417. lowerband11 = lowerBand(src, len_group11)
  418. upperband12 = upperBand(src, len_group12)
  419. lowerband12 = lowerBand(src, len_group12)
  420. upperband13 = upperBand(src, len_group13)
  421. lowerband13 = lowerBand(src, len_group13)
  422. upperband14 = upperBand(src, len_group14)
  423. lowerband14 = lowerBand(src, len_group14)
  424. upperband15 = upperBand(src, len_group15)
  425. lowerband15 = lowerBand(src, len_group15)
  426. upperband16 = upperBand(src, len_group16)
  427. lowerband16 = lowerBand(src, len_group16)
  428. upperband17 = upperBand(src, len_group17)
  429. lowerband17 = lowerBand(src, len_group17)
  430. upperband18 = upperBand(src, len_group18)
  431. lowerband18 = lowerBand(src, len_group18)
  432. upperband19 = upperBand(src, len_group19)
  433. lowerband19 = lowerBand(src, len_group19)
  434. upperband20 = upperBand(src, len_group20)
  435. lowerband20 = lowerBand(src, len_group20)
  436. upperband21 = upperBand(src, len_group21)
  437. lowerband21 = lowerBand(src, len_group21)
  438.  
  439. // Calculate average of all upper and lower bands
  440. averageBand = (upperband1 + lowerband1 + upperband2 + lowerband2 + upperband3 + lowerband3 + upperband4 + lowerband4 + upperband5 + lowerband5 + upperband6 + lowerband6 + upperband7 + lowerband7 + upperband8 + lowerband8 + upperband9 + lowerband9 + upperband10 + lowerband10 + upperband11 + lowerband11 + upperband12 + lowerband12 + upperband13 + lowerband13 + upperband14 + lowerband14 + upperband15 + lowerband15 + upperband16 + lowerband16 + upperband17 + lowerband17 + upperband18 + lowerband18 + upperband19 + lowerband19 + upperband20 + lowerband20 + upperband21 + lowerband21) / 42
  441.  
  442. // Calculate average of all upper bands
  443. averageUpperBand = (upperband1 + upperband2 + upperband3 + upperband4 + upperband5 + upperband6 + upperband7 + upperband8 + upperband9 + upperband10 + upperband11 + upperband12 + upperband13 + upperband14 + upperband15 + upperband16 + upperband17 + upperband18 + upperband19 + upperband20 + upperband21) / 21
  444.  
  445. // Calculate average of all lower bands
  446. averageLowerBand = (lowerband1 + lowerband2 + lowerband3 + lowerband4 + lowerband5 + lowerband6 + lowerband7 + lowerband8 + lowerband9 + lowerband10 + lowerband11 + lowerband12 + lowerband13 + lowerband14 + lowerband15 + lowerband16 + lowerband17 + lowerband18 + lowerband19 + lowerband20 + lowerband21) / 21
  447.  
  448. // Define fill color for the area between upper and lower bands
  449. fillcolor = color.rgb(0, 191, 255, 95)
  450.  
  451. // Plot upper and lower bands and fill the area between them
  452. fill(plot(averageUpperBand, title="Average Upper Band", color=color.rgb(14, 116, 212), linewidth=1), plot(averageLowerBand, title="Average Lower Band", color=color.rgb(14, 116, 212), linewidth=1), color=fillcolor)
  453.  
  454. // Plot average band
  455. plot(averageBand, title="Ultimate Trend Line", color=color.rgb(243, 128, 33), linewidth=1)
  456.  
  457.  
  458.  
Advertisement
Add Comment
Please, Sign In to add comment