Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- strategy("neo test", 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 2011"), title = "Start Date")
- isInTimeRange = time >= startTime
- // 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))
- lengthrsiema = input.int(14, group="RSI Settings")
- RSIEMA = ta.ema(rsi,lengthrsiema)
- // RSIema_long = RSIEMA > 50
- RSIema_short = RSIEMA < 50
- RSIema_long = ta.crossover(RSIEMA, 50)
- // RSIema_short = ta.crossunder(RSIEMA, 50)
- 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)
- // 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
- //STC
- EEEEEE = input(17, 'STC Length', group = "STC")
- BBBB = input(38, 'STC FastLength', group = "STC")
- BBBBB = input(55, 'STC SlowLength', 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 = input(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)
- mColor = mAAAAA > mAAAAA[1] ? color.new(color.green, 20) : color.new(color.red, 20)
- stc = mAAAAA > mAAAAA[1] ? true : false
- stc_long = mAAAAA > mAAAAA[1]
- stc_short = mAAAAA < mAAAAA[1]
- // GET INPUTS //----------------------------------------------------------------------------------
- src0 = input.source (close , 'Source', group = "VZO" )
- len = input.int (45 , 'VZO Length', group = "VZO" , minval=1)
- malen = input.int (7 , 'MA Length', group = "VZO" , minval=1)
- flen = input.int (7 , 'Fisher Length', group = "VZO", minval=1)
- col_1 = input.color(#22ab94,'Color 1')
- col_2 = input.color(#f7525f,'Color 2')
- // CALC VZO //------------------------------------------------------------------------------------
- zone(_src, _len) =>
- vol = volume
- src = ta.wma(2 * ta.wma(_src, malen / 2) - ta.wma(_src, malen), math.round(math.sqrt(malen)))
- vp = src > src[1] ? vol : src < src[1] ? -vol : src == src[1] ? 0 : 0
- z = 100 * (ta.ema(vp, _len) / ta.ema(vol, _len))
- vzo = request.security(syminfo.tickerid,"",zone(src0, len))
- // CALC FISHER //---------------------------------------------------------------------------------
- fsrc = vzo
- MaxH = ta.highest (fsrc , flen)
- MinL = ta.lowest (fsrc , 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])
- // PLOT //----------------------------------------------------------------------------------------
- fzvzo_down = f1<f2
- fzvzo_up = f1 > f2
- //plot(f1 , color=col , title="Fisher" )
- //plot(f2 , color=col , title="Trigger" )
- //Aroon
- aroonlength = input.int(27, "Aroon UP", group = "Aroon")
- lowerlength = input.int(28,"Aroon Down", group = "Aroon")
- upper = 100 * (ta.highestbars(high, aroonlength+1) + aroonlength)/aroonlength
- lower = 100 * (ta.lowestbars(low, lowerlength+1) + lowerlength)/lowerlength
- oscillator1 = upper - lower
- smoothing1 = input.int(14, "Aroon Smoothing", group = "Aroon")
- oscillator = ta.ema(oscillator1, smoothing1)
- aroonup = input.int(7, "AroonUP lvl", group = "Aroon")
- aroondn = input.int(14,"AroonDN lvl", group = "Aroon")
- //Trading
- aroon_long = upper > aroonup
- aroon_short = lower > aroondn and oscillator < 75
- //adx
- adxlen = input(7, title="ADX Smoothing", group = "ADX")
- dilen = input(6, title="ADX_DI Length", group = "ADX")
- adx_crit = input(27, title="ADX Crit", group = "ADX")
- dirmov(len) =>
- 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)
- truerange = ta.rma(ta.tr, len)
- plus = fixnan(100 * ta.rma(plusDM, len) / truerange)
- minus = fixnan(100 * ta.rma(minusDM, len) / truerange)
- [plus, minus]
- adx(dilen, adxlen) =>
- [plus, minus] = dirmov(dilen)
- sum = plus + minus
- //adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)
- sig = adx(dilen, adxlen)
- adx_up = sig > adx_crit
- adx_down = sig > adx_crit
- // RTI
- trend_data_count = input.int(113, step=4, 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 > 21
- RTIshort = RelativeTrendIndex < 79
- atrSupertrend = input.int(10, "ATR", group="Supertrend")
- factor = input.float(3, "Factor", step=0.05,group="Supertrend")
- [a, direction] = ta.supertrend(factor, atrSupertrend)
- // supertrend_Long = direction < 0
- // supertrend_Short = direction > 0
- supertrend_Long = ta.crossunder(direction, 0)
- supertrend_Short = ta.crossover(direction, 0)
- // ** ---> Inputs ------------- {
- var bool positive = false
- var bool negative = false
- string RSI_group = "RSI Settings"
- string mom_group = "Momentum Vales"
- string visual = "Visuals"
- int Len2 = input(14,"RSI 1️⃣",inline = "rsi",group = RSI_group)
- int pmom = input(65," Positive above",inline = "rsi1",group =RSI_group )
- int nmom = input(32,"Negative below",inline = "rsi1",group =RSI_group )
- bool showlabels = input(true,"Show Momentum ❓",inline = "001",group =visual )
- //color p = input(color.rgb(76, 175, 79, 62),"Positive",inline = "001",group =visual )
- //color n = input(color.rgb(255, 82, 82, 66),"Negative",inline = "001",group =visual )
- bool filleshow = input(true,"Show highlighter ❓",inline = "002",group =visual )
- color bull = input(color.rgb(76, 175, 79, 62),"Bull",inline = "002",group =visual )
- color bear = input(color.rgb(255, 82, 82, 66),"Bear",inline = "002",group =visual )
- //rsi = ta.rsi(close, Len2)
- //------------------- }
- // ** ---> Momentums ------------- {
- p_mom = rsi[1] < pmom and rsi > pmom and rsi > nmom and ta.change(ta.ema(close,5)) > 0
- n_mom = rsi < nmom and ta.change(ta.ema(close,5)) < 0
- if p_mom
- positive:= true
- negative:= false
- if n_mom
- positive:= false
- negative:= true
- // ** ---> Entry Conditions ------------- {
- //a = plot(filleshow ? ta.ema(high,5) : na,display = display.none,editable = false)
- //b = plot(filleshow ? ta.ema(low,10) : na,style = plot.style_stepline,color = color.red,display = display.none,editable = false)
- // fill(a,b,color = color.from_gradient(rsi14,35,pmom,color.rgb(255, 82, 82, 66),color.rgb(76, 175, 79, 64)) )
- //fill(a,b,color = positive ? bull :bear ,editable = false)
- //plotting
- longcondition = positive and not positive[1]
- shortcondition = negative and not negative[1]
- //MACD
- FastLength = input(title="MACD Fast Length", group="MACD", defval=47)
- Slowlength = input(title="MACD Slow Length", group="MACD", defval=79)
- MACDLength = input(title="MACD Signal Length", group="MACD", defval=30)
- MACD = ta.ema(close, FastLength) - ta.ema(close, Slowlength)
- aMACD = ta.ema(MACD, MACDLength)
- delta = MACD - aMACD
- LongMACD = ta.crossover(delta, 0)
- ShortMACD = ta.crossunder(delta, 0)
- // 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(5 , "1st Multiplier", group = "Loxx", step=0.1) //~using the same step as supertrend and *2 to test the robustness = 0.05*2 = 0.1
- multloxx2 = input.float(2 , "2nd Multiplier", group = "Loxx", step=0.1) //~
- multloxx3 = input.float(3 , "3rd Multiplier", group = "Loxx", step=0.1) //~
- multloxx1825 = input.float(1.825, "4th Multiplier", group = "Loxx", step=0.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)
- [supertrendloxx3, directionloxx3] = pine_supertrend(srcloxx, multloxx3, adaptloxx ? lenloxx : per)
- [supertrendloxx2, directionloxx2] = pine_supertrend(srcloxx, multloxx2, adaptloxx ? lenloxx : per)
- [supertrendloxx1825, directionloxx1825] = pine_supertrend(srcloxx, multloxx1825, adaptloxx ? lenloxx : per)
- // loxx_long = directionloxx == -1 and directionloxx[1] == 1
- // loxx_short = directionloxx == 1 and directionloxx[1] == -1
- loxx_long = close > supertrendloxx5
- loxx_short = close < supertrendloxx5
- loxx_long_2 = directionloxx2 == -1 and directionloxx2[1] == 1
- loxx_short_2 = directionloxx == 1 and directionloxx[1] == -1
- loxx_long_3 = directionloxx3 == -1 and directionloxx3[1] == 1
- loxx_short_3 = close < supertrendloxx3
- loxx_long_1_825 = close > supertrendloxx1825
- loxx_short_1_825 = close < supertrendloxx1825
- // {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=31, minval=1,group = "Trend Sniper Settings")
- int smoothing_length = input.int(title='MA Smooth ', defval=10, minval=1, maxval=10,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 = weighted_line_smooth > weighted_line_smooth[1]
- trend_down = weighted_line_smooth < weighted_line_smooth[1]
- //trend_up = ta.crossover(weighted_line_smooth, weighted_line_smooth[1])
- //t//rend_down = ta.crossunder(weighted_line_smooth, weighted_line_smooth[1])
- //longCondition =
- // STClong and ((DMIlong and DMIlong_2) or ((loxx_long_2 or loxx_long_3) and supertrend_Long and trend_up))
- // and (RSIema_long or RTIlong or roughlong or loxx_long or loxx_long_2 )
- //shortCondition =
- // STCshort and (DMIshort and DMIshort_2) and (loxx_short_1_825 or loxx_short_3)
- // and (RSIema_short or RTIshort or roughshort or loxx_short or loxx_short_2 or (trend_down2 and trend_down2_2))
- // Buy, Sell
- //psar
- start = input(0.02)
- increment = input(0.02)
- maximum = input(0.2)
- psar = ta.sar(start, increment, maximum)
- // Signals
- psar_long = high[1] < psar[2] and high > psar[1]
- psar_short = low[1] > psar[2] and low < psar[1]
- //RSI
- //RSI_Length = input.int(14, minval=1, group="RSI - Confluence 3")
- rsi1 = ta.rsi(close, 14)
- rsi_over_sold = rsi < 80
- rsi_over_bought = rsi > 20
- rsi_high = rsi1 > 21
- rsi_low = rsi1 < 79
- //Momentum
- length4 = input.int(10, title="Momentum Length", minval=1, group="Momentum Indicator")
- price = close
- momentum(seria, length4) =>
- mom = seria - seria[length4]
- mom
- mom0 = momentum(price, length4)
- mom1 = momentum( mom0, 1)
- mom_long = (mom0 > 0 and mom1 > 0)
- mom_short = (mom0 < 0 and mom1 < 0)
- ///mfi
- length = input.int(title="Length", defval=14, minval=1, maxval=2000)
- src = hlc3
- mf = ta.mfi(src, length)
- plot(mf, "MF", color=#7E57C2)
- overbought=hline(80, title="Overbought", color=#787B86)
- hline(50, "Middle Band", color=color.new(#787B86, 50))
- oversold=hline(20, title="Oversold", color=#787B86)
- fill(overbought, oversold, color=color.rgb(126, 87, 194, 90), title="Background")
- longmfi=ta.crossover(mf,50)
- shortmfi=ta.crossunder(mf,50)
- length1 = input.int(12, minval=1)
- source = input(close, "Source")
- roc = 100 * (source - source[length1])/source[length1]
- plot(roc, color=#2962FF, title="ROC")
- hline(0, color=#787B86, title="Zero Line")
- longroc=ta.crossover(roc,0)
- shortroc=ta.crossunder(roc,0)
- buy_signal = stc_long and aroon_long
- sell_signal = stc_short and aroon_short
- if barstate.isconfirmed and isInTimeRange and buy_signal
- strategy.entry("Long", strategy.long)
- if barstate.isconfirmed and isInTimeRange and sell_signal
- 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