Advertisement
NKactive

Untitled

Aug 15th, 2023
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.75 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.  
  4. //@version=5
  5. strategy(title='[SHK] Schaff Trend Cycle (STC)', shorttitle='STC', overlay=false, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, initial_capital=1000, pyramiding=0, slippage=1)
  6.  
  7. //Library
  8. import EliCobra/CobraMetrics/4 as cobra
  9. //// PConstruct Cobra Table
  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("Full", "Table Type", options = ["Full", "Simple", "None"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  13. plot(cobra.curve(disp_ind))
  14. cobra.cobraTable(type_table, pos_table)
  15.  
  16. EEEEEE = input(12, 'Length')
  17. BBBB = input(26, 'FastLength')
  18. BBBBB = input(50, 'SlowLength')
  19.  
  20. // NK inputs for smoothing
  21. // boundary limits
  22. limitOn = input.bool(defval = false, title = 'Limit Smooth On?', group = 'Smoothing')
  23. lowLimit = input.int(defval = 25, title = 'Smoothing Low Limit', group = 'Smoothing')
  24. highLimit = input.int(defval = 75, title = 'Smoothing High Limit', group = 'Smoothing')
  25. // ema Smooth
  26. emaSmoothOn = input.bool(defval = false, title = 'ema Smooth On?', group = 'Smoothing')
  27. emaSmoothLen = input.int(defval = 12, title = 'Smoothing EMA', group = 'Smoothing')
  28. // wma Smooth
  29. wmaSmoothOn = input.bool(defval = false, title = 'wma Smooth On?', group = 'Smoothing')
  30. wmaSmoothLen = input.int(defval = 18, title = 'Smoothing WMA', group = 'Smoothing')
  31.  
  32. //Functions
  33. AAAA(BBB, BBBB, BBBBB) =>
  34. fastMA = ta.ema(BBB, BBBB)
  35. slowMA = ta.ema(BBB, BBBBB)
  36. AAAA = fastMA - slowMA
  37. AAAA
  38.  
  39. AAAAA(EEEEEE, BBBB, BBBBB) =>
  40. AAA = input.float(defval = 0.5, title = 'AAA', group = 'function', step = 0.1 )
  41. var CCCCC = 0.0
  42. var DDD = 0.0
  43. var DDDDDD = 0.0
  44. var EEEEE = 0.0
  45. BBBBBB = AAAA(close, BBBB, BBBBB)
  46. CCC = ta.lowest(BBBBBB, EEEEEE)
  47. CCCC = ta.highest(BBBBBB, EEEEEE) - CCC
  48. CCCCC := CCCC > 0 ? (BBBBBB - CCC) / CCCC * 100 : nz(CCCCC[1])
  49. DDD := na(DDD[1]) ? CCCCC : DDD[1] + AAA * (CCCCC - DDD[1])
  50. DDDD = ta.lowest(DDD, EEEEEE)
  51. DDDDD = ta.highest(DDD, EEEEEE) - DDDD
  52. DDDDDD := DDDDD > 0 ? (DDD - DDDD) / DDDDD * 100 : nz(DDDDDD[1])
  53. EEEEE := na(EEEEE[1]) ? DDDDDD : EEEEE[1] + AAA * (DDDDDD - EEEEE[1])
  54. EEEEE
  55.  
  56. // Maths
  57. mAAAAA = AAAAA(EEEEEE, BBBB, BBBBB)
  58. mColor = mAAAAA > mAAAAA[1] ? color.new(color.green, 20) : color.new(color.red, 20)
  59.  
  60. //ema and wma smoothing
  61. emaSmooth = ta.ema(mAAAAA, emaSmoothLen)
  62. plot(emaSmoothOn ? emaSmooth : na, color = color.white)
  63. wmaSmooth = ta.wma(mAAAAA, wmaSmoothLen)
  64. plot(wmaSmoothOn ? wmaSmooth : na, color = color.gray)
  65. // limit lines
  66. ll = plot(limitOn ? lowLimit : na, color=color.new(color.gray, 70), title = "LowerLimit")
  67. ul = plot(limitOn ? highLimit : na, color=color.new(color.gray, 70), title = 'UpperLimit')
  68. // fill(ul, ll, color=color.new(color.gray, 90)) // need to figure out how to use ? : to do the fill
  69.  
  70. // logic NK.active for buy and sell
  71. BuySignal = mAAAAA >= mAAAAA[1] and (((mAAAAA[1] < lowLimit) and limitOn) or not limitOn) and (((mAAAAA <= wmaSmooth) and wmaSmoothOn) or not wmaSmoothOn) and (((mAAAAA <= emaSmooth) and emaSmoothOn) or not emaSmoothOn)
  72. SellSignal = mAAAAA < mAAAAA[1] and (((mAAAAA[1] > highLimit) and limitOn) or not limitOn) and (((mAAAAA >= wmaSmooth) and wmaSmoothOn) or not wmaSmoothOn) and (((mAAAAA >= emaSmooth) and emaSmoothOn) or not emaSmoothOn)
  73. // Kept for original logic incase needed
  74. //if mAAAAA[3] <= mAAAAA[2] and mAAAAA[2] > mAAAAA[1] and mAAAAA > 75
  75. // alert("Red", alert.freq_once_per_bar)
  76. //if mAAAAA[3] >= mAAAAA[2] and mAAAAA[2] < mAAAAA[1] and mAAAAA < 25
  77. // alert("Green", alert.freq_once_per_bar)
  78.  
  79. // plot the STC line
  80. plot(mAAAAA, color=mColor, title='STC', linewidth=2)
  81.  
  82. //
  83. // Define the start and end dates for the restricted range
  84. //
  85. //startDate = timestamp("2018-01-01T00:00")
  86. startDate = timestamp("2017-12-29T00:00")
  87. endDate = time
  88. // Check if the current timestamp is within the restricted range
  89. inRestrictedRange = time >= startDate and time <= endDate
  90.  
  91. if BuySignal and inRestrictedRange
  92. strategy.entry("My Long Entry Id", strategy.long, qty = 100)
  93. if SellSignal and inRestrictedRange
  94. strategy.entry("My Short Entry Id", strategy.short, qty = 100)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement