Advertisement
NKactive

Untitled

Aug 16th, 2023
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.05 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. // © Specalist333
  3.  
  4. //@version=5
  5. strategy("BTC Specalist V1", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, pyramiding=0, slippage=1)
  6.  
  7. // Date Range (and limits start date for level 1 submission)
  8. start_date = input.int(title='Start Date', defval=1, minval=1, maxval=31, group='Date Range', inline='1')
  9. end_date = input.int(title='End Date', defval=1, minval=1, maxval=31, group='Date Range', inline='1')
  10. start_month = input.int(title='Start Month', defval=1, minval=1, maxval=12, group='Date Range', inline='2')
  11. end_month = input.int(title='End Month', defval=1, minval=1, maxval=12, group='Date Range', inline='2')
  12. start_year = input.int(title='Start Year', defval=2018, minval=1800, maxval=3000, group='Date Range', inline='3')
  13. end_year = input.int(title='End Year', defval=2024, minval=1800, maxval=3000, group='Date Range', inline='3')
  14. in_date_range = time >= timestamp(syminfo.timezone, start_year, start_month, start_date, 0, 0) and time < timestamp(syminfo.timezone, end_year, end_month, end_date, 0, 0)
  15.  
  16. // Inport cobra
  17. import EliCobra/CobraMetrics/4 as cobra
  18.  
  19. //// PLOT DATA
  20.  
  21. 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 = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  22. 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 = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  23. type_table = input.string("None", "Table Type", options = ["Full", "Simple", "None"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  24.  
  25. plot(cobra.curve(disp_ind))
  26. cobra.cobraTable(type_table, pos_table)
  27.  
  28. //EMAs
  29. // - EMA1 superfast
  30. // - EMA2 slow
  31. // - EMA1 very slow
  32. EMA_Length_1 = input.int(title="EMA 1 Length", group="EMA", defval=5)
  33. EMA_Length_2 = input.int(title="EMA 2 Length", group="EMA", defval=50)
  34. EMA_Length_3 = input.int(title="EMA 3 Length", group="EMA", defval=98)
  35.  
  36. EMA1 = ta.ema(close, EMA_Length_1)
  37. EMA2 = ta.ema(close, EMA_Length_2)
  38. EMA3 = ta.ema(close, EMA_Length_3)
  39. // Use these plots to visualise what the code is doing
  40. //plot(EMA1, color=color.red, title = "EMA1", linewidth=10) // NK Debug
  41. //plot(EMA2, color=color.white, title = "EMA2", linewidth=5)// NK Debug
  42. //plot(EMA3, color=color.blue, title = "EMA3", linewidth=2) // NK Debug
  43.  
  44. // Price Volatility
  45. // Calcualtes the price volatility giving extrream +ve value for upwards trends and -ve for downward trends
  46. // volatilityLower and volatilityHigher used later to filter
  47. volatilityLower = input.float(title = "Lower Range", defval= -39, group = "VRG")
  48. volatilityHigher = input.float(title = "Higher Range", defval= 9)
  49. volatilityLength = 58
  50. volatilityRange = ta.sma(close - open, volatilityLength)
  51. // Use this plot to visualise what the code is doing
  52. // plot(volatilityRange, color=color.fuchsia, title = "sma")// NK Debug
  53.  
  54. //MACD
  55. FastLength = input(title="MACD Fast Length", group="MACD", defval=56)
  56. Slowlength = input(title="MACD Slow Length", group="MACD", defval=73)
  57. MACDLength = input(title="MACD Signal Length", group="MACD", defval=26)
  58.  
  59. MACD = ta.ema(close, FastLength) - ta.ema(close, Slowlength)
  60. aMACD = ta.ema(MACD, MACDLength)
  61. delta = MACD - aMACD
  62. // Use these plots to visualise what the code is doing
  63. //plot(MACD, color=color.red, title = "MACD", linewidth=10) // NK Debug
  64. //plot(aMACD, color=color.white, title = "aMACD", linewidth=5) // NK Debug
  65. //plot(delta, color=color.blue, title = "delta", linewidth=10) // NK Debug
  66.  
  67. //STRATEGY PARAMETERS
  68. start= timestamp(2012,1,1,0,0)
  69. timeCond = time > start
  70.  
  71. // Picking up ANY possible buy/sell signal using all EMAs
  72. LongEMA = ta.crossover(EMA1, EMA2) or ta.crossover(EMA1, EMA3) or ta.crossover(EMA2, EMA3)
  73. ShortEMA = ta.crossunder(EMA1, EMA2) or ta.crossunder(EMA1, EMA3) or ta.crossunder(EMA2, EMA3)
  74.  
  75. // Using the differnce between the MACDs to find buy/sell signals
  76. LongMACD = ta.crossover(delta, 0)
  77. ShortMACD = ta.crossunder(delta, 0)
  78.  
  79. // Checks Market Direction
  80. VRL = volatilityRange > volatilityLower
  81. VRS = volatilityRange < volatilityHigher
  82.  
  83. // Builds bool for buy/sell based on individual indictor calculations
  84. Long = (LongMACD and LongEMA) or (LongMACD and VRL) or (LongEMA and VRL)
  85. Short = (ShortMACD and ShortEMA) or (ShortMACD and VRS) or (ShortEMA and VRS)
  86.  
  87. strategy.entry("Open Long", strategy.long, when=Long and in_date_range)
  88. strategy.entry("Open Short", strategy.short, when=Short and in_date_range)
  89.  
  90. //these strategy.entry commands are fine but will be phased out in future iterations
  91. // I have added 100% of euqity to the entry to avoid margin calls
  92. //if Long and in_date_range
  93. // strategy.entry("Open Long", strategy.long, 100)
  94. //if Short and in_date_range
  95. // strategy.entry("Open Short", strategy.short, 100)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement