Advertisement
danucante

Untitled

Nov 25th, 2023
81
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.04 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. // © vigilmiguel
  3.  
  4. //@version=5
  5.  
  6. strategy(title='TOTAL MACD DMI Aroon (3)', overlay=true, default_qty_type = strategy.percent_of_equity , pyramiding=1 , initial_capital = 1000000000000 , default_qty_value = 100)
  7.  
  8.  
  9. // Date Range
  10. start_date = input.int(title='Start Date', defval=1, minval=1, maxval=31, group='Date Range', inline='1')
  11. end_date = input.int(title='End Date', defval=1, minval=1, maxval=31, group='Date Range', inline='1')
  12. start_month = input.int(title='Start Month', defval=1, minval=1, maxval=12, group='Date Range', inline='2')
  13. end_month = input.int(title='End Month', defval=1, minval=1, maxval=12, group='Date Range', inline='2')
  14. start_year = input.int(title='Start Year', defval=2018, minval=1800, maxval=3000, group='Date Range', inline='3')
  15. end_year = input.int(title='End Year', defval=2024, minval=1800, maxval=3000, group='Date Range', inline='3')
  16. 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)
  17.  
  18. // Import cobra
  19. import EliCobra/CobraMetrics/4 as cobra
  20. //// PLOT DATA
  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. plot(cobra.curve(disp_ind))
  25. cobra.cobraTable(type_table, pos_table)
  26. price = close
  27. longMsg = ""
  28. shortMsg = ""
  29.  
  30. // Getting inputs
  31. fast_length = input(title="Fast Length", defval=2)
  32. slow_length = input(title="Slow Length", defval=35)
  33. src = input(title="Source", defval=close)
  34. sma_source = input.string(title="Oscillator MA Type", defval="SMA", options=["SMA", "EMA"])
  35.  
  36. // Calculating
  37. fast_ma = sma_source == "SMA" ? ta.sma(src, fast_length) : ta.ema(src, fast_length)
  38. slow_ma = sma_source == "SMA" ? ta.sma(src, slow_length) : ta.ema(src, slow_length)
  39. macd = fast_ma - slow_ma
  40.  
  41. long=ta.crossover(macd,0)
  42. short=ta.crossunder(macd,0)
  43.  
  44. if long
  45. longMsg += "MACD "
  46. if short
  47. shortMsg += "MACD "
  48. //plot(delta, title="Histogram", style=plot.style_columns, color=(delta>=0 ? (delta[1] < delta ? #26A69A : #B2DFDB) : (delta[1] < delta ? #FFCDD2 : #FF5252)))
  49.  
  50. lensig = input.int(9, title="ADX Smoothing", minval=1, maxval=50)
  51. lenDmi = input.int(6, minval=1, title="DI Length")
  52. upD = ta.change(high)
  53. downD = -ta.change(low)
  54. plusDM = na(upD) ? na : (upD > downD and upD > 0 ? upD : 0)
  55. minusDM = na(downD) ? na : (downD > upD and downD > 0 ? downD : 0)
  56. trur = ta.rma(ta.tr, lenDmi)
  57. plus = fixnan(550 * ta.rma(plusDM, lenDmi) / trur)
  58. minus = fixnan(500 * ta.rma(minusDM, lenDmi) / trur)
  59. sum = plus + minus
  60. adx = 520 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), lensig)
  61.  
  62. long_condition = ta.cross(adx, plus)
  63. short_condition = ta.cross(adx, minus)
  64.  
  65. if long_condition
  66. longMsg += "DMI "
  67. if short_condition
  68. shortMsg += "DMI "
  69.  
  70. // plot(plus, color=color.green, title="+DI")
  71. // plot(minus, color=color.red, title="-DI")
  72. // plot(adx, color=color.orange, title="ADX")
  73. // hlineup = hline(30, color=#787B86)
  74.  
  75. fastLength = input(title='MACD Fast Length', defval=9)
  76. slowLength = input(title='MACD Slow Length', defval=34)
  77. cycleLength = input(title='Cycle Length', defval=11)
  78. d1Length = input(title='1st %D Length', defval=1)
  79. d2Length = input(title='2nd %D Length', defval=4)
  80. src1 = close
  81. upper = 75
  82. lower = 25
  83.  
  84. macd1 = ta.ema(src1, fastLength) - ta.ema(src1, slowLength)
  85. k = nz(fixnan(ta.stoch(macd1, macd1, macd1, cycleLength)))
  86. d = ta.ema(k, d1Length)
  87. kd = nz(fixnan(ta.stoch(d, d, d, cycleLength)))
  88. stc = ta.ema(kd, d2Length)
  89. stc := math.max(math.min(stc, 100), 0)
  90.  
  91.  
  92. buySignal = ta.crossover(stc, lower)
  93. sellSignal = ta.crossunder(stc, upper)
  94.  
  95. if buySignal
  96. longMsg += "AROON "
  97. if sellSignal
  98. shortMsg += "AROON "
  99.  
  100.  
  101.  
  102. src12= input.source(hl2, group= 'rsi')
  103. rsiLength= input.int(11, group= 'rsi')
  104. rsi = ta.rsi(src12, rsiLength)
  105.  
  106. ysell= input.int(51)
  107. ybuy= input.int(61)
  108.  
  109. longRSI = rsi > ybuy
  110. shortRSI = rsi < ysell
  111.  
  112. SLP_long = (long or long_condition or buySignal and longRSI ) and (longRSI and long) or (longRSI and long_condition) or (longRSI and buySignal)
  113. SLP_short = (short or short_condition or sellSignal and shortRSI) and (shortRSI and short) or( shortRSI and short_condition) or (shortRSI and sellSignal)
  114.  
  115.  
  116.  
  117.  
  118. if (SLP_long and in_date_range)
  119. strategy.entry("SLP", strategy.long, comment = longMsg)
  120. else if (SLP_short and in_date_range)
  121. strategy.entry("SLP", strategy.short, comment = shortMsg)
  122.  
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