warriorofbtc

Untitled

Nov 25th, 2023
203
0
Never
1
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.43 KB | None | 0 0
  1. //@version=5
  2. strategy("TPI LIKE BTC STRAT", initial_capital=10000, slippage=1, default_qty_value=100, pyramiding=0, default_qty_type=strategy.percent_of_equity, process_orders_on_close=true, shorttitle="TPI STRAT BTC", overlay=true)
  3.  
  4. // Backtest Code
  5. useDateFilter = input.bool(true, title="Filter Date Range of Backtest",
  6. group="Backtest Time Period")
  7. backtestStartDate = input.time(timestamp("1 Jan 2018"),
  8. title="Start Date", group="Backtest Time Period")
  9. backtestEndDate = input.time(timestamp("1 Jan 2092"),
  10. title="End Date", group="Backtest Time Period")
  11. inDateRange = not useDateFilter or (time >= backtestStartDate and
  12. time < backtestEndDate)
  13.  
  14.  
  15. // BOLLINGER BANDS %
  16.  
  17. //Inputs
  18. timeframebb = input.string("2D", "Days", ["1D", "2D", "3D", "4D", "5D", "6D", "7D"],group = "BB%")
  19. length_bb = input.int(20, title="BB Length",group = "BB%")
  20. src_bb = input(close, title="BB Source",group = "BB%")
  21.  
  22. //Calculations
  23. mult = 2
  24. basis = ta.sma(src_bb, length_bb)
  25. dev = mult * ta.stdev(src_bb, length_bb)
  26. upper_bb = basis + dev
  27. lower_bb = basis - dev
  28. bb_percent = (src_bb - lower_bb) / (upper_bb - lower_bb)
  29.  
  30. //Conditions
  31. bb_Long = bb_percent > 0.5
  32. bb_Short = bb_percent < 0.5
  33. bb_Long_cn = request.security(syminfo.tickerid,timeframebb,bb_Long)
  34. bb_Short_cn = request.security(syminfo.tickerid,timeframebb,bb_Short)
  35.  
  36. var vbb = 0
  37. if bb_Long_cn
  38. vbb := 1
  39. if bb_Short_cn
  40. vbb := -1
  41.  
  42. ////////////////////////// RSI ///////////////////////////////////
  43. timeframersi = input.string("2D", "Days", ["1D", "2D", "3D", "4D", "5D", "6D", "7D"],group = "RSI")
  44. ma(source, length, type) =>
  45. switch type
  46. "SMA" => ta.sma(source, length)
  47. "EMA" => ta.ema(source, length)
  48.  
  49. rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI")
  50. rsiSourceInput = input.source(close, "Source", group="RSI")
  51. maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="RSI")
  52. maLengthInput = input.int(14, title="MA Length", group="RSI")
  53. upRSI = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
  54. downRSI = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
  55. rsi = downRSI == 0 ? 100 : upRSI == 0 ? 0 : 100 - (100 / (1 + upRSI / downRSI))
  56. rsiMA = ma(rsi, maLengthInput, maTypeInput)
  57. RSILong = rsi > rsiMA
  58. RSIShort = rsi < rsiMA
  59. RSILONG_cn1 = request.security(syminfo.tickerid,timeframersi,RSILong)
  60. RSISHORT_cn1 = request.security(syminfo.tickerid,timeframersi,RSIShort)
  61.  
  62. var vrsi = 0
  63. if RSILONG_cn1
  64. vrsi := 1
  65. if RSISHORT_cn1
  66. vrsi := -1
  67.  
  68.  
  69. ///////////////////////////////////Supertrend ///////////////////////////////////////
  70. atrPeriod = input.int(10, "ATR Length", minval = 1, group = "Supertrend")
  71. factor = input.float(3.0, "Factor", minval = 0.01, step = 0.01, group = "Supertrend")
  72. [supertrend, direction] = ta.supertrend(factor, atrPeriod)
  73. supertrend := barstate.isfirst ? na : supertrend
  74. bodyMiddle = plot(barstate.isfirst ? na : (open + close) / 2, "Body Middle",display = display.none)
  75. superon = direction < 0
  76. superoff = direction > 0
  77.  
  78. var vsuper = 0
  79. if superon
  80. vsuper := 1
  81. if superoff
  82. vsuper := -1
  83.  
  84. ///////////////////////////////////////// STC ////////////////////////////////////////////
  85. import TradingView/ta/5
  86. STC_len = input.int(12, "STC Length")
  87. STC_fast = input.int(26, "Fast Length")
  88. STC_slow = input.int(50, "Slow Length")
  89. STC = ta.stc(close, STC_fast, STC_slow, STC_len, 3, 3)
  90.  
  91. STC_Long = STC > STC[1]
  92. STC_Short = STC < STC[1]
  93.  
  94. var vstc = 0
  95. if STC_Long
  96. vstc := 1
  97. if STC_Short
  98. vstc := -1
  99.  
  100. ////////////////////////Stochastic /////////////////////
  101. smoothK = input.int(3, "K", minval=1, group = "S RSI" )
  102. smoothD = input.int(3, "D", minval=1, group = "S RSI")
  103. lengthRSI = input.int(14, "RSI Length", minval=1, group = "S RSI")
  104. lengthStoch = input.int(14, "Stochastic Length", minval=1, group = "S RSI")
  105. src = input(close, title="RSI Source" )
  106. rsi1 = ta.rsi(src, lengthRSI)
  107. k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
  108. d = ta.sma(k, smoothD)
  109. timeframestoch = input.string("2D", "Days", ["1D", "2D", "3D", "4D", "5D", "6D", "7D"],group = "Stochastic")
  110. stchlongcn = request.security(syminfo.tickerid,timeframestoch,ta.crossover(k, d))
  111. stchshortcn = request.security(syminfo.tickerid,timeframestoch,ta.crossunder(k, d))
  112.  
  113. var vstch = 0
  114. if stchlongcn
  115. vstch := 1
  116. if stchshortcn
  117. vstch := -1
  118. ///////////////////////DMI////////////////////////////
  119. timeframedmi = input.string("2D", "Times", ["1D", "2D", "3D", "4D", "5D", "6D", "7D"],group = "DMI")
  120. lensig = input.int(14, title="ADX Smoothing", minval=1, maxval=50,group = "DMI")
  121. lendmi = input.int(14, minval=1, title="DI Length",group = "DMI")
  122. up = ta.change(high)
  123. down = -ta.change(low)
  124. plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
  125. minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
  126. trur = ta.rma(ta.tr, lendmi)
  127. plus = fixnan(100 * ta.rma(plusDM, lendmi) / trur)
  128. minus = fixnan(100 * ta.rma(minusDM, lendmi) / trur)
  129. sum = plus + minus
  130. adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), lensig)
  131.  
  132. dmilong = ta.crossover(plus,minus) and ta.crossover(plus,adx)
  133. dmishort = ta.crossunder(plus,minus) and ta.crossover (minus,adx)
  134.  
  135. dmilongcn = request.security(syminfo.tickerid,timeframedmi,dmilong)
  136. dmishortcn =request.security(syminfo.tickerid,timeframedmi,dmishort)
  137.  
  138. var vdmi = 0
  139. if dmilongcn
  140. vdmi := 1
  141. if dmishort
  142. vdmi := -1
  143.  
  144. ///////////////////////FISHER/////////////////////////
  145. len = input.int(9, minval=1, title="Length",group = "Fisher")
  146. timeframefish = input.string("2D", "Times", ["1D", "2D", "3D", "4D", "5D", "6D", "7D"],group = "Fisher")
  147. high_ = ta.highest(hl2, len)
  148. low_ = ta.lowest(hl2, len)
  149. round_(val) => val > .99 ? .999 : val < -.99 ? -.999 : val
  150. value = 0.0
  151. value := round_(.66 * ((hl2 - low_) / (high_ - low_) - .5) + .67 * nz(value[1]))
  152. fish1 = 0.0
  153. fish1 := .5 * math.log((1 + value) / (1 - value)) + .5 * nz(fish1[1])
  154. fish2 = fish1[1]
  155. fishl= fish1 > fish2
  156. fishs= fish1 < fish2
  157.  
  158. fishlong = request.security(syminfo.tickerid,timeframefish,fishl)
  159. fishshort = request.security(syminfo.tickerid,timeframefish,fishs)
  160.  
  161. var vfish = 0
  162. if fishlong
  163. vfish := 1
  164. if fishshort
  165. vfish :=-1
  166.  
  167.  
  168. //Sum of values
  169. //Trend = math.avg(vbb,vrsi,vsuper,vstc,vstch,vfish,vcmf,vdmi)
  170. Trend = math.avg (vrsi,vstc,vbb)
  171. Trend_Bull = ta.crossover(Trend, 0)
  172. Trend_Bear = ta.crossunder(Trend, 0)
  173. //Define Trade Conditions
  174. trendlong = Trend_Bull
  175. trendshort =Trend_Bear
  176.  
  177. if trendlong and inDateRange
  178. strategy.entry("VALHALLA", strategy.long)
  179.  
  180. if trendshort and inDateRange
  181. strategy.entry("TARTAROS", strategy.short)
  182.  
  183. import EliCobra/CobraMetrics/4 as cobra
  184. //// PLOT DATA
  185.  
  186. 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 = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  187. 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 = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  188. type_table = input.string("Full", "Table Type", options = ["Full", "Simple", "None"], group = "🐍 𝓒𝓸𝓫𝓻𝓪 𝓜𝓮𝓽𝓻𝓲𝓬𝓼 🐍")
  189.  
  190. plot(cobra.curve(disp_ind))
  191. 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