Advertisement
NKactive

NK Michael's EMA BTC

Nov 17th, 2023
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.51 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 (replace with your name)
  3. // Original source code belongs to TopG Professor Michael from The Real World.
  4. //@version=5
  5. strategy("NK Michael's EMA BTC", 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. // NK Michael's EMA
  17. // ****************************************************************************************************************************************************************
  18.  
  19. // Inputs
  20. timeframe=input.timeframe(defval ='2D', group = "MichaelsEMA", tooltip = "Select a different timeframe for this series") // Use Alternative timeframe
  21. emaS_value = input.int(12, minval=1, title="EMA Small - Value", group = "MichaelsEMA")
  22. emaB_value = input.int(21, minval=1, title="EMA Big - Value", group = "MichaelsEMA")
  23.  
  24. // Get close from selected timeframe
  25. src = request.security(syminfo.tickerid,timeframe, close)
  26. emaS = request.security(syminfo.tickerid,timeframe, ta.ema(close, emaS_value))
  27. emaB = request.security(syminfo.tickerid,timeframe, ta.ema(close, emaB_value))
  28.  
  29. // Rules For Up and Down EMA trends
  30. EMA_UpTrend = emaS >= emaB
  31. EMA_DownTrend = emaS < emaB
  32.  
  33. // Plot EMAs on chart
  34. EMA_UpTrend_color = color.green
  35. EMA_DownTrend_color = #ff0000
  36. plot(emaS, color=color.new(EMA_UpTrend ? EMA_UpTrend_color : EMA_DownTrend_color, 0), title="EMA Small", style=plot.style_line, linewidth=1, offset=0)
  37. plot(emaB, color=color.new(EMA_UpTrend ? EMA_UpTrend_color : EMA_DownTrend_color, 0), title="EMA Big", style=plot.style_line, linewidth=2, offset=0)
  38.  
  39. // ****************************************************************************************************************************************************************
  40. // Call combine signals and execute buy/sell positions within timeframe
  41. //.****************************************************************************************************************************************************************
  42. // Date Range To Include
  43. startDate = timestamp("2018-01-01T00:00")
  44. endDate = time
  45. // Check if the current timestamp is within the restricted range
  46. inRestrictedRange = time >= startDate and time <= endDate
  47. //
  48. // Buy Signals on overbought and oversold
  49. //
  50. if inRestrictedRange and EMA_UpTrend// ADD OTHER BUY SIGNAL BOOLS
  51. strategy.entry("My Long Entry Id", strategy.long, 100)
  52. if inRestrictedRange and EMA_DownTrend // ADD OTHER BUY SIGNAL BOOLS
  53. strategy.entry("My Short Entry Id", strategy.short, 100)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement