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/
- // © danielcantea
- //@version=5
- strategy("THE MATRIX KILLER", overlay=true, pyramiding = 0, slippage = 1, initial_capital = 100, default_qty_type = strategy.percent_of_equity, default_qty_value = 100)
- // Plot Cobra Metrics Table
- import EliCobra/CobraMetrics/4 as cobra
- 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("Bottom 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)
- // Time Range
- startTime = input.time(defval = timestamp("01 January 2018"), title = "Start Date")
- isInTimeRange = time >= startTime
- //////////////////////////////////////////////////////////////////////////Main indicators////////////////////////////////////////////////////////////////////////
- //STC
- EEEEEE = input.int(defval = 13, step = 1, title = "STC Length", group = "STC")
- BBBB = input.int(defval = 31, step = 1, title = "STC Fast Length", group = "STC")
- BBBBB = input.int(defval = 70, step = 1, title = "STC Slow Length", group = "STC")
- AAAA(BBB, BBBB, BBBBB) =>
- fastMA = ta.ema(BBB, BBBB)
- slowMA = ta.ema(BBB, BBBBB)
- AAAA = fastMA - slowMA
- AAAA
- AAAAA(EEEEEE, BBBB, BBBBB) =>
- AAA = 0.5
- 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)
- STClong = mAAAAA > mAAAAA[1]
- STCshort = mAAAAA < mAAAAA[1]
- // DMI
- LengthDMI = input.int(defval = 16, title = "DMI Length", group = 'DMI')
- LengthDMI_2 = input.int(defval = 16, title = "DMI Length_2", group = 'DMI')
- smoothing_lengthDMI = input.int(defval = 12, title = "DMI ADX Smoothing", group = 'DMI')
- [diplus, diminus, adx] = ta.dmi(LengthDMI, smoothing_lengthDMI)
- [diplus_2, diminus_2, adx_2] = ta.dmi(LengthDMI_2, smoothing_lengthDMI)
- DMIlong = diplus > diminus and adx > adx[1]
- DMIshort = diminus > diplus
- // DMIlong = ta.crossover(diplus, diminus) and ta.crossover(adx, adx[1])
- // DMIshort = ta.crossunder(diplus, diminus)
- DMIlong_2 = diplus_2 > diminus_2 and adx_2 > adx_2[1]
- DMIshort_2 = diminus_2 > diplus_2
- // RTI
- trend_data_count = input.int(113, step=1, minval=10, title="Trend Length", inline = "RT", group="RTI")
- trend_sensitivity_percentage = input.int(95, step=1,minval=50, maxval=98,title='Sensitivity', inline = "RT1", group="RTI")
- upper_trend = close + ta.stdev(close, 2)
- lower_trend = close - ta.stdev(close, 2)
- upper_array = array.new<float>(0)
- lower_array = array.new<float>(0)
- for i = 0 to trend_data_count - 1
- upper_array.push(upper_trend[i])
- lower_array.push(lower_trend[i])
- upper_array.sort()
- lower_array.sort()
- upper_index = math.round(trend_sensitivity_percentage / 100 * trend_data_count) - 1
- lower_index = math.round((100 - trend_sensitivity_percentage) / 100 * trend_data_count) - 1
- UpperTrend = upper_array.get(upper_index)
- LowerTrend = lower_array.get(lower_index)
- RelativeTrendIndex = ((close - LowerTrend) / (UpperTrend - LowerTrend))*100
- //
- RTIlong = RelativeTrendIndex > 50
- RTIshort = RelativeTrendIndex < 50
- // RTIlong = ta.crossover(RelativeTrendIndex, 50)
- // RTIshort = ta.crossunder(RelativeTrendIndex, 50)
- // rsi
- rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")
- rsiSourceInput = input.source(close, group="RSI Settings")
- 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))
- rsi2 = ta.rsi(close, 21)
- RSI_long = rsi2 > 50
- RSI_short = rsi2 < 50
- // RSI_long = ta.crossover(rsi2, 50)
- // RSI_short = ta.crossunder(rsi2, 50)
- // Loxx supertrend
- RMA(x, t) =>
- EMA1 = x
- EMA1 := na(EMA1[1]) ? x : (x - nz(EMA1[1])) * (1/t) + nz(EMA1[1])
- EMA1
- fdip(float srcloxx, int per, int speedin)=>
- float fmax = ta.highest(srcloxx, per)
- float fmin = ta.lowest(srcloxx, per)
- float lengthloxx = 0
- float diff = 0
- for i = 1 to per - 1
- diff := (nz(srcloxx[i]) - fmin) / (fmax - fmin)
- if i > 0
- lengthloxx += math.sqrt( math.pow(nz(diff[i]) - nz(diff[i + 1]), 2) + (1 / math.pow(per, 2)))
- float fdi = 1 + (math.log(lengthloxx) + math.log(2)) / math.log(2 * per)
- float traildim = 1 / (2 - fdi)
- float alpha = traildim / 2
- int speed = math.round(speedin * alpha)
- speed
- pine_supertrend(float srcloxx, float factor, int atrPeriod) =>
- float atr = RMA(ta.tr(true), atrPeriod)
- float upperBand = srcloxx + factor * atr
- float lowerBand = srcloxx - factor * atr
- float prevLowerBand = nz(lowerBand[1])
- float prevUpperBand = nz(upperBand[1])
- lowerBand := lowerBand > prevLowerBand or close[1] < prevLowerBand ? lowerBand : prevLowerBand
- upperBand := upperBand < prevUpperBand or close[1] > prevUpperBand ? upperBand : prevUpperBand
- int directionloxx = na
- float superTrend = na
- float prevSuperTrend = superTrend[1]
- if na(atr[1])
- directionloxx := 1
- else if prevSuperTrend == prevUpperBand
- directionloxx := close > upperBand ? -1 : 1
- else
- directionloxx := close < lowerBand ? 1 : -1
- superTrend := directionloxx == -1 ? lowerBand : upperBand
- [superTrend, directionloxx]
- srcloxx = input.source(hl2, group = "Loxx")
- per = input.int(30, "Fractal Period Ingest", group = "Loxx")
- speed = input.int(20, "Speed", group = "Loxx")
- //Loxx input
- multloxx5 = input.float(7 , "1st Multiplier", group = "Loxx", step=1) //~using the same step as supertrend and *2 to test the robustness = 0.05*2 = 0.1
- multloxx2 = input.float(3 , "2rd Multiplier", group = "Loxx", step=1) //~
- adaptloxx = input.bool(true)
- masterdom = fdip(srcloxx, per, speed)
- int lenloxx = math.floor(masterdom) < 1 ? 1 : math.floor(masterdom)
- lenloxx := nz(lenloxx, 1)
- [supertrendloxx5, directionloxx] = pine_supertrend(srcloxx, multloxx5, adaptloxx ? lenloxx : per)
- [supertrendloxx2, directionloxx2] = pine_supertrend(srcloxx, multloxx2, adaptloxx ? lenloxx : per)
- loxx_long = close > supertrendloxx5
- loxx_short = close < supertrendloxx5
- loxx_long_2 = directionloxx2 == -1 and directionloxx2[1] == 1
- loxx_short_2 = close < supertrendloxx2
- // rough avg
- len = input.int(70, "Length", group = "Rough AVG")
- colbar = input.string("None", "Bar Coloring", ["None", "Trend", "Extremities", "Reversions"])
- revshow = input.bool(true)
- f_checkp() =>
- p = close
- count = 0
- while p > 1
- p /= 10
- count += 1
- math.pow(10, count)
- f_profile(len) =>
- l = len
- integral = 0.0
- f_x = math.abs(ta.rsi(close, len))
- for x = low / f_checkp() to high / f_checkp()
- integral := integral + f_x
- l * integral
- spacing_profile = f_profile(len)
- ra = ta.rsi(ta.ema(spacing_profile, len), len)
- roughlong = ra > 50
- roughshort = ra < 50
- // roughlong = ta.crossover(ra, 50)
- // roughshort = ta.crossunder(ra, 50)
- // {Gunzo} Trend Sniper
- float ma_source = input(title='MA Source', defval=close,group = "Trend Sniper Settings")
- int ma_length = input.int(title='MA Length', defval=28, minval=1,group = "Trend Sniper Settings")
- int smoothing_length = input.int(title='MA Smooth ', defval=10, minval=1, maxval=13,group = "Trend Sniper Settings")
- coefficient = ma_length / 3.0
- fn_calculate_wma_with_coefficient(source, length, coefficient) =>
- candle_weighted_sum = 0.0
- total_weight = 0.0
- for i = 0 to length by 1
- candle_weight = length - i
- candle_weighted_sum += (candle_weight - coefficient) * source[i]
- total_weight += candle_weight - coefficient
- total_weight
- weighted_line = candle_weighted_sum / total_weight
- [weighted_line]
- [weighted_line] = fn_calculate_wma_with_coefficient(ma_source, ma_length, coefficient)
- weighted_line_smooth = ta.ema(weighted_line, smoothing_length)
- trend_up = ta.crossover(weighted_line_smooth, weighted_line_smooth[1])
- // trend_down = ta.crossunder(weighted_line_smooth, weighted_line_smooth[1])
- // {Gunzo} Trend Sniper_2
- float ma_source2 = input(title='MA sni Source2', defval=close,group = "Trend Sniper Settings")
- int ma_length2 = input.int(title='MA sni Length2', defval=34, minval=1,group = "Trend Sniper Settings")
- int smoothing_length2 = input.int(title='MA sni Smooth2 ', defval=9, minval=1, maxval=13,group = "Trend Sniper Settings")
- coefficient2 = ma_length2 / 3.0
- fn_calculate_wma_with_coefficient2(source1, length2, coefficient2) =>
- candle_weighted_sum2 = 0.0
- total_weight2 = 0.0
- for i2 = 0 to length2 by 1
- candle_weight2 = length2 - i2
- candle_weighted_sum2 += (candle_weight2 - coefficient2) * source1[i2]
- total_weight2 += candle_weight2 - coefficient2
- total_weight2
- weighted_line2 = candle_weighted_sum2 / total_weight2
- [weighted_line2]
- [weighted_line2] = fn_calculate_wma_with_coefficient2(ma_source2, ma_length2, coefficient2)
- weighted_line_smooth2 = ta.ema(weighted_line2, smoothing_length2)
- trend_up2 = ta.crossover(weighted_line_smooth2, weighted_line_smooth2[1])
- // Inputs
- timeframe1=input.timeframe(defval ='1D', group = "Hull", tooltip = "Select a different timeframe for this series") // Use Alternative timeframe
- modeSwitch = input.string("Thma", title="Hull Variation", options=["Thma"])
- length = input(175, title="Length(180-200 for floating S/R , 55 for swing entry)")
- lengthMult = input.float(1.0, title="Length multiplier (Used to view higher timeframes with straight band)")
- useHtf = input(false, title="Show Hull MA from X timeframe? (good for scalping)")
- htf = input("240", title="Higher timeframe")
- //FUNCTIONS
- src = request.security(syminfo.tickerid,timeframe1 ,close)
- //THMA
- //THMA(_src, _length) => ta.wma(ta.wma(_src,_length / 3) * 3 - ta.wma(_src, _length / 2) - ta.wma(_src, _length), _length)
- THMA(_src, _length) => request.security(syminfo.tickerid,timeframe1 ,ta.wma(ta.wma(_src,_length / 3) * 3 - ta.wma(_src, _length / 2) - ta.wma(_src, _length), _length))
- //SWITCH
- Mode(modeSwitch, src, len) =>
- modeSwitch == "Thma" ? request.security(syminfo.tickerid,timeframe1,THMA(src, len/2)) : na
- //OUT
- _hull = Mode(modeSwitch, src, int(length * lengthMult))
- HULL = useHtf ? request.security(syminfo.ticker, htf, _hull) : _hull
- MHULL = HULL[0]
- SHULL = HULL[2]
- HullLong = request.security(syminfo.tickerid,timeframe1 ,ta.crossover(MHULL, SHULL))
- HullShort = request.security(syminfo.tickerid,timeframe1 ,ta.crossover(SHULL, MHULL))
- //EFI
- // Inputs
- timeframeefi=input.timeframe(defval ='3D', group = "EFI", tooltip = "Select a different timeframe for this series") // Use Alternative timeframe
- efilength = input.int(111, minval=1, group = "EFI")
- // Get high and low from selected timeframe instead of the one on the chart
- TFclose=request.security(syminfo.tickerid,timeframeefi , close)
- TFvolume=request.security(syminfo.tickerid,timeframeefi , volume)
- var cumVol = 0.
- cumVol += request.security(syminfo.tickerid,timeframeefi ,nz(volume))
- if barstate.islast and cumVol == 0
- runtime.error('Nope')
- efi = ta.ema(ta.change(TFclose) * TFvolume, efilength)
- efiLong = efi > 0
- efiShort = efi < 0
- // ***************************************************************************************************************************************************************
- // VR
- volatilityLower = input.float(title = "Lower Range", defval= -39, group = "VRG")
- volatilityHigher = input.float(title = "Higher Range", defval= 9)
- volatilityLength = 58
- volatilityRange = ta.sma(close - open, volatilityLength)
- //VR PARAMETERS
- VRL = volatilityRange > volatilityLower
- VRS = volatilityRange < volatilityHigher
- //VZO
- // inputs
- src0 = input.source(high, 'Source', group="VZO")
- len1 = input.float(17.25, 'VZO Length', minval=1, step=0.5, group="VZO")
- flen = input.float(3.5, 'Fisher Length', minval=1, step=0.5, group="VZO")
- ud = input.int(12, 'Updown val', group="VZO")
- var VZO_Intraday = input.bool(true, 'Smoothing', group="VZO")
- var repaint = input.bool(false, 'Allow Repainting', group="VZO")
- timeframe2=input.timeframe(defval ='1D', group="VZO", tooltip = "Select a different timeframe for this series") // Use Alternative timeframe
- // Sauce
- get_close = request.security(syminfo.tickerid,timeframe2 , close[repaint ? 0 : 1])
- get_vol = request.security(syminfo.tickerid,timeframe2 , volume[repaint ? 0 : 1])
- sym = syminfo.tickerid
- VZO(length, get_close, vol) =>
- Volume_Direction = get_close > get_close[3] ? vol : -vol
- VZO_volume = request.security(syminfo.tickerid,timeframe2 , ta.linreg(Volume_Direction, int(length), 0))
- Total_volume = request.security(syminfo.tickerid,timeframe2 , ta.linreg(vol, int(length), 0))
- 100 * VZO_volume / Total_volume
- VZO_ = VZO(len, get_close, get_vol)
- if VZO_Intraday
- VZO_ := ta.ema(VZO_, 9)
- // Fish
- fsrc = VZO_
- MaxH = request.security(syminfo.tickerid,timeframe2 , ta.highest(fsrc, int(flen)))
- MinL = request.security(syminfo.tickerid,timeframe2 , ta.lowest(fsrc, int(flen)))
- var nValue1 = 0.0
- var nFish = 0.0
- nValue1 := 0.33 * 2 * ((fsrc - MinL) / (MaxH - MinL) - 0.5) + 0.67 * nz(nValue1[1])
- nValue2 = (nValue1 > 0.99 ? 0.999 : (nValue1 < -0.99 ? -0.999 : nValue1))
- nFish := 0.5 * math.log((1 + nValue2) / (1 - nValue2)) + 0.5 * nz(nFish[1])
- f1 = nFish
- f2 = nz(nFish[1])
- stat = 0
- fzvzo_up = f1 > f2
- fzvzo_down = f1 < f2
- // Can use stat or fzvzoshort and fzvzoshort for firing buy/sell signals
- fzvzoshort = request.security(syminfo.tickerid,timeframe2 , ta.crossunder(f1, f2))
- fzvzolong = request.security(syminfo.tickerid,timeframe2 , ta.crossover(f1, f2))
- if fzvzolong
- stat := 1
- if fzvzoshort
- stat := -1
- //MACD
- // Inputs
- FastLength = input(title="MACD Fast Length", group="MACD", defval=44)
- Slowlength = input(title="MACD Slow Length", group="MACD", defval=95)
- MACDLength = input(title="MACD Signal Length", group="MACD", defval=31)
- timeframe3=input.timeframe(defval ='1D', group = "MACD", tooltip = "Select a different timeframe for this series") // Use Alternative timeframe
- MACD = request.security(syminfo.tickerid,timeframe3 , ta.ema(close, FastLength)) - request.security(syminfo.tickerid,timeframe3 , ta.ema(close, Slowlength))
- aMACD = request.security(syminfo.tickerid,timeframe3 , ta.ema(MACD, MACDLength))
- delta = MACD - aMACD
- // Calculate Buy/Sell orders
- LongMACD = ta.crossover(delta, 0)
- ShortMACD = ta.crossunder(delta, 0)
- length4 = input.int(46, minval=1, title="CCI LENGTH", group = "CCI")
- src_CCI = high
- //CALCULATIONS//
- ma = ta.sma(src_CCI, length4)
- cci = (src_CCI - ma) / (0.015 * ta.dev(src_CCI, length4))
- //TRADE CONDITIONS//
- CCI_LONG = cci > 90
- CCI_SHORT = cci < -90
- // Coral Trend
- sm =input(21, title="Smoothing Period", group = "CoralTrend")
- cd = input(0.6, title="Constant D", group = "CoralTrend")
- ribm=input(false, title="Ribbon Mode", group = "CoralTrend")
- timeframe4=input.timeframe(defval ='2D', group = "CoralTrend")
- //initialise vars
- var float i1 = na
- var float i2 = na
- var float i3 = na
- var float i4 = na
- var float i5 = na
- var float i6 = na
- src1=request.security(syminfo.tickerid,timeframe4, close)
- di = (sm - 1.0) / 2.0 + 1.0
- c1 = 2 / (di + 1.0)
- c2 = 1 - c1
- c3 = 3.0 * (cd * cd + cd * cd * cd)
- c4 = -3.0 * (2.0 * cd * cd + cd + cd * cd * cd)
- c5 = 3.0 * cd + 1.0 + cd * cd * cd + 3.0 * cd * cd
- i1 := c1*src1 + c2*nz(i1[1])
- i2 := c1*i1 + c2*nz(i2[1])
- i3 := c1*i2 + c2*nz(i3[1])
- i4 := c1*i3 + c2*nz(i4[1])
- i5 := c1*i4 + c2*nz(i5[1])
- i6 := c1*i5 + c2*nz(i6[1])
- bfr = -cd*cd*cd*i6 + c3*(i5) + c4*(i4) + c5*(i3)
- CoralLong = bfr > nz(bfr[1])?true:false
- CoralShort = bfr < nz(bfr[1])?true:false
- //INPUTS//
- length_AROON = input.int(25, minval=1, group = "AROON")
- //CALCULATIONS//
- upper1 = 100 * (ta.highestbars(high, length_AROON + 1) + length_AROON)/length_AROON
- lower1 = 100 * (ta.lowestbars(low, length_AROON + 1) + length_AROON)/length_AROON
- //TRADE CONDITIONS//
- AROON_LONG = upper1 > 94 and lower1 < 6
- AROON_SHORT = lower1 > 94 and upper1< 6
- // STOCHASTIC
- lengthK = input.int(10, "%K Length", minval = 1, maxval = 15000)
- lengthD = input.int(4, "%D Length", minval = -1, maxval = 4999)
- lengthEMA = input.int(13, "EMA Length", minval = 1, maxval = 4999)
- emaEma(source, length) => ta.ema(ta.ema(source, length), length)
- highestHigh = ta.highest(lengthK)
- lowestLow = ta.lowest(lengthK)
- highestLowestRange = highestHigh - lowestLow
- relativeRange = close - (highestHigh + lowestLow) / 2
- smi = 200 * (emaEma(relativeRange, lengthD) / emaEma(highestLowestRange, lengthD))
- EMAsmi = ta.ema(smi, lengthEMA)
- // LONG/SHORT STOCHASTIC
- StochasticLong = smi > EMAsmi
- StochasticShort = smi < EMAsmi
- /////////
- longCondition = (RTIlong or STClong and (loxx_long and loxx_long_2)
- or efiLong and fzvzo_up and RSI_long or LongMACD or roughlong or trend_up or trend_up2 or AROON_LONG )
- and (DMIlong and DMIlong_2 ) or (HullLong and VRL or CCI_LONG and CoralLong and AROON_LONG and StochasticLong )
- shortCondition = (RTIshort or STCshort and loxx_short and loxx_short_2
- or efiShort and fzvzo_down and RSI_short or ShortMACD or roughshort )
- and (DMIshort and DMIshort_2 ) or (HullShort and VRS or CCI_SHORT and CoralShort and StochasticShort )
- if barstate.isconfirmed and isInTimeRange and longCondition
- strategy.entry("Long", strategy.long)
- if barstate.isconfirmed and isInTimeRange and shortCondition
- strategy.entry("Short", 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