Advertisement
NKactive

Untitled

Aug 11th, 2023
214
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.19 KB | None | 0 0
  1. // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
  2. // © NKactive and based on profitprotrading
  3.  
  4. //@version=5
  5. strategy("ALMA Smoothed Gaussian Moving Average", overlay=true, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=0, slippage=1)
  6.  
  7. import EliCobra/CobraMetrics/4 as cobra
  8. //// PLOT DATA
  9. disp_ind = input.string ("None" , title = "Display Curve" , tooltip = "Choose which data you would like to display", options=["Strategy", "Equity", "Open Profit", "Gross Profit", "Net Profit", "None"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  10. pos_table = input.string("Middle Left", "Table Position", options = ["Top Left", "Middle Left", "Bottom Left", "Top Right", "Middle Right", "Bottom Right", "Top Center", "Bottom Center"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  11. type_table = input.string("None", "Table Type", options = ["Full", "Simple", "None"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  12. plot(cobra.curve(disp_ind))
  13. cobra.cobraTable(type_table, pos_table)
  14. //
  15. // ****************************************************************************************************************************************************************
  16. //
  17. // ****************************************************************************************************************************************************************
  18. //
  19.  
  20. //ALMA Smoothing
  21. src = input(close, title='Source', group = "ALMA Smoothing")
  22. smooth = input.int(1, title='Smoothing', minval=1, group = "ALMA Smoothing")
  23. length1 = input.int(25, title='Lookback', minval=1, group = "ALMA Smoothing")
  24. rsiNKactiveLength = input.int(14, title='rsiLookback', minval=1, group = "NK Smoothing")
  25. offset = input.float(defval = 0.85, title='offset for ALMA', group = "NK Smoothing") // offset = 0.85
  26. sigma1= input.int(7, title='sigma1 for ALMA', minval=1, group = "NK Smoothing") // sigma1 = 7
  27. pchange = ta.change(src, smooth) / src * 100
  28. avpchange = ta.alma(pchange, length1, offset, sigma1)
  29.  
  30. //RSI
  31. rsi = ta.rsi(close, 14)
  32. rsiL = rsi > rsi[1]
  33. rsiS = rsi < rsi[1]
  34.  
  35. //Chande Momentum
  36. length11 = 9
  37. src1 = close
  38. momm = ta.change(src1)
  39. f1(m) => m >= 0.0 ? m : 0.0
  40. f2(m) => m >= 0.0 ? 0.0 : -m
  41. m1 = f1(momm)
  42. m2 = f2(momm)
  43. sm1 = math.sum(m1, length11)
  44. sm2 = math.sum(m2, length11)
  45. percent(nom, div) => 100 * nom / div
  46. chandeMO = percent(sm1-sm2, sm1+sm2)
  47. cL = chandeMO > chandeMO[1]
  48. cS = chandeMO < chandeMO[1]
  49.  
  50. //GAMA credit to author: © LeafAlgo https://www.tradingview.com/v/th7NZUPM/
  51. length = input.int(14, minval=1, title="Length", group = "Gaussian Adaptive Moving Average")
  52. adaptive = input.bool(true, title="Adaptive Parameters", group = "Gaussian Adaptive Moving Average")
  53. volatilityPeriod = input.int(20, minval=1, title="Volatility Period", group = "Gaussian Adaptive Moving Average")
  54.  
  55. // Calculate Gaussian Moving Average
  56. gma = 0.0
  57. sumOfWeights = 0.0
  58. sigma = adaptive ? ta.stdev(close, volatilityPeriod) : input.float(1.0, minval=0.1, title="Standard Deviation", group = "Gaussian Adaptive Moving Average")
  59.  
  60. for i = 0 to length - 1
  61. weight = math.exp(-math.pow(((i - (length - 1)) / (2 * sigma)), 2) / 2)
  62. value = ta.highest(avpchange, i + 1) + ta.lowest(avpchange, i + 1)
  63. gma := gma + (value * weight)
  64. sumOfWeights := sumOfWeights + weight
  65.  
  66. gma := (gma / sumOfWeights) / 2
  67. gma:= ta.ema(gma, 7)
  68. gmaColor = avpchange >= gma ? color.rgb(0, 161, 5) : color.rgb(215, 0, 0)
  69.  
  70. // Color bars based on signals until the next signal occurs
  71. var int currentSignal = 0
  72. currentSignal := avpchange >= gma ? 1 : -1//le_final ? -1 : currentSignal
  73.  
  74. var color barColor = na
  75. if currentSignal == 1
  76. barColor := color.rgb(0, 186, 6)
  77. else if currentSignal == -1
  78. barColor := color.rgb(176, 0, 0)
  79.  
  80. barcolor(barColor)
  81. plotcandle(open, high, low, close, "Bar Color", barColor, barColor, bordercolor = barColor)
  82.  
  83. //Plotting
  84. ema = ta.ema(close, 7)
  85. plot(ema, color=gmaColor, linewidth=3, title="Gaussian Moving Average")
  86.  
  87. longCondition = ta.crossover(avpchange,gma)
  88. shortCondition = ta.crossunder(avpchange,gma)
  89. plotshape(ta.crossover(avpchange,gma) and barstate.isconfirmed, "Buy Signal", text = "B", textcolor = color.white, style = shape.labelup, location = location.belowbar, color = color.rgb(0, 161, 5))
  90. plotshape(ta.crossunder(avpchange,gma) and barstate.isconfirmed, "Sell Signal", text = "S", textcolor = color.white, style = shape.labeldown, location = location.abovebar, color = color.rgb(215, 0, 0))
  91.  
  92. bgcolor(ta.crossover(avpchange,gma) and barstate.isconfirmed and rsiL and cL ? color.rgb(0, 162, 5, 85): na)
  93. bgcolor(ta.crossunder(avpchange,gma) and barstate.isconfirmed and rsiS and cS ? color.rgb(207, 0, 0, 85): na)
  94. barcolor(gmaColor)
  95.  
  96. //alertcondition(ta.crossover(avpchange,gma) and barstate.isconfirmed, title="Buy Signal", message="Go Long! {{exchange}}:{{ticker}}")
  97. //alertcondition(ta.crossunder(avpchange,gma) and barstate.isconfirmed, title="Sell Signal", message="Go Short! {{exchange}}:{{ticker}}")
  98.  
  99. // Second Plot for eight day candles
  100. // plot(close, color=color.fuchsia, linewidth = 10)
  101. //dayClose = request.security(syminfo.tickerid, "8D", close)
  102. //dayOpen = request.security(syminfo.tickerid, "8D", open)
  103. //plot(dayClose, color = color.gray, title = "8D Close")
  104. //plot(dayOpen, color = color.yellow, title = "8D Open")
  105.  
  106. // ****************************************************************************************************************************************************************
  107. // Call combine signals and execute buy/sell positions within timeframe
  108. //.****************************************************************************************************************************************************************
  109. // Date Range To Include
  110. startDate = timestamp("2018-01-01T00:00")
  111. endDate = time
  112. // Check if the current timestamp is within the restricted range
  113. inRestrictedRange = time >= startDate and time <= endDate
  114. //
  115. // Buy Signals on overbought and oversold
  116. //
  117. if longCondition and inRestrictedRange
  118. strategy.entry("My Long Entry Id", strategy.long, 100)
  119. if shortCondition and inRestrictedRange
  120. strategy.entry("My Short Entry Id", strategy.short, 100)
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