// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/ // © blackcat1402 //@version=4 study(title="[blackcat] L2 Ehlers Decycler Oscillator", shorttitle="BCL2EDO", overlay=false) //inputs Price = input(hl2, title = "Price") Fast_HPPeriod = input(100, title = "Fast_HPPeriod", minval = 0) Slow_HPPeriod = input(125, title = "Slow_HPPeriod", minval = 0) Fast_K = input(1.2, title = "Fast_K", step = 0.1, minval = 0) Slow_K = input(1.2, title = "Slow_K", step = 0.1, minval = 0) //vars Fast_Val = 0.00 Slow_Val = 0.00 //func DecyclerOscillator(Price, HPPeriod, K) => //Vars alpha1 = 0.00 alpha2 = 0.00 HP = 0.00 Decycle = 0.00 DecycleOsc = 0.00 DecyclerOscillator = 0.00 pi = 2 * asin(1) alpha1 := ( cos ( 0.707 * 2 * pi / HPPeriod ) + sin( 0.707 * 2 * pi / HPPeriod ) - 1 ) / cos( .707 * 2 * pi / HPPeriod ) HP := ( 1 - alpha1 / 2 ) * ( 1 - alpha1 / 2 ) * ( Price - 2 * Price[1] + Price[2] ) + 2 * ( 1 - alpha1 ) * nz(HP[1]) - ( 1 - alpha1 ) * ( 1 - alpha1 ) * nz(HP[2]) Decycle := Price - HP alpha2 := ( cos( 0.707 * 2 * pi / ( 0.5 * HPPeriod ) ) + sin( 0.707 * 2 * pi / ( 0.5 * HPPeriod ) ) - 1) / cos( 0.707 * 2 * pi / ( 0.5 * HPPeriod ) ) DecycleOsc := ( 1 - alpha2 / 2 ) * ( 1 - alpha2 / 2 ) * ( Decycle - 2 * nz(Decycle[1]) + nz(Decycle[2]) ) + 2 * ( 1 - alpha2 ) * nz(DecycleOsc[1]) - ( 1 - alpha2 ) * ( 1 - alpha2 ) * nz(DecycleOsc[2]) DecyclerOscillator := 100 * K * DecycleOsc / Price Fast_Val := DecyclerOscillator( Price, Fast_HPPeriod, Fast_K ) Slow_Val := DecyclerOscillator( Price, Slow_HPPeriod, Slow_K ) plot1 = plot(Fast_Val, "Fast_Val", color=color.yellow, linewidth=1) plot2 = plot(Slow_Val, "Slow_Val", color=color.fuchsia, linewidth =1 ) fill(plot1, plot2, color=Fast_Val>Slow_Val ? color.yellow : color.fuchsia, transp=60) // Plots cross labels l = crossunder(Fast_Val, Slow_Val) ? label.new (bar_index, Fast_Val[1], "SELL", color=color.red, textcolor=color.white, style=label.style_labeldown, yloc=yloc.price, size=size.small) : crossover(Fast_Val, Slow_Val) ? label.new (bar_index, Fast_Val[1], "BUY", color=color.green, textcolor=color.white, style=label.style_labelup, yloc=yloc.price, size=size.small) : na // plot Fast_Val divergence lbR = input(title="Pivot Lookback Right", defval=5) lbL = input(title="Pivot Lookback Left", defval=5) rangeUpper = input(title="Max of Lookback Range", defval=60) rangeLower = input(title="Min of Lookback Range", defval=5) plotBull = input(title="Plot Bullish", defval=true) plotHiddenBull = input(title="Plot Hidden Bullish", defval=false) plotBear = input(title="Plot Bearish", defval=true) plotHiddenBear = input(title="Plot Hidden Bearish", defval=false) bearColor = color.red bullColor = color.green hiddenBullColor = color.green hiddenBearColor = color.red textColor = color.white noneColor = color.new(color.white, 100) osc = Fast_Val plFound = na(pivotlow(osc, lbL, lbR)) ? false : true phFound = na(pivothigh(osc, lbL, lbR)) ? false : true _inRange(cond) => bars = barssince(cond == true) rangeLower <= bars and bars <= rangeUpper //------------------------------------------------------------------------------ // Regular Bullish // Osc: Higher Low oscHL = osc[lbR] > valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) // Price: Lower Low priceLL = low[lbR] < valuewhen(plFound, low[lbR], 1) bullCond = plotBull and priceLL and oscHL and plFound plot( plFound ? osc[lbR] : na, offset=-lbR, title="Regular Bullish", linewidth=7, color=(bullCond ? bullColor : noneColor), transp=0 ) plotshape( bullCond ? osc[lbR] : na, offset=-lbR, title="Regular Bullish Label", text=" Bull ", style=shape.labelup, location=location.absolute, color=bullColor, textcolor=textColor, transp=0 ) alertcondition(bullCond, title="Regular bullish divergence found", message="Check charts for a regular bullish divergence found") //------------------------------------------------------------------------------ // Hidden Bullish // Osc: Lower Low oscLL = osc[lbR] < valuewhen(plFound, osc[lbR], 1) and _inRange(plFound[1]) // Price: Higher Low priceHL = low[lbR] > valuewhen(plFound, low[lbR], 1) hiddenBullCond = plotHiddenBull and priceHL and oscLL and plFound plot( plFound ? osc[lbR] : na, offset=-lbR, title="Hidden Bullish", linewidth=7, color=(hiddenBullCond ? hiddenBullColor : noneColor), transp=0 ) plotshape( hiddenBullCond ? osc[lbR] : na, offset=-lbR, title="Hidden Bullish Label", text=" H Bull ", style=shape.labelup, location=location.absolute, color=bullColor, textcolor=textColor, transp=0 ) alertcondition(hiddenBullCond, title="Hidden bullish divergence found", message="Check charts for a hidden bullish divergence found") //------------------------------------------------------------------------------ // Regular Bearish // Osc: Lower High oscLH = osc[lbR] < valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) // Price: Higher High priceHH = high[lbR] > valuewhen(phFound, high[lbR], 1) bearCond = plotBear and priceHH and oscLH and phFound plot( phFound ? osc[lbR] : na, offset=-lbR, title="Regular Bearish", linewidth=7, color=(bearCond ? bearColor : noneColor), transp=0 ) plotshape( bearCond ? osc[lbR] : na, offset=-lbR, title="Regular Bearish Label", text=" Bear ", style=shape.labeldown, location=location.absolute, color=bearColor, textcolor=textColor, transp=0 ) alertcondition(bearCond, title="Regular bearish divergence found", message="Check charts for a regular bearish divergence found") //------------------------------------------------------------------------------ // Hidden Bearish // Osc: Higher High oscHH = osc[lbR] > valuewhen(phFound, osc[lbR], 1) and _inRange(phFound[1]) // Price: Lower High priceLH = high[lbR] < valuewhen(phFound, high[lbR], 1) hiddenBearCond = plotHiddenBear and priceLH and oscHH and phFound plot( phFound ? osc[lbR] : na, offset=-lbR, title="Hidden Bearish", linewidth=7, color=(hiddenBearCond ? hiddenBearColor : noneColor), transp=0 ) plotshape( hiddenBearCond ? osc[lbR] : na, offset=-lbR, title="Hidden Bearish Label", text=" H Bear ", style=shape.labeldown, location=location.absolute, color=bearColor, textcolor=textColor, transp=0 ) alertcondition(hiddenBearCond, title="Hidden bearish divergence found", message="Check charts for a hidden bearish divergence found") ------------------------------------------ "Win$ & Donate w/ This" Address: BTC / USDT(OMNI): 3DsouvyXoT4T2u8qdWvs9TXVD4hUozAKTc ETH / ERC20 Coin: 0xfE2240fb97F11d81A324C6d3881de43E09EadEF9 LTC: LchnDmA2rnZ5ULdqbr9UbnTX4fFcP2yrJf TRX: TEeUzBUvfYbqb8LyL7iGZbJewr9tWnxEuF EOS: blackcatjust ------------------------------------------- From: https://www.tradingview.com/script/Z9wb3LVJ-blackcat-L2-Ehlers-Decycler-Oscillator/