Advertisement
NKactive

Specialist STC

Nov 10th, 2023
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.21 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 Specialist
  4. //@version=5
  5.  
  6. strategy("Specialist STC", overlay=false, 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. //
  18.  
  19. //STC
  20. var g_stc = "STC Settings"
  21. fastLength = input.float(31.0, title = "MACD Fast Length", step = 1)
  22. slowLength = input.float(48.0, title = "MACD Slow Length", step = 1)
  23. cycleLength = input.float(41.0, title = "Cycle Length", step = 1)
  24. upper = input.float(31.0, title = "Upper Band", step = 1)
  25. lower = input.float(24.5, title = "Lower Band", step = 1)
  26. fastLengthInt = int(fastLength)
  27. slowLengthInt = int(slowLength)
  28. cycleLengthInt = int(cycleLength)
  29. macd = ta.ema(close, fastLengthInt) - ta.ema(close, slowLengthInt)
  30. k = nz(fixnan(ta.stoch(macd, macd, macd, cycleLengthInt)))
  31. d = ta.ema(k, 1)
  32. kd = nz(fixnan(ta.stoch(d, d, d, cycleLengthInt)))
  33. stc = ta.ema(kd, 1)
  34. stc := math.max(math.min(stc, 100), 0)
  35. stcLong = stc > lower
  36. stcShort = stc < upper
  37.  
  38. //PLOT
  39. plot(stc, color=color.blue)
  40. plot(lower, color=color.gray)
  41. plot(upper, color=color.gray)
  42. // ****************************************************************************************************************************************************************
  43.  
  44.  
  45.  
  46.  
  47. // ****************************************************************************************************************************************************************
  48. // Call combine signals and execute buy/sell positions within timeframe
  49. //.****************************************************************************************************************************************************************
  50. // Date Range To Include
  51. startDate = timestamp("2018-01-01T00:00")
  52. endDate = time
  53. // Check if the current timestamp is within the restricted range
  54. inRestrictedRange = time >= startDate and time <= endDate
  55. //
  56. // Buy Signals on overbought and oversold
  57. //
  58. if inRestrictedRange and stcLong// ADD OTHER BUY SIGNAL BOOLS
  59. strategy.entry("My Long Entry Id", strategy.long, 100)
  60. if inRestrictedRange and stcShort // ADD OTHER BUY SIGNAL BOOLS
  61. strategy.entry("My Short Entry Id", strategy.short, 100)
  62.  
  63.  
  64.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement