warriorofbtc

Untitled

Dec 4th, 2023
85
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.58 KB | None | 0 0
  1. //@version=5
  2. strategy(title="STAGGONAUT .12.23", initial_capital=10000, slippage=1, default_qty_value=100, pyramiding=0, default_qty_type=strategy.percent_of_equity, process_orders_on_close=true,shorttitle="STGN", format=format.price, precision=4)
  3.  
  4. useDateFilter = input.bool(true, title="Filter Date Range of Backtest",
  5. group="Backtest Time Period")
  6. backtestStartDate = input.time(timestamp("1 Jan 2018"),
  7. title="Start Date", group="Backtest Time Period",
  8. tooltip="This start date is in the time zone of the exchange " +
  9. "where the chart's instrument trades. It doesn't use the time " +
  10. "zone of the chart or of your computer.")
  11. backtestEndDate = input.time(timestamp("1 Jan 2092"),
  12. title="End Date", group="Backtest Time Period",
  13. tooltip="This end date is in the time zone of the exchange " +
  14. "where the chart's instrument trades. It doesn't use the time " +
  15. "zone of the chart or of your computer.")
  16.  
  17. //Range Conditions
  18. inDateRange = not useDateFilter or (time >= backtestStartDate and
  19. time < backtestEndDate)
  20.  
  21. //_________________________________________________________________________________________________________________
  22. //_________________________________________________________________________________________________________________
  23. //_________________________________________________________________________________________________________________
  24. //_________________________________________________________________________________________________________________
  25.  
  26. ///////////////////////////////////////////////////////////////STC
  27.  
  28.  
  29.  
  30. // STC Indicator
  31. fastLength = input(title='MACD Fast Length', defval=9,group = "STC")
  32. slowLength = input(title='MACD Slow Length', defval=34,group = "STC")
  33. cycleLength = input(title='Cycle Length', defval=11,group = "STC")
  34. d1Length = input(title='1st %D Length', defval=1,group = "STC")
  35. d2Length = input(title='2nd %D Length', defval=4,group = "STC")
  36. src = close
  37. upper = 75
  38. lower = 25
  39.  
  40. macd = ta.ema(src, fastLength) - ta.ema(src, slowLength)
  41. k = nz(fixnan(ta.stoch(macd, macd, macd, cycleLength)))
  42. d = ta.ema(k, d1Length)
  43. kd = nz(fixnan(ta.stoch(d, d, d, cycleLength)))
  44. stc = ta.ema(kd, d2Length)
  45. stc := math.max(math.min(stc, 100), 0)
  46.  
  47.  
  48. STCLong = ta.crossover(stc, lower)
  49. STCShort = ta.crossunder(stc, upper)
  50.  
  51.  
  52. //RSI
  53. timeframersi = input.string("1D", "Days", ["1D", "2D", "3D", "4D", "5D", "6D", "7D"],group = "RSI Settings")
  54. ma(source, length, type) =>
  55. switch type
  56. "SMA" => ta.sma(source, length)
  57. "EMA" => ta.ema(source, length)
  58. "SMMA (RMA)" => ta.rma(source, length)
  59. "WMA" => ta.wma(source, length)
  60. "VWMA" => ta.vwma(source, length)
  61.  
  62. // RSI Settings
  63. rsiLengthInput = input.int(24, minval=1, title="RSI Length", group="RSI Settings")
  64. rsiSourceInput = input.source(close, "Source", group="RSI Settings")
  65.  
  66. // Overbought and Oversold Level Inputs
  67. overboughtLevel = input.float(53, title="Overbought Level", group="RSI Settings")
  68. oversoldLevel = input.float(54, title="Oversold Level", group="RSI Settings")
  69.  
  70. // RSI Calculation
  71. up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
  72. down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
  73. rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
  74.  
  75. // SMA and EMA Length Inputs
  76. //smaLength = input.int(14, title="SMA Length")
  77. emaLength = input.int(14, title="EMA Length")
  78.  
  79. // SMA and EMA of RSI
  80. //smaRsi = ta.sma(rsi, smaLength)
  81. emaRsi = ta.ema(rsi, emaLength)
  82.  
  83.  
  84. //plot(smaRsi, color=color.green, title="SMA of RSI")
  85. plot(emaRsi, color=color.red, title="EMA of RSI")
  86. plot(rsi, "RSI", color=color.rgb(243, 173, 33))
  87. //hline(overboughtLevel, "Overbought Level", color=color.red)
  88. //hline(oversoldLevel, "Oversold Level", color=color.green)
  89.  
  90. Longrsi = rsi > emaRsi //ta.crossover(rsi,oversoldLevel)
  91. Shortrsi = rsi <emaRsi //ta.crossunder(rsi,overboughtLevel)
  92.  
  93. longrsi = request.security(syminfo.tickerid,timeframersi,Longrsi)
  94. shortrsi = request.security(syminfo.tickerid,timeframersi,Shortrsi)
  95.  
  96. //BB%
  97.  
  98. timeframebb = input.string("2D", "Days", ["1D", "2D", "3D", "4D", "5D", "6D", "7D"],group = "BB Settings")
  99. length_bb = input.int(24 , title="BB Length",group = "BB Settings")
  100. mult = 2
  101. src_bb = input(close, title="BB Source",group = "BB Settings")
  102. basis = ta.sma(src_bb, length_bb)
  103. dev = mult * ta.stdev(src_bb, length_bb)
  104. upper_bb = basis + dev
  105. lower_bb = basis - dev
  106. bb_percent = (src_bb - lower_bb) / (upper_bb - lower_bb)
  107.  
  108. bb_Long = bb_percent > 0.5
  109. bb_Short = bb_percent < 0.5
  110. bb_Long_cn = request.security(syminfo.tickerid,timeframebb,bb_Long)
  111. bb_Short_cn = request.security(syminfo.tickerid,timeframebb,bb_Short)
  112.  
  113. //AFR
  114.  
  115. p = input(100, "Period",group= "AFR")
  116. atr_factor = input.float(0.9, "Factor", step = 0.005,group= "AFR")
  117.  
  118. // Calculations
  119. atr = ta.atr(p)
  120. e = atr * atr_factor
  121.  
  122. afr = close
  123. afr := nz(afr[1], afr)
  124.  
  125. atr_factoryHigh = close + e
  126. atr_factoryLow = close - e
  127.  
  128. if atr_factoryLow > afr
  129. afr := atr_factoryLow
  130. if atr_factoryHigh < afr
  131. afr := atr_factoryHigh
  132.  
  133.  
  134. buy = afr > afr[1] and not (afr[1] > afr[2])
  135. sell = afr < afr[1] and not (afr[1] < afr[2])
  136. ls = 0
  137. ls := buy ? 1 : sell ? -1 : ls[1]
  138.  
  139.  
  140. AFRLong = buy and ls != ls[1]
  141. AFRShort = sell and ls != ls[1]
  142.  
  143. //Super
  144.  
  145. atrPeriod = input.int(1, "ATR Length", minval = 1,group= "SUPER")
  146. factor = input.float(1, "Factor", minval = 0.01, step = 0.01,group= "SUPER")
  147.  
  148. [supertrend, direction] = ta.supertrend(factor, atrPeriod)
  149.  
  150. superlong = direction < 0
  151. supershort = direction > 0
  152.  
  153. // TRADE CONDITIONS
  154. moon = (longrsi and superlong)
  155. hades = STCShort and supershort
  156.  
  157. // Strategy Execution
  158. if moon and inDateRange
  159. strategy.entry("Long", strategy.long)
  160.  
  161. if hades and inDateRange
  162. strategy.entry("Short", strategy.short)
  163.  
  164. import EliCobra/CobraMetrics/4 as cobra
  165. //// PLOT DATA
  166.  
  167. 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 = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  168. 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 = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  169. type_table = input.string("Simple", "Table Type", options = ["Full", "Simple", "None"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  170.  
  171. plot(cobra.curve(disp_ind))
  172. cobra.cobraTable(type_table, pos_table)
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