Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © indheaddHe
- //@version=5
- strategy("BTCUSD - J.A BTC", initial_capital = 1000, default_qty_type = strategy.percent_of_equity,
- default_qty_value = 100, pyramiding = 0, slippage = 0, overlay = true)
- ////DATE SETTINGS
- begin = input.time(defval=timestamp("01 January 2018"), title="start time")
- end = input.time(defval=timestamp("01 January 2030"), title="end time")
- timezone = time >= begin and time <= end
- //// END OF DATE SETTINGS
- //////// INDICATORS SET UP ////////
- ////DMI SETTINGS
- lensig = input.int(14, title="ADX Smoothing", minval=1, maxval=50, group = "DMI SETTINGS")
- lenDMI = input.int(10, minval=1, title="DI Length", group = "DMI SETTINGS")
- 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 = 100 * ta.rma(plusDM, lenDMI) / trur
- minus = 100 * ta.rma(minusDM, lenDMI) / trur
- // DMI Signal Conditions
- DMILong = ta.crossover(plus, minus)
- DMIShort = ta.crossunder(plus, minus)
- //// STC SETTINGS
- EEEEEE = input(29, 'Length', group = "STC Settings")
- BBBB = input(45, 'FastLength', group = "STC Settings")
- BBBBB = input(75, 'SlowLength', group = "STC Settings")
- AAAA(BBB, BBBB, BBBBB) =>
- fastMA = ta.ema(BBB, BBBB)
- slowMA = ta.ema(BBB, BBBBB)
- AAAA = fastMA - slowMA
- AAAA
- AAAAA(EEEEEE, BBBB, BBBBB) =>
- AAA = input.float(0.75, step = 0.01, group = "STC Settings")
- var CCCCC = 0.0
- var DDD = 0.0
- var DDDDDD = 0.0
- var EEEEE = 0.0
- BBBBBB = AAAA(close, BBBB, BBBBB)
- CCC = ta.lowest(BBBBBB, EEEEEE)
- CCCC = ta.highest(BBBBBB, EEEEEE) - CCC
- CCCCC := CCCC > 0 ? (BBBBBB - CCC) / CCCC * 100 : nz(CCCCC[1])
- DDD := na(DDD[1]) ? CCCCC : DDD[1] + AAA * (CCCCC - DDD[1])
- DDDD = ta.lowest(DDD, EEEEEE)
- DDDDD = ta.highest(DDD, EEEEEE) - DDDD
- DDDDDD := DDDDD > 0 ? (DDD - DDDD) / DDDDD * 100 : nz(DDDDDD[1])
- EEEEE := na(EEEEE[1]) ? DDDDDD : EEEEE[1] + AAA * (DDDDDD - EEEEE[1])
- EEEEE
- mAAAAA = AAAAA(EEEEEE, BBBB, BBBBB)
- //STC Signal Conditions
- StcLong = mAAAAA > mAAAAA[1]
- StcShort = mAAAAA <= mAAAAA[1]
- //// END OF STC SETTINGS
- //// MACD SETTINGS
- maType = input.string(title="MA Type", defval="SMA", options=["SMA", "EMA"], group="MACD SETTINGS")
- fastLen = input.int(title="Fast Length", defval=22, group="MACD SETTINGS")
- slowLen = input.int(title="Slow Length", defval=139, group="MACD SETTINGS")
- macdLen = input.int(title="MACD Length", defval=18, group="MACD SETTINGS")
- fast_ma = maType == "SMA" ? ta.sma(close, fastLen) : ta.ema(close, fastLen)
- slow_ma = maType == "SMA" ? ta.sma(close, slowLen) : ta.ema(close, slowLen)
- macd = fast_ma - slow_ma
- aMacd = ta.ema(macd, macdLen)
- // MACD Signal Conditions
- macdLong = macd > aMacd
- macdShort = macd < aMacd
- //// Bollinger Bands SETTINGS
- bbLen = input.int(title="Length", defval=12, step = 1, group = "BB SETTINGS")
- bbMultiplier = input.float(title="Multiplier", defval=0.1, step = 0.1, group = "BB SETTINGS")
- bbBase = ta.sma(close, bbLen)
- bbStd = bbMultiplier * ta.stdev(close, bbLen)
- bbUpper = bbBase + bbStd
- bbLower = bbBase - bbStd
- // BB Signal Conditions
- bbLong = close > bbUpper
- bbShort = close < bbLower
- //// END OF BOLLINGER BANDS SETTINGS
- // SUPERTREND SETTINGS
- atrPeriod = input(4, "ATR Length", group = "Supertrend Settings")
- factor = input.float(0.78, "Factor", step = 0.01, group = "Supertrend Settings")
- [_, direction] = ta.supertrend(factor, atrPeriod)
- //SuperTrend SignaL Conditions
- supertrendLong = ta.change(direction) < 0
- supertrendShort = ta.change(direction) > 0
- //// END OF SUPERTREND SETTINGS
- //// Regularized MA SETTINGS
- f_kama(src, len, kamaf, kamas) =>
- white = math.abs(src - src[1])
- ama = 0.0
- nsignal = math.abs(src - src[len])
- nnoise = math.sum(white, len)
- nefratio = nnoise != 0 ? nsignal / nnoise : 0
- nsmooth = math.pow(nefratio * (kamaf - kamas) + kamas, 2)
- ama := nz(ama[1]) + nsmooth * (src - nz(ama[1]))
- ama
- f_t3(src, len) =>
- x1 = ta.ema(src, len)
- x2 = ta.ema(x1, len)
- x3 = ta.ema(x2, len)
- x4 = ta.ema(x3, len)
- x5 = ta.ema(x4, len)
- x6 = ta.ema(x5, len)
- b = 0.7
- c1 = - math.pow(b, 3)
- c2 = 3 * math.pow(b, 2) + 3 * math.pow(b, 3)
- c3 = -6 * math.pow(b, 2) - 3 * b - 3 * math.pow(b, 3)
- c4 = 1 + 3 * b + math.pow(b, 3) + 3 * math.pow(b, 2)
- c1 * x6 + c2 * x5 + c3 * x4 + c4 * x3
- f_ma(src, len, type, kamaf, kamas, offset, sigma) =>
- x = switch type
- "SMA" => ta.sma(src, len)
- "EMA" => ta.ema(src, len)
- "HMA" => ta.hma(src, len)
- "RMA" => ta.rma(src, len)
- "WMA" => ta.wma(src, len)
- "VWMA" => ta.vwma(src, len)
- "ALMA" => ta.alma(src, len, offset, sigma)
- "DEMA" => 2 * ta.ema(src, len) - ta.ema(ta.ema(src, len), len)
- "TEMA" => 3 * ta.ema(src, len) - 3 * ta.ema(ta.ema(src, len), len) + ta.ema(ta.ema(ta.ema(src, len), len), len)
- "EHMA" => ta.ema(2 * ta.ema(src, len / 2) - ta.ema(src, len), math.round(math.sqrt(len)))
- "THMA" => ta.wma(ta.wma(src, len / 3) * 3 - ta.wma(src, len / 2) - ta.wma(src, len), len)
- "T3" => f_t3(src, len)
- "KAMA" => f_kama(src, len, kamaf, kamas)
- "LSMA" => ta.linreg(src, len, 0)
- x
- matype = input.string("LSMA", "Type", ["SMA", "EMA", "DEMA", "TEMA", "HMA", "EHMA", "THMA", "RMA", "WMA", "VWMA", "T3", "KAMA", "ALMA", "LSMA"], group = "R.MA Settings")
- src = input.source(close, "Source", inline = "1", group = "R.MA Settings")
- len = input.int(23, "Length", inline = "1", group = "R.MA Settings")
- kamaf = input.float(0.666, "Kaufman Fast", group = "R.MA Settings")
- kamas = input.float(0.0645, "Kaufman Slow", group = "R.MA Settings")
- offset = input.float(0.85, "ALMA Offset", group = "R.MA Settings")
- sigma = input.int(6, "ALMA Sigma", group = "R.MA Settings")
- norm = input.int(7, "Regularize Length", group = "R.MA Settings")
- ma = f_ma(src, len, matype, kamaf, kamas, offset, sigma)
- mean = ta.sma(ma, norm)
- dev = ta.stdev(ma, norm)
- zmean = (ma - mean) / dev
- RmaLong = ta.crossover(zmean, 0)
- RmaShort = ta.crossunder(zmean, 0)
- //// END OF RMA SETTINGS
- //// RAVI-FISHER SETTINGS
- srcRavi = input.source(close, "Source", group = "RAVI SETTINGS")
- maf = input.int(23, "Fast MA Length", minval = 1, group = "RAVI SETTINGS")
- mas = input.int(28, "Slow MA Length", minval = 1, group = "RAVI SETTINGS")
- trigger = input.float(0.07, "Trigger", minval = 0, step = 0.01, group = "RAVI SETTINGS")
- maval = (ta.wma(srcRavi, maf) - ta.wma(srcRavi, mas)) * ta.atr(maf) / ta.wma(srcRavi, mas) / ta.atr(mas)
- maval := 100 * maval
- fish = (math.exp(2 * maval) - 1) / (math.exp(2 * maval) + 1)
- raviLong = fish >= 0
- raviShort = fish <= 0
- //// END OF RAVI-FISHER SETTINGS
- // CCI SETTINGS
- CCILength = input.int(defval = 42, step = 1, title = "CCI Length", group = "CCI")
- cci = ta.cci(hlc3,CCILength)
- CCIlong = ta.crossover(cci,100)
- CCIshort = ta.crossunder(cci,-100)
- /// END OF CCI SETTINGS
- //// ALPHATREND SETTINGS
- coeff = input.float(0.2, 'Multiplier', step=0.1, group = "ALPHATREND SETTINGS")
- AP = input(3, 'Common Period', group = "ALPHATREND SETTINGS")
- ATR = ta.sma(ta.tr, AP)
- srcALPHA = input(close, group = "ALPHATREND SETTINGS")
- showsignalsk = input(title='Show Signals?', defval=true, group = "ALPHATREND SETTINGS")
- novolumedata = input(title='Change calculation (no volume data)?', defval=false, group = "ALPHATREND SETTINGS")
- upT = low - ATR * coeff
- downT = high + ATR * coeff
- AlphaTrend = 0.0
- AlphaTrend := (novolumedata ? ta.rsi(srcALPHA, AP) >= 50 : ta.mfi(hlc3, AP) >= 50) ? upT < nz(AlphaTrend[1]) ? nz(AlphaTrend[1]) : upT : downT > nz(AlphaTrend[1]) ? nz(AlphaTrend[1]) : downT
- buySignalk = ta.crossover(AlphaTrend, AlphaTrend[2])
- sellSignalk = ta.crossunder(AlphaTrend, AlphaTrend[2])
- K1 = ta.barssince(buySignalk)
- K2 = ta.barssince(sellSignalk)
- O1 = ta.barssince(buySignalk[1])
- O2 = ta.barssince(sellSignalk[1])
- alphaLong = buySignalk and (O1 > K2)
- alphaShort = sellSignalk and (O2 > K1)
- //// END OF ALPHATREND SETTINGS
- ///// NORMALIZED KAMA SETTINGS
- // Define input parameters
- fast_period = input.int(title='Fast Period', defval=8, minval=1, group = "KAMA SETTINGS")
- slow_period = input.int(title='Slow Period', defval=4, minval=1, group = "KAMA SETTINGS")
- er_period = input.int(title='Efficiency Ratio Period', defval=32, minval=1, group = "KAMA SETTINGS")
- norm_period = input.int(title='Normalization lookback', defval=21, minval=1, group = "KAMA SETTINGS")
- // Calculate the efficiency ratio
- change = math.abs(close - close[er_period])
- volatility = math.sum(math.abs(close - close[1]), er_period)
- er = change / volatility
- // Calculate the smoothing constant
- sc = er * (2 / (fast_period + 1) - 2 / (slow_period + 1)) + 2 / (slow_period + 1)
- // Calculate the KAMA
- kama = ta.ema(close, fast_period) + sc * (close - ta.ema(close, fast_period))
- // Normalize the oscillator
- lowest = ta.lowest(kama, norm_period)
- highest = ta.highest(kama, norm_period)
- normalized = (kama - lowest) / (highest - lowest) - 0.5
- // Kama L/S Conditions
- kamalong = ta.crossover(normalized, 0)
- kamashort = ta.crossunder(normalized, 0)
- //// END OF KAMA SETTINGS
- ////Execution (ALL SIGNALS) = StcLong bbLong macdLong supertrendLong DMILong RmaLong CCIlong raviLong kamalong alphaLong
- // DMI/ADX
- dmiGroup = "DMI/ADX"
- adxSmoothing = input.int(6, title="ADX Smoothing", group=dmiGroup)
- diLength = input.int(19, title="DI Length", group=dmiGroup)
- [diPlus, diMinus, adx] = ta.dmi(diLength, adxSmoothing)
- adxLong = diPlus > diMinus and adx > adx[1]
- adxShort = diMinus > diPlus
- LongCondition = bbLong and adxLong
- ShortCondition = bbShort and adxShort
- if strategy.equity > 0 and timezone and LongCondition and barstate.isconfirmed
- strategy.entry("B", strategy.long)
- if strategy.equity > 0 and timezone and ShortCondition and barstate.isconfirmed
- strategy.entry("S", strategy.short)
- //ELI CobraMetrics TABLE INPUTS
- import EliCobra/CobraMetrics/4 as cobra
- import TradingView/ta/5
- 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)
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