Advertisement
danucante

Untitled

Nov 26th, 2023
159
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.45 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. // © Jackoooomate
  3.  
  4. //@version=5
  5. strategy("BTC STRAT 2", overlay=true, pyramiding = 0, slippage = 1, initial_capital = 100, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)
  6.  
  7. // Plot Cobra Metrics Table
  8. import EliCobra/CobraMetrics/4 as cobra
  9.  
  10.  
  11. disp_ind = input.string ("Equity" , title = "Display Curve" , tooltip = "Choose which data you would like to display", options=["Strategy", "Equity", "Open Profit", "Gross Profit", "Net Profit", "None"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  12. pos_table = input.string("Bottom Right", "Table Position", options = ["Top Left", "Middle Left", "Bottom Left", "Top Right", "Middle Right", "Bottom Right", "Top Center", "Bottom Center"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  13. type_table = input.string("Full", "Table Type", options = ["Full", "Simple", "None"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  14.  
  15. plot(cobra.curve(disp_ind))
  16. cobra.cobraTable(type_table, pos_table)
  17.  
  18. // Time Range
  19. startTime = input.time(defval = timestamp("01 January 2018"), title = "Start Date")
  20. isInTimeRange = time >= startTime
  21.  
  22.  
  23. //////////////////////////////////////////////////////////////////////////Main indicators////////////////////////////////////////////////////////////////////////
  24.  
  25.  
  26. // ****************************************************************************************************************************************************************
  27. // FranDMI
  28. // ****************************************************************************************************************************************************************
  29.  
  30.  
  31. lensig = input.int(8, title="ADX Smoothing", minval=1, maxval=50)
  32. lenDmi = input.int(5, minval=1, title="DI Length")
  33. upD = ta.change(high)
  34. downD = -ta.change(low)
  35. plusDM = na(upD) ? na : (upD > downD and upD > 0 ? upD : 0)
  36. minusDM = na(downD) ? na : (downD > upD and downD > 0 ? downD : 0)
  37. trur = ta.rma(ta.tr, lenDmi)
  38. plus = fixnan(550 * ta.rma(plusDM, lenDmi) / trur)
  39. minus = fixnan(500 * ta.rma(minusDM, lenDmi) / trur)
  40. sum = plus + minus
  41. adx = 520 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), lensig)
  42.  
  43. buyFranDMI = ta.cross(adx, plus)
  44. sellFranDMI = ta.cross(adx, minus)
  45.  
  46. plot(adx, color=color.red)
  47. plot(plus, color=color.gray)
  48. plot(minus, color=color.gray)
  49.  
  50. // ****************************************************************************************************************************************************************
  51. // Call combine signals and execute buy/sell positions within timeframe
  52. //.****************************************************************************************************************************************************************
  53. // Set Buy/Sell Condition
  54.  
  55. goLong = buyFranDMI
  56. goShort = sellFranDMI
  57.  
  58.  
  59.  
  60. // ****************************************************************************************************************************************************************
  61. //MACD
  62. // ****************************************************************************************************************************************************************
  63.  
  64. // Inputs
  65. FastLength = input(title="MACD Fast Length", group="MACD", defval=47)
  66. Slowlength = input(title="MACD Slow Length", group="MACD", defval=79)
  67. MACDLength = input(title="MACD Signal Length", group="MACD", defval=29)
  68. thresholdMACD = input.int(title="MACD Threshold", group="MACD", defval=0)
  69. timeframe=input.timeframe(defval ='1D', group = "MACD", tooltip = "Select a different timeframe for this series") // Use Alternative timeframe
  70.  
  71. MACD = request.security(syminfo.tickerid,timeframe , ta.ema(close, FastLength)) - request.security(syminfo.tickerid,timeframe , ta.ema(close, Slowlength))
  72. aMACD = request.security(syminfo.tickerid,timeframe , ta.ema(MACD, MACDLength))
  73. delta = MACD - aMACD
  74.  
  75. // Testing plots
  76. //plot(MACD, color = color.blue)
  77. //plot(aMACD, color = color.red)
  78. plot(thresholdMACD, color = color.gray)
  79. plot(delta, color = color.green)
  80.  
  81. // Calculate Buy/Sell orders intermittently
  82. LongMACD = ta.crossover(delta, thresholdMACD)
  83. ShortMACD = ta.crossunder(delta, thresholdMACD)
  84.  
  85. // Calculate Buy/Sell orders intermittently
  86. //LongMACD = delta > thresholdMACD ? true : false
  87. //ShortMACD = delta < thresholdMACD ? true : false
  88.  
  89. //////////////////////////////////////////////////////////////////
  90.  
  91. // ****************************************************************************************************************************************************************
  92. // EverPSAR
  93. // ****************************************************************************************************************************************************************
  94.  
  95. start = input.float(title='Start', step=0.001, defval=0.02)
  96. increment = input.float(title='Increment', step=0.001, defval=0.02)
  97. maximum = input.float(title='Maximum', step=0.01, defval=0.2)
  98. width = input.int(title='Point Width', minval=1, defval=2)
  99. highlightStartPoints = input(title='Highlight Start Points ?', defval=true)
  100. showLabels = input(title='Show Buy/Sell Labels ?', defval=true)
  101. highlightState = input(title='Highlight State ?', defval=true)
  102.  
  103. psar = ta.sar(start, increment, maximum)
  104. dir = psar < close ? 1 : -1
  105.  
  106. buyPSAR = dir == 1 and dir[1] == -1
  107. sellPSAR = dir == -1 and dir[1] == 1
  108.  
  109. //Plots
  110. psarColor = dir == 1 ? #3388bb : #fdcc02
  111. psarPlot = plot(psar, title='PSAR', style=plot.style_circles, linewidth=width, color=color.new(psarColor, 0))
  112. var color longColor = color.green
  113. var color shortColor = color.red
  114. // Buy Plots
  115. plotshape(buyPSAR and highlightStartPoints ? psar : na, title='Long Start', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(longColor, 50))
  116. plotshape(buyPSAR and showLabels ? psar : na, title='Buy Label', text='Buy', location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(longColor, 50), textcolor=color.new(color.white, 0))
  117. // Sell Plots
  118. plotshape(sellPSAR and highlightStartPoints ? psar : na, title='Short Start', location=location.absolute, style=shape.circle, size=size.tiny, color=color.new(shortColor, 50))
  119. plotshape(sellPSAR and showLabels ? psar : na, title='Sell Label', text='Sell', location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(shortColor, 50), textcolor=color.new(color.white, 0))
  120. midPricePlot = plot(ohlc4, title='', display=display.none)
  121. fillColor = highlightState ? dir == 1 ? longColor : shortColor : na
  122. fill(midPricePlot, psarPlot, title='Trade State Filling', color=color.new(fillColor, 75))
  123.  
  124. ////////////////////////////////////////////////////////
  125. src12= input.source(hlcc4, group= 'rsi')
  126. rsiLength= input.int(11, group= 'rsi')
  127. rsi = ta.rsi(src12, rsiLength)
  128.  
  129. ysell= input.int(61)
  130. ybuy= input.int(54)
  131.  
  132. longRSI = rsi > ybuy
  133. shortRSI = rsi < ysell
  134.  
  135.  
  136. // Date Range To Include
  137. startDate = timestamp("2018-01-01T00:00")
  138. endDate = time
  139. // Check if the current timestamp is within the restricted range
  140. inRestrictedRange = time >= startDate and time <= endDate
  141. //
  142. // Buy Signals on overbought and oversold
  143. //
  144. if inRestrictedRange and (buyPSAR and LongMACD or buyFranDMI ) and (buyFranDMI or LongMACD and longRSI)
  145. strategy.entry("LONG MATE ", strategy.long)
  146. if inRestrictedRange and (sellFranDMI and ShortMACD or (sellPSAR and shortRSI) )
  147. strategy.entry("SHORT MATE", strategy.short)
  148.  
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