//@version=5 indicator('77-Liquidation Estimates (Real-Time)', '77-Liquidation Estimates (Real-Time)', false, format.volume) //------------------------------------------------------------------------------ // Settings //-----------------------------------------------------------------------------{ liqS1 = "Longs/Shorts Liquidations" liqSH = liqS1 refPL = input.string("open", "Longs Reference Price", options = ["open", "close", "oc2", "hl2", "ooc3", "occ3", "hlc3", "ohlc4", "hlcc4"]) refPS = input.string("oc2", "Shorts Reference Price", options = ["open", "close", "oc2", "hl2", "ooc3", "occ3", "hlc3", "ohlc4", "hlcc4"]) //------------------------------------------------------------------------------ // Bear Market Filter //------------------------------------------------------------------------------ // Define the 4-year cycle halvingYear = input(2011, title="Last Halving Year") // Set the last halving year yearDifference = year(time) - halvingYear // Bear market condition: The bear market is typically the third year after the halving year bearMarket = (yearDifference % 4 == 3) // Plot the bear market filter on the chart for reference bgcolor(bearMarket ? color.red : na, transp=90, title="Bear Market", force_overlay=true) //------------------------------------------------------------------------------ // User Defined Types //-----------------------------------------------------------------------------{ // @type bar properties with their values // // @field h (float) high price of the bar // @field l (float) low price of the bar // @field v (float) volume of the bar type bar float h = high float l = low float v = volume //----------------------------------------------------------------------------- // Variables //----------------------------------------------------------------------------- bar b = bar.new() nzV = nz(b.v) //----------------------------------------------------------------------------- // Functions/methods //----------------------------------------------------------------------------- f_gSRC(_s) => switch _s "open" => open "close" => close "oc2" => math.avg(open, close) "hl2" => hl2 "ooc3" => math.avg(open, open, close) "occ3" => math.avg(open, close, close) "hlc3" => hlc3 "ohlc4" => ohlc4 "hlcc4" => hlcc4 //----------------------------------------------------------------------------- // Calculations //----------------------------------------------------------------------------- rPS = f_gSRC(refPS) rPL = f_gSRC(refPL) lLQ = nzV / (rPL / (rPL - b.l)) sLQ = nzV / (rPS / (b.h - rPS)) plot(liqSH == liqS1 ? lLQ : na, 'Longs' , color.new(#26a69a, 17), style = plot.style_columns) plot(liqSH == liqS1 ? -sLQ : na, 'Shorts', color.new(#ef5350, 17), style = plot.style_columns) //------------------------------------------------------------------------------ // Funding Threshold and Buy Signal //------------------------------------------------------------------------------ // EMA Calculation ema24 = ta.ema(close, 24) ema110 = ta.ema(close, 110) plot(ema24, title="24 EMA", color=color.blue, linewidth=1,force_overlay = true) plot(ema110, title="110 EMA", color=color.purple, linewidth=1,force_overlay = true) // Bollinger Bands //------------------------------------------------------------------------------ length = input.int(55, minval=1) maType = input.string("SMA", "Basis MA Type", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"]) src = (liqSH == liqS1 ? lLQ : na) mult = input.float(4.0, minval=0.001, step=0.1, maxval=50, title="StdDev") ma(source, length, _type) => switch _type "SMA" => 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) basis = ma(src, length, maType) *2.6 basis2 = ma(src, length, maType) *2.6 dev = mult * ta.stdev(src, length) upper = basis + dev lower = basis - dev offset = input.int(0, "Offset", minval = -500, maxval = 500, display = display.data_window) plot(basis, "Basis", color=#2962FF, offset=offset) p_1 = plot(upper, "Upper", color=#F23645, offset=offset) p_2 = plot(lower, "Lower", color=#089981, offset=offset) fill(p_1, p_2, title="Background", color=color.rgb(33, 150, 243, 95)) // Add the buy signal with Bollinger Band condition, bear market filter, and price below 21 EMA if not bearMarket and (liqSH == liqS1 ? lLQ : na) > upper and close < ema110 // Highest priority signal (1): "⁂" label.new(bar_index, low, text="⁂", textcolor=#ffebba, style=label.style_label_up, color=#4caf4f00, size=size.large, force_overlay=true) // Second priority signal (2): "⁑" else if not bearMarket and (liqSH == liqS1 ? lLQ : na) > basis and close < ema24 and close < ema110 label.new(bar_index, low, text="⁑", textcolor=#ff5a00, style=label.style_label_up, color=#4caf4f00, size=size.large, force_overlay=true) // Lowest priority signal (3): "⁎" else if not bearMarket and (liqSH == liqS1 ? lLQ : na) > basis and close < ema24 and close > ema110 label.new(bar_index, low, text="⁎", textcolor=#5d606b, style=label.style_label_up, color=#4caf4f00, size=size.large, force_overlay=true) // Define alert conditions for each signal alertcondition(not bearMarket and (liqSH == liqS1 ? lLQ : na) > basis and close < ema24 and close > ema110, title="Priority 1 Signal", message="Priority 3 Signal: ⁎ detected (Bollinger Basis, Bear Market Filter, price below 21 EMA and above 110 EMA)") alertcondition(not bearMarket and (liqSH == liqS1 ? lLQ : na) > basis and close < ema24 and close < ema110, title="Priority 2 Signal", message="Priority 2 Signal: ⁑ detected (Bollinger Basis, Bear Market Filter, price below 21 and 110 EMA)") alertcondition(not bearMarket and (liqSH == liqS1 ? lLQ : na) > upper and close < ema110, title="Priority 3 Signal", message="Priority 1 Signal: ⁂ detected (Bollinger Upper Band, Bear Market Filter, and price below 110 EMA)")