Advertisement
NKactive

NKCoralTrendBTC

Nov 11th, 2023 (edited)
163
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 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
  3. // Original code from LazyBear
  4. //@version=5
  5.  
  6. strategy("NKCoralTrendBTC", overlay=true, initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=0, slippage=1)
  7.  
  8. import EliCobra/CobraMetrics/4 as cobra
  9. //// PLOT DATA
  10. 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 = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  11. 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 = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  12. type_table = input.string("None", "Table Type", options = ["Full", "Simple", "None"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  13. plot(cobra.curve(disp_ind))
  14. cobra.cobraTable(type_table, pos_table)
  15. //
  16. // ****************************************************************************************************************************************************************
  17. // Coral Trend
  18. // ****************************************************************************************************************************************************************
  19. //
  20. // Inputs
  21. sm =input(21, title="Smoothing Period", group = "CoralTrend")
  22. cd = input(0.6, title="Constant D", group = "CoralTrend")
  23. ribm=input(false, title="Ribbon Mode", group = "CoralTrend")
  24. timeframe=input.timeframe(defval ='1D', group = "CoralTrend")
  25.  
  26. //initialise vars
  27. var float i1 = na
  28. var float i2 = na
  29. var float i3 = na
  30. var float i4 = na
  31. var float i5 = na
  32. var float i6 = na
  33.  
  34. src=request.security(syminfo.tickerid,timeframe, close)
  35.  
  36. di = (sm - 1.0) / 2.0 + 1.0
  37. c1 = 2 / (di + 1.0)
  38. c2 = 1 - c1
  39. c3 = 3.0 * (cd * cd + cd * cd * cd)
  40. c4 = -3.0 * (2.0 * cd * cd + cd + cd * cd * cd)
  41. c5 = 3.0 * cd + 1.0 + cd * cd * cd + 3.0 * cd * cd
  42.  
  43. i1 := c1*src + c2*nz(i1[1])
  44. i2 := c1*i1 + c2*nz(i2[1])
  45. i3 := c1*i2 + c2*nz(i3[1])
  46. i4 := c1*i3 + c2*nz(i4[1])
  47. i5 := c1*i4 + c2*nz(i5[1])
  48. i6 := c1*i5 + c2*nz(i6[1])
  49.  
  50. bfr = -cd*cd*cd*i6 + c3*(i5) + c4*(i4) + c5*(i3)
  51.  
  52. CoralLong = bfr > nz(bfr[1])?true:false
  53. CoralShort = bfr < nz(bfr[1])?true:false
  54.  
  55. // --------------------------------------------------------------------------
  56. // Plots arrows above/below price to show whene it fires
  57. // --------------------------------------------------------------------------
  58. plotshape(series=ribm ? na : (CoralLong ? bfr : na), title="Trend Up", style=shape.triangleup, location=location.belowbar,color=color.green)
  59. plotshape(series=ribm ? na : (CoralShort ? bfr : na), title="Trend Down", style=shape.triangledown, location=location.abovebar, color=color.red)
  60. //
  61. CoralLong := request.security(syminfo.tickerid,timeframe, CoralLong)
  62. CoralShort := request.security(syminfo.tickerid,timeframe,CoralShort)
  63. //
  64. // ****************************************************************************************************************************************************************
  65. // Call combine signals and execute buy/sell positions within timeframe
  66. //.****************************************************************************************************************************************************************
  67. // Date Range To Include
  68. startDate = timestamp("2018-01-01T00:00")
  69. endDate = time
  70. // Check if the current timestamp is within the restricted range
  71. inRestrictedRange = time >= startDate and time <= endDate
  72. //
  73. // Buy Signals on overbought and oversold
  74. //
  75. if inRestrictedRange and CoralLong // ADD OTHER BUY SIGNAL BOOLS
  76. strategy.entry("My Long Entry Id", strategy.long, 100)
  77. if inRestrictedRange and CoralShort // ADD OTHER BUY SIGNAL BOOLS
  78. strategy.entry("My Short Entry Id", strategy.short, 100)
  79.  
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