Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- 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)
- // Backtest Code
- useDateFilter = input.bool(true, title="Filter Date Range of Backtest",
- group="Backtest Time Period")
- backtestStartDate = input.time(timestamp("1 Jan 2018"),
- title="Start Date", group="Backtest Time Period")
- backtestEndDate = input.time(timestamp("1 Jan 2092"),
- title="End Date", group="Backtest Time Period")
- inDateRange = not useDateFilter or (time >= backtestStartDate and
- time < backtestEndDate)
- // BOLLINGER BANDS %
- //Inputs
- timeframebb = input.string("2D", "Days", ["1D", "2D", "3D", "4D", "5D", "6D", "7D"],group = "BB%")
- length_bb = input.int(20, title="BB Length",group = "BB%")
- src_bb = input(close, title="BB Source",group = "BB%")
- //Calculations
- mult = 2
- basis = ta.sma(src_bb, length_bb)
- dev = mult * ta.stdev(src_bb, length_bb)
- upper_bb = basis + dev
- lower_bb = basis - dev
- bb_percent = (src_bb - lower_bb) / (upper_bb - lower_bb)
- //Conditions
- bb_Long = bb_percent > 0.5
- bb_Short = bb_percent < 0.5
- bb_Long_cn = request.security(syminfo.tickerid,timeframebb,bb_Long)
- bb_Short_cn = request.security(syminfo.tickerid,timeframebb,bb_Short)
- var vbb = 0
- if bb_Long_cn
- vbb := 1
- if bb_Short_cn
- vbb := -1
- ////////////////////////// RSI ///////////////////////////////////
- timeframersi = input.string("2D", "Days", ["1D", "2D", "3D", "4D", "5D", "6D", "7D"],group = "RSI")
- ma(source, length, type) =>
- switch type
- "SMA" => ta.sma(source, length)
- "EMA" => ta.ema(source, length)
- rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI")
- rsiSourceInput = input.source(close, "Source", group="RSI")
- maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="RSI")
- maLengthInput = input.int(14, title="MA Length", group="RSI")
- upRSI = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
- downRSI = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
- rsi = downRSI == 0 ? 100 : upRSI == 0 ? 0 : 100 - (100 / (1 + upRSI / downRSI))
- rsiMA = ma(rsi, maLengthInput, maTypeInput)
- RSILong = rsi > rsiMA
- RSIShort = rsi < rsiMA
- RSILong1 = ta.crossover(rsi,rsiMA)
- RSIShort1 = ta.crossunder(rsi,rsiMA)
- RSILong2 = rsiMA > 50
- RSIShort2 = rsiMA < 50
- RSILONG_cn1 = request.security(syminfo.tickerid,timeframersi,RSILong)
- RSISHORT_cn1 = request.security(syminfo.tickerid,timeframersi,RSIShort)
- RSILONG_cn2 = request.security(syminfo.tickerid,timeframersi,RSILong1)
- RSISHORT_cn2 = request.security(syminfo.tickerid,timeframersi,RSIShort1)
- RSILONG_cn3 = request.security(syminfo.tickerid,timeframersi,RSILong2)
- RSISHORT_cn3 = request.security(syminfo.tickerid,timeframersi,RSIShort2)
- var vrsi = 0
- if RSILONG_cn1 or RSILONG_cn2 or RSILONG_cn3
- vrsi := 1
- if RSISHORT_cn1 or RSISHORT_cn2 or RSISHORT_cn3
- vrsi := -1
- ///////////////////////////////////Supertrend ///////////////////////////////////////
- atrPeriod = input.int(10, "ATR Length", minval = 1, group = "Supertrend")
- factor = input.float(3.0, "Factor", minval = 0.01, step = 0.01, group = "Supertrend")
- [supertrend, direction] = ta.supertrend(factor, atrPeriod)
- supertrend := barstate.isfirst ? na : supertrend
- bodyMiddle = plot(barstate.isfirst ? na : (open + close) / 2, "Body Middle",display = display.none)
- superon = direction < 0
- superoff = direction > 0
- var vsuper = 0
- if superon
- vsuper := 1
- if superoff
- vsuper := -1
- ///////////////////////////////////////// STC ////////////////////////////////////////////
- import TradingView/ta/5
- STC_len = input.int(12, "STC Length", group = "STC")
- STC_fast = input.int(26, "Fast Length", group = "STC")
- STC_slow = input.int(50, "Slow Length", group = "STC")
- STC = ta.stc(close, STC_fast, STC_slow, STC_len, 3, 3)
- STC_Long = STC > STC[1]
- STC_Short = STC < STC[1]
- STC_Long1 = ta.crossover(STC, STC[1])
- STC_Short1 = ta.crossunder(STC, STC[1])
- var vstc = 0
- if STC_Long or STC_Long1
- vstc := 1
- if STC_Short or STC_Short1
- vstc := -1
- ////////////////////////Stochastic /////////////////////
- smoothK = input.int(3, "K", minval=1, group = "S RSI" )
- smoothD = input.int(3, "D", minval=1, group = "S RSI")
- lengthRSI = input.int(14, "RSI Length", minval=1, group = "S RSI")
- lengthStoch = input.int(14, "Stochastic Length", minval=1, group = "S RSI")
- src = input(close, title="RSI Source" )
- rsi1 = ta.rsi(src, lengthRSI)
- k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, lengthStoch), smoothK)
- d = ta.sma(k, smoothD)
- timeframestoch = input.string("2D", "Days", ["1D", "2D", "3D", "4D", "5D", "6D", "7D"],group = "Stochastic")
- stchlongcn = request.security(syminfo.tickerid,timeframestoch,ta.crossover(k, d))
- stchshortcn = request.security(syminfo.tickerid,timeframestoch,ta.crossunder(k, d))
- var vstch = 0
- if stchlongcn
- vstch := 1
- if stchshortcn
- vstch := -1
- ///////////////////////DMI////////////////////////////
- timeframedmi = input.string("2D", "Times", ["1D", "2D", "3D", "4D", "5D", "6D", "7D"],group = "DMI")
- lensig = input.int(14, title="ADX Smoothing", minval=1, maxval=50,group = "DMI")
- lendmi = input.int(14, minval=1, title="DI Length",group = "DMI")
- up = ta.change(high)
- down = -ta.change(low)
- plusDM = na(up) ? na : (up > down and up > 0 ? up : 0)
- minusDM = na(down) ? na : (down > up and down > 0 ? down : 0)
- trur = ta.rma(ta.tr, lendmi)
- plus = fixnan(100 * ta.rma(plusDM, lendmi) / trur)
- minus = fixnan(100 * ta.rma(minusDM, lendmi) / trur)
- sum = plus + minus
- adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), lensig)
- dmilong = ta.crossover(plus,minus) and ta.crossover(plus,adx)
- dmishort = ta.crossunder(plus,minus) and ta.crossover (minus,adx)
- dmilongcn = request.security(syminfo.tickerid,timeframedmi,dmilong)
- dmishortcn =request.security(syminfo.tickerid,timeframedmi,dmishort)
- var vdmi = 0
- if dmilongcn
- vdmi := 1
- if dmishort
- vdmi := -1
- ///////////////////////FISHER/////////////////////////
- len = input.int(9, minval=1, title="Length",group = "Fisher")
- timeframefish = input.string("2D", "Times", ["1D", "2D", "3D", "4D", "5D", "6D", "7D"],group = "Fisher")
- high_ = ta.highest(hl2, len)
- low_ = ta.lowest(hl2, len)
- round_(val) => val > .99 ? .999 : val < -.99 ? -.999 : val
- value = 0.0
- value := round_(.66 * ((hl2 - low_) / (high_ - low_) - .5) + .67 * nz(value[1]))
- fish1 = 0.0
- fish1 := .5 * math.log((1 + value) / (1 - value)) + .5 * nz(fish1[1])
- fish2 = fish1[1]
- fishl= fish1 > fish2
- fishs= fish1 < fish2
- fishlong = request.security(syminfo.tickerid,timeframefish,fishl)
- fishshort = request.security(syminfo.tickerid,timeframefish,fishs)
- var vfish = 0
- if fishlong
- vfish := 1
- if fishshort
- vfish :=-1
- //Sum of values
- //Trend = math.avg(vbb,vrsi,vsuper,vstc,vstch,vfish,vcmf,vdmi)
- Trend = math.avg (vrsi,vstc,vbb,vstc,vsuper)
- Trend_Bull = ta.crossover(Trend, 0)
- Trend_Bear = ta.crossunder(Trend, 0)
- //Define Trade Conditions
- trendlong = Trend_Bull
- trendshort =Trend_Bear
- if trendlong and inDateRange
- strategy.entry("VALHALLA", strategy.long)
- if trendshort and inDateRange
- strategy.entry("TARTAROS", strategy.short)
- import EliCobra/CobraMetrics/4 as cobra
- //// PLOT DATA
- 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 = "๐ ๐๐ธ๐ซ๐ป๐ช ๐๐ฎ๐ฝ๐ป๐ฒ๐ฌ๐ผ ๐")
- 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 = "๐ ๐๐ธ๐ซ๐ป๐ช ๐๐ฎ๐ฝ๐ป๐ฒ๐ฌ๐ผ ๐")
- type_table = input.string("Full", "Table Type", options = ["Full", "Simple", "None"], group = "๐ ๐๐ธ๐ซ๐ป๐ช ๐๐ฎ๐ฝ๐ป๐ฒ๐ฌ๐ผ ๐")
- plot(cobra.curve(disp_ind))
- cobra.cobraTable(type_table, pos_table)
- // Determining the color based on the trend value
- trendColor = Trend > 0 ? color.green : color.red
- // Plotting the oscillator with dynamic color
- plot(Trend, title="Trend Oscillator", color=trendColor, linewidth=2)
- hline(0, title="Zero Line", color=color.red, linestyle=hline.style_dashed)
Advertisement
Comments
-
- 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