Advertisement
xmd79

Merged Script [LuxAlgo + CDC ActionZone]

Nov 11th, 2023
823
1
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.67 KB | None | 1 0
  1. //@version=5
  2. indicator("Merged Script [LuxAlgo + CDC ActionZone]", overlay=true, max_lines_count=500, max_labels_count=500, max_bars_back=500, precision=6)
  3.  
  4. //------------------------------------------------------------------------------
  5. // LuxAlgo Nadaraya-Watson Envelope - Begin
  6. //------------------------------------------------------------------------------
  7. h = input.float(8.0, title='Bandwidth', minval=0)
  8. mult = input.float(3.0, title='Multiplier', minval=0)
  9. src = input(close, title='Source')
  10.  
  11.  
  12. repaint = input(true, 'Repainting Smoothing', tooltip='Repainting is an effect where the indicator\'s historical output is subject to change over time. Disabling repainting will cause the indicator to output the endpoints of the calculations')
  13.  
  14. upCss = input(color.teal, 'Colors', inline='inline1', group='Style')
  15. dnCss = input(color.red, '', inline='inline1', group='Style')
  16.  
  17. gauss(x, h) => math.exp(-math.pow(x, 2) / (math.pow(h, 2) * 2))
  18.  
  19. var ln = array.new_line(0)
  20.  
  21. if (barstate.isfirst and repaint)
  22. for i = 0 to 499
  23. array.push(ln, line.new(na, na, na, na))
  24.  
  25. var coefs = array.new_float(0)
  26. var den = 0.0
  27.  
  28. if (barstate.isfirst and not repaint)
  29. for i = 0 to 499
  30. w = gauss(i, h)
  31. array.push(coefs, w)
  32.  
  33. den := array.sum(coefs)
  34.  
  35. out = 0.0
  36. if (not repaint)
  37. for i = 0 to 499
  38. out := out + src[i] * array.get(coefs, i)
  39. out := out / den
  40. mae = ta.sma(math.abs(src - out), 499) * mult
  41.  
  42. upper = out + mae
  43. lower = out - mae
  44.  
  45. var float y2 = na
  46. var float y1 = na
  47.  
  48. nwe = array.new_float(0)
  49. if (barstate.islast and repaint)
  50. sae = 0.0
  51.  
  52. for i = 0 to math.min(499, bar_index - 1)
  53. sum = 0.0
  54. sumw = 0.0
  55.  
  56. for j = 0 to math.min(499, bar_index - 1)
  57. w = gauss(i - j, h)
  58. sum := sum + src[j] * w
  59. sumw := sumw + w
  60.  
  61. y2 := sum / sumw
  62. sae := sae + math.abs(src[i] - y2)
  63. array.push(nwe, y2)
  64.  
  65. sae := sae / math.min(499, bar_index - 1) * mult
  66. for i = 0 to math.min(499, bar_index - 1)
  67. if i % 2
  68. line.new(bar_index - i + 1, y1 + sae, bar_index - i, array.get(nwe, i) + sae, color=upCss)
  69. line.new(bar_index - i + 1, y1 - sae, bar_index - i, array.get(nwe, i) - sae, color=dnCss)
  70.  
  71. if src[i] > array.get(nwe, i) + sae and src[i + 1] < array.get(nwe, i) + sae
  72. label.new(bar_index - i, src[i], '▼', color=color(na), style=label.style_label_down, textcolor=dnCss, textalign=text.align_center)
  73. if src[i] < array.get(nwe, i) - sae and src[i + 1] > array.get(nwe, i) - sae
  74. label.new(bar_index - i, src[i], '▲', color=color(na), style=label.style_label_up, textcolor=upCss, textalign=text.align_center)
  75.  
  76. y1 := array.get(nwe, i)
  77.  
  78.  
  79. var tb = table.new(position.top_right, 1, 1, bgcolor=#1e222d, border_color=#373a46, border_width=1, frame_color=#373a46, frame_width=1)
  80.  
  81.  
  82. if (repaint)
  83. tb.cell(0, 0, 'Repainting Mode Enabled', text_color=color.white, text_size=size.small)
  84.  
  85. plot(repaint ? na : out + mae, 'Upper', upCss)
  86. plot(repaint ? na : out - mae, 'Lower', dnCss)
  87.  
  88. plotshape(ta.crossunder(close, out - mae) ? low : na, "Crossunder", shape.labelup, location.absolute, color(na), 0, text='▲', textcolor=upCss, size=size.tiny)
  89. plotshape(ta.crossover(close, out + mae) ? high : na, "Crossover", shape.labeldown, location.absolute, color(na), 0, text='▼', textcolor=dnCss, size=size.tiny)
  90. //------------------------------------------------------------------------------
  91. // LuxAlgo Nadaraya-Watson Envelope - End
  92. //------------------------------------------------------------------------------
  93.  
  94. //------------------------------------------------------------------------------
  95. // CDC ActionZone V3 2020 Optimized - Begin
  96. //------------------------------------------------------------------------------
  97. xsrc = input(close, title='Source Data')
  98. xprd1 = input(12, title='Fast EMA period')
  99. xprd2 = input(26, title='Slow EMA period')
  100. xsmooth = input(1, title='Smoothing period (1 = no smoothing)')
  101. fillSW = input(true, title='Paint Bar Colors')
  102. fastSW = input(true, title='Show fast moving average line')
  103. slowSW = input(true, title='Show slow moving average line')
  104. labelSwitch = input(true, title='Turn on assistive text')
  105. plotSigsw = input(true, title='Plot Buy/Sell Signals?')
  106. plotRibsw = input(false, title='Plot Buy/Sell Ribbon')
  107. plotRibbonPos = input('Top', title='Ribbon Position')
  108. plotRibbonPos := plotRibbonPos == 'Top' ? 'Top' : plotRibbonPos == 'Bottom' ? 'Bottom' : na
  109. plotSig2sw = input(false, title='Plot momentum-based Buy/Sell Signals?')
  110. plotSig2lv = input(1, title='Set signal threshold (higher = stricter)')
  111.  
  112. FastMA = ta.ema(xsrc, xprd1)
  113. SlowMA = ta.ema(xsrc, xprd2)
  114.  
  115. Bull = FastMA > SlowMA
  116. Bear = FastMA < SlowMA
  117.  
  118. Green = Bull and close > FastMA
  119. Blue = Bear and close > FastMA and close > SlowMA
  120. LBlue = Bear and close > FastMA and close < SlowMA
  121. Red = Bear and close < FastMA
  122. Orange = Bull and close < FastMA and close < SlowMA
  123. Yellow = Bull and close < FastMA and close > SlowMA
  124.  
  125. bColor = Green ? color.green : Blue ? color.blue : LBlue ? color.aqua : Red ? color.red : Orange ? color.orange : Yellow ? color.yellow : color.black
  126. barcolor(fillSW ? bColor : na)
  127.  
  128. FastL = plot(fastSW ? FastMA : na, 'Fast EMA', color=color.red, linewidth=1, style=plot.style_stepline)
  129. SlowL = plot(slowSW ? SlowMA : na, 'Slow EMA', color=color.blue, linewidth=1, style=plot.style_stepline)
  130. fill(FastL, SlowL, Bull ? color.new(color.green, 90) : Bear ? color.new(color.red, 90) : color.new(color.black, 90))
  131.  
  132. buycond = Green and Green[1] == 0
  133. sellcond = Red and Red[1] == 0
  134.  
  135. bullish = ta.barssince(buycond) < ta.barssince(sellcond)
  136. bearish = ta.barssince(sellcond) < ta.barssince(buycond)
  137.  
  138. buy = bearish[1] and buycond
  139. sell = bullish[1] and sellcond
  140.  
  141. bColor_BullBear = bullish ? color.green : bearish ? color.red : color.black
  142.  
  143. plotshape(plotSigsw ? buy : na, style=shape.circle, title='Buy Signal', location=location.belowbar, color=color.new(color.green, 0))
  144. plotshape(plotSigsw ? sell : na, style=shape.circle, title='Sell Signal', location=location.abovebar, color=color.new(color.red, 0))
  145.  
  146. plotshape(plotRibsw ? plotRibbonPos == 'Top' ? close : na : na, style=shape.square, title='Buy/Sell Ribbon', location=location.top, color=bColor_BullBear)
  147. plotshape(plotRibsw ? plotRibbonPos == 'Bottom' ? close : na : na, style=shape.square, title='Buy/Sell Ribbon', location=location.bottom, color=bColor_BullBear)
  148.  
  149. labelstyle = close > SlowMA ? label.style_label_down : label.style_label_up
  150. labelyloc = close > SlowMA ? yloc.abovebar : yloc.belowbar
  151. labeltcolor = buy ? color.black : sell ? color.white : close > close[1] ? color.green : color.red
  152. labelbgcolor = buy ? color.green : sell ? color.red : color.silver
  153. labeltext = buy ? 'BUY next bar\n' : sell ? 'SELL next bar\n' : ' '
  154. trendText = bullish ? 'bullish' : bearish ? 'bearish' : 'sideways'
  155.  
  156. l1 = label.new(bar_index, na, text=labeltext + syminfo.ticker + ' ' + str.tostring(close) + ' ' + syminfo.currency + '\n currently in a ' + trendText + ' trend \n', color=labelbgcolor, textcolor=labeltcolor, yloc=labelyloc, style=labelstyle)
  157. label.delete(labelSwitch ? l1[1] : l1)
  158.  
  159. rsi1 = ta.rsi(close, 14)
  160. k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, 14), 3)
  161. d = ta.sma(k, 3)
  162.  
  163. crossover_1 = ta.crossover(k, d)
  164. crossover_2 = ta.crossover(k, d)
  165. iff_1 = d > 30 and crossover_2 ? 1 : 0
  166. iff_2 = d < 30 and crossover_1 ? 2 : iff_1
  167. storsiBuySig = bullish ? iff_2 : 0
  168.  
  169. crossunder_1 = ta.crossunder(k, d)
  170. crossunder_2 = ta.crossunder(k, d)
  171. iff_3 = d < 70 and crossunder_2 ? 1 : 0
  172. iff_4 = d > 70 and crossunder_1 ? 2 : iff_3
  173. storsiSellSig = bearish ? iff_4 : 0
  174.  
  175. plotshape(plotSig2sw ? storsiBuySig > plotSig2lv ? storsiBuySig : na : na, 'Buy more signals', style=shape.triangleup, location=location.belowbar, color=color.new(color.teal, 0))
  176. plotshape(plotSig2sw ? storsiSellSig > plotSig2lv ? storsiSellSig : na : na, 'Sell more signals', style=shape.triangledown, location=location.abovebar, color=color.new(color.orange, 0))
  177.  
  178. alertcondition(buy, title='*Buy Alert', message='Buy {{exchange}}:{{ticker}}')
  179. alertcondition(sell, title='*Sell Alert', message='Sell {{exchange}}:{{ticker}}')
  180. alertcondition(bullish, title='is Bullish')
  181. alertcondition(bearish, title='is Bearish')
  182. alertcondition(Green, title='is Green')
  183. alertcondition(Blue, title='is Blue (Strong Rally)')
  184. alertcondition(LBlue, title='is Light Blue (Rally)')
  185. alertcondition(Red, title='is Red')
  186. alertcondition(Orange, title='is Orange (Strong Dip)')
  187. alertcondition(Yellow, title='is Yellow (Dip)')
  188. //------------------------------------------------------------------------------
  189. // CDC ActionZone V3 2020 Optimized - End
  190. //------------------------------------------------------------------------------
  191.  
Advertisement
Comments
  • # text 0.12 KB | 0 0
    1. download all types of premium tradingview indicators codes available on telegram - https://t.me/tradingview_premium_indicator
Add Comment
Please, Sign In to add comment
Advertisement