Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This Pine Scriptโข code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // ยฉ GuufyKing
- //@version=5
- strategy("Strat Dev Experimental Strategy (BTC)", initial_capital=10000, slippage=1, default_qty_value=100,
- pyramiding=0, default_qty_type=strategy.percent_of_equity, process_orders_on_close=true,
- shorttitle="SD101", overlay=true)
- //Date Range:
- useDateFilter = input.bool(true, title="Range of Backtest",
- group="Backtest")
- backtestStartDate = input.time(timestamp("1 Jan 2018"),
- title="Start Date", group="Backtest Time Period")
- //Range Conditions:
- inDateRange = not useDateFilter or (time >= backtestStartDate)
- //Cobra Metrics Table:
- import EliCobra/CobraMetrics/4 as cobra
- //// PLOT DATA
- 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 = "๐ ๐๐ธ๐ซ๐ป๐ช ๐๐ฎ๐ฝ๐ป๐ฒ๐ฌ๐ผ ๐")
- pos_table = input.string("Middle Right", "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)
- //Exponential Moving Average (EMA) Indicator:
- EMA = ta.ema(close, 12)
- SMA = ta.sma(close, 12)
- plot(EMA, title = "EMA", color = color.orange)
- longEMA = EMA >= close[1]
- shortEMA = EMA < close [1]
- //Relative Strength Index (RSI) Indicator:
- ma(source, length, type) =>
- switch type
- "SMA" => ta.sma(source, length)
- "Bollinger Bands" => ta.sma(source, length)
- "EMA" => ta.ema(source, length)
- "SMMA (RMA)" => ta.rma(source, length)
- "WMA" => ta.wma(source, length)
- "VWMA" => ta.vwma(source, length)
- // RSI Inputs:
- rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")
- rsiSourceInput = input.source(close, "Source", group="RSI Settings")
- maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings", display = display.data_window)
- maLengthInput = input.int(14, title="MA Length", group="MA Settings", display = display.data_window)
- bbMultInput = input.float(2.0, minval=0.001, maxval=50, title="BB StdDev", group="MA Settings", display = display.data_window)
- showDivergence = input.bool(false, title="Show Divergence", group="RSI Settings", display = display.data_window)
- // RSI Moves:
- up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)
- down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)
- rsiDaily = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))
- rsiMA = ma(rsiDaily, maLengthInput, maTypeInput)
- isBB = maTypeInput == "Bollinger Bands"
- // RSI Plots:
- //rsiPlot = plot(rsi, "RSI", color=#7E57C2)
- //plot(rsiMA, "RSI-based MA", color=color.yellow)
- //rsiUpperBand = hline(70, "RSI Upper Band", color=#787B86)
- //midline = hline(50, "RSI Middle Band", color=color.new(#787B86, 50))
- //rsiLowerBand = hline(30, "RSI Lower Band", color=#787B86)
- //fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title="RSI Background Fill")
- //bbUpperBand = plot(isBB ? rsiMA + ta.stdev(rsi, maLengthInput) * bbMultInput : na, title = "Upper Bollinger Band", color=color.green)
- //bbLowerBand = plot(isBB ? rsiMA - ta.stdev(rsi, maLengthInput) * bbMultInput : na, title = "Lower Bollinger Band", color=color.green)
- //fill(bbUpperBand, bbLowerBand, color= isBB ? color.new(color.green, 90) : na, title="Bollinger Bands Background Fill")
- //midLinePlot = plot(50, color = na, editable = false, display = display.none)
- //fill(rsiPlot, midLinePlot, 100, 70, top_color = color.new(color.green, 0), bottom_color = color.new(color.green, 100), title = "Overbought Gradient Fill")
- //fill(rsiPlot, midLinePlot, 30, 0, top_color = color.new(color.red, 100), bottom_color = color.new(color.red, 0), title = "Oversold Gradient Fill")
- // Divergence
- lookbackRight = 5
- lookbackLeft = 5
- rangeUpper = 60
- rangeLower = 5
- bearColor = color.red
- bullColor = color.green
- textColor = color.white
- noneColor = color.new(color.white, 100)
- plFound = na(ta.pivotlow(rsiDaily, lookbackLeft, lookbackRight)) ? false : true
- phFound = na(ta.pivothigh(rsiDaily, lookbackLeft, lookbackRight)) ? false : true
- _inRange(cond) =>
- bars = ta.barssince(cond == true)
- rangeLower <= bars and bars <= rangeUpper
- //------------------------------------------------------------------------------
- // Regular Bullish
- // rsi: Higher Low
- rsiHL = rsiDaily[lookbackRight] > ta.valuewhen(plFound, rsiDaily[lookbackRight], 1) and _inRange(plFound[1])
- // Price: Lower Low
- priceLL = low[lookbackRight] < ta.valuewhen(plFound, low[lookbackRight], 1)
- bullCondAlert = priceLL and rsiHL and plFound
- bullCond = showDivergence and bullCondAlert
- //plot(
- // plFound ? rsiDaily[lookbackRight] : na,
- // offset=-lookbackRight,
- // title="Regular Bullish",
- // linewidth=2,
- // color=(bullCond ? bullColor : noneColor)
- // )
- //
- //plotshape(
- // bullCond ? rsiDaily[lookbackRight] : na,
- // offset=-lookbackRight,
- // title="Regular Bullish Label",
- // text=" Bull ",
- // style=shape.labelup,
- // location=location.absolute,
- // color=bullColor,
- // textcolor=textColor
- // )
- //
- //------------------------------------------------------------------------------
- // Regular Bearish
- // rsi: Lower High
- rsiLH = rsiDaily[lookbackRight] < ta.valuewhen(phFound, rsiDaily[lookbackRight], 1) and _inRange(phFound[1])
- // Price: Higher High
- priceHH = high[lookbackRight] > ta.valuewhen(phFound, high[lookbackRight], 1)
- bearCondAlert = priceHH and rsiLH and phFound
- bearCond = showDivergence and bearCondAlert
- //plot(
- // phFound ? rsiDaily[lookbackRight] : na,
- // offset=-lookbackRight,
- // title="Regular Bearish",
- // linewidth=2,
- // color=(bearCond ? bearColor : noneColor)
- // )
- //
- //plotshape(
- // bearCond ? rsiDaily[lookbackRight] : na,
- // offset=-lookbackRight,
- // title="Regular Bearish Label",
- // text=" Bear ",
- // style=shape.labeldown,
- // location=location.absolute,
- // color=bearColor,
- // textcolor=textColor
- // )
- //
- //alertcondition(bullCondAlert, title='Regular Bullish Divergence', message="Found a new Regular Bullish Divergence, `Pivot Lookback Right` number of bars to the left of the current bar.")
- //alertcondition(bearCondAlert, title='Regular Bearish Divergence', message='Found a new Regular Bearish Divergence, `Pivot Lookback Right` number of bars to the left of the current bar.')
- //Standard Deviation Indicator:
- length = input.int(20, minval=1)
- src = input(close, title='Source')
- stdev = ta.stdev(src, length)
- plot(stdev, color=color.new(color.blue, 0))
- longCon = rsiDaily > 50 and stdev >= close and longEMA
- shortCon = rsiDaily < 50 and stdev < close and shortEMA
- if longCon and inDateRange and barstate.isconfirmed
- strategy.entry("Long State", strategy.long)
- if shortCon and inDateRange and barstate.isconfirmed
- strategy.entry("Short State", strategy.short)
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
Advertisement