//@version=5 //Basic Hull Ma Pack tinkered by InSilico indicator("", overlay=true) //// CVD show_cvd_fast = input(true, 'Show Fast CVD?', group = "CVD") show_rma_alert = input(true, 'Show CVD-RMA crossover alert?', group = "CVD") barcolor_delta_based = input(false, "Color bars : delta compared?", "Color bars based on comparing Delta(last bar) against CVD") bullish = input.color( color.rgb(78, 78, 78), inline = "Color scheme 1") bearish = input.color( color.rgb(8, 8, 8), inline = "Color scheme 1") bullish2 = input.color(color.rgb(53, 238, 167), inline = "Color scheme 2" ) bearish2 = input.color(color.rgb(13, 38, 63), inline = "Color scheme 2" ) bullish3 = input.color( color.rgb(51, 238, 238), inline = "Color scheme 3" ) bearish3 = input.color(color.rgb(255, 51, 133), inline = "Color scheme 3" ) //// Variables Initialization int baseLookback = 0 int l1 = 0, lenCVDFast = 0 if timeframe.multiplier==30 baseLookback := 8, lenCVDFast := 14 else if timeframe.multiplier==60 baseLookback := 4, lenCVDFast := 7 else lenCVDFast := 14 int length = 0 ltf_volume_ar = array.new_float(), ltf_delta = 0.0 v00 = 0.0, b00 = 0.0, s00 = 0.0 d00 = 0.0, nd00 = 0.0 bardelta = 0.0 vol_buy = 0.0, vol_sell = 0.0, vol_delta = 0.0 alertLong00 = false, alertShort00 = false, threshold00 = input(0.75, "Alert 00 Threshold", group = "CVD") //// Functions //----Normalization Function n(s,l) => hi = ta.highest(s, l) lo = ta.lowest(s, l) n = (s - lo) / (hi - lo)+1 n //// Delta calculation delta_function() => vbuy=0.0, vsell=0.0, d=0.0 if close > open vbuy := volume * math.abs( open/close -1 ) if close < open vsell := volume * math.abs( open/close -1 ) d := ta.cum(vbuy - vsell) d //// Delta calculation with normalized volume delta_function_norm(length_x) => vbuy=0.0, vsell=0.0, d=0.0 vol_n = n(volume, length_x) if close > open vbuy := vol_n * math.abs( open/close -1 ) if close < open vsell := vol_n * math.abs( open/close -1 ) d := ta.cum(vbuy - vsell) d := ( n(d, length_x) - 1.5 ) * 2 cvd = ta.alma(d, length_x, 0.85, 7) cvd //// Normal Speed CVD //// ltf_vol_ar = request.security_lower_tf(syminfo.tickerid, "1", volume, false) length := input(24, "Normal CVD length", "Length used for Normal CVD", group = "CVD") vol = ltf_vol_ar.sum() vol_n = n(vol, length) vol_buy := 0.0, vol_sell := 0.0, vol_delta := 0.0 [open_ltf_ar, close_ltf_ar] = request.security_lower_tf(syminfo.tickerid, "1", [open, close]) open_ltf = array.sum(open_ltf_ar) close_ltf = array.sum(close_ltf_ar) if close_ltf > open_ltf vol_buy := vol_n * math.abs(open_ltf / close_ltf - 1) vol_buy if close_ltf < open_ltf vol_sell := vol_n * math.abs(open_ltf / close_ltf - 1) vol_sell vol_delta := ta.cum(vol_buy-vol_sell) vol_delta := ( n(vol_delta, length) - 1.5 ) * 2 cvd_normal = ta.alma(vol_delta, length, 0.85, 7) rma_normal = ta.rma(cvd_normal, 2) //// CVD Fast //// //length := input.int(14, "Fast CVD Length", tooltip = "Length used in Fast CVD", group = "CVD") length := lenCVDFast vol_n := n(volume, length) [open_ltf_ar00, close_ltf_ar00] = request.security_lower_tf(syminfo.tickerid, "1", [open, close]) open_ltf := array.sum(open_ltf_ar00) close_ltf := array.sum(close_ltf_ar00) if close_ltf > open_ltf vol_buy := vol_n * math.abs(open_ltf / close_ltf - 1) vol_buy if close_ltf < open_ltf vol_sell := vol_n * math.abs(open_ltf / close_ltf - 1) vol_sell vol_delta := ta.cum(vol_buy - vol_sell) vol_delta := (n(vol_delta, length) -1.5)*2.0 cvd_fast = ta.alma(vol_delta,length,0.90,7) rma_fast = ta.rma(cvd_fast, 2) //// ALMA-RMA crossover alert //// col_rma_cross = cvd_fast > rma_fast ? bullish : bearish //// ALert : Bardelta v CVD //// bardelta := vol_delta cvd_bardelta = cvd_fast alertLong01 = bardelta > cvd_bardelta ? true : false alertShort01 = bardelta < cvd_bardelta ? true : false col_bardelta_comparison = bardelta > cvd_bardelta ? bullish : bearish //// CVD fast //// transp = cvd_fast >= 0 ? 50 - cvd_fast*50 : cvd_fast < 0 ? 50-math.abs(cvd_fast*50) : 100 cvd_rising = ta.rising(cvd_fast, 2) ? true : false cvd_falling = ta.falling(cvd_fast, 2) ? true : false //cvd_color = cvd_rising ? color.new(bullish, transp) : cvd_falling ? color.new(bearish, transp) : color.new(color.rgb(255, 215, 0), 100) cvd_color = cvd_rising ? color.from_gradient(cvd_fast, -1, 1, bearish, bullish) : cvd_falling ? color.from_gradient(cvd_fast, -1, 1, bearish, bullish) : na //// cvd_indicator_type = input.string("Rising/falling", "Type of CVD indicator to show", options = ["Rising/falling", "ALMA/RMA crossover", "Bardelta/CVD comparison"], group = "CVD") cvd_rise_fall_based = str.contains("Rising/falling", cvd_indicator_type) ? true : false cvd_rma_based = str.contains("ALMA/RMA crossover", cvd_indicator_type) ? true : false cvd_bardelta_based = str.contains("Bardelta/CVD comparison", cvd_indicator_type) ? true : false bgcolor( timeframe.multiplier <= 60 ? cvd_rise_fall_based ? cvd_color : cvd_rma_based ? col_rma_cross : cvd_bardelta_based ? col_bardelta_comparison : na : na) ////--------------------------------------------- HULL Suite by Insilico //INPUT show_mhull = timeframe.multiplier <= 60 and timeframe.isminutes ? true : false show_shull = show_mhull ? true : false src = input(close, title="Source") modeSwitch = input.string("Hma", title="Hull Variation", options=["Hma", "Thma", "Ehma"]) int chartTFInMinutes = timeframe.in_seconds() / 60 tf_minute = timeframe.isminutes ? true : false tf_hour = tf_minute ? timeframe.multiplier == 60 ? true : false : false tf15min = timeframe.isminutes and timeframe.multiplier == 15 ? true : false tf30min = tf_minute ? timeframe.multiplier == 30 ? true : false : false tf1h = timeframe.isminutes and timeframe.multiplier == 60 ? true : false //length = chartTFInMinutes >= 30 ? 24 : chartTFInMinutes >= 60 ? 15 : 0 //length = len_adjusted length := input.int(15, title="Length(180-200 for floating S/R , 55 for swing entry)") lengthMult = input(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("120", title="Higher timeframe") //htf = input("240", title="Higher timeframe", type=input.resolution) switchColor = input(true, "Color Hull according to trend?") candleCol = input(false,title="Color candles based on Hull's Trend?") visualSwitch = input(true, title="Show as a Band?") thicknesSwitch = input(1, title="Line Thickness") transpSwitch = input.int(40, title="Band Transparency",step=5) bgcol_hullcol = input(false, "Bg color will be Hull color?") //// Colors //// hull_bullish = input.color(color.rgb(232, 234, 232, 70)) hull_bearish = input.color(color.rgb(246, 135, 191, 70)) //FUNCTIONS //HMA HMA(_src, _length) => ta.wma(2 * ta.wma(_src, _length / 2) - ta.wma(_src, _length), math.round(math.sqrt(_length))) //EHMA EHMA(_src, _length) => ta.ema(2 * ta.ema(_src, _length / 2) - ta.ema(_src, _length), math.round(math.sqrt(_length))) //THMA THMA(_src, _length) => ta.wma(ta.wma(_src,_length / 3) * 3 - ta.wma(_src, _length / 2) - ta.wma(_src, _length), _length) //SWITCH Mode(modeSwitch, src, len) => modeSwitch == "Hma" ? HMA(src, len) : modeSwitch == "Ehma" ? EHMA(src, len) : modeSwitch == "Thma" ? 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] //COLOR hullColor = switchColor ? (HULL > HULL[2] ? hull_bullish : hull_bearish ) : #000000 //// Background color according to Hull color bgcolor(bgcol_hullcol ? HULL > HULL[2] ? hull_bullish : hull_bearish : na) //PLOT ///< Frame Fi1 = plot(show_mhull ? MHULL : na, title="MHULL", color=hullColor, linewidth=thicknesSwitch) Fi2 = plot(show_shull ? SHULL : na, title="SHULL", color=hullColor, linewidth=thicknesSwitch) alertcondition(ta.crossover(MHULL, SHULL), title="Hull trending up.", message="Hull trending up.") alertcondition(ta.crossover(SHULL, MHULL), title="Hull trending down.", message="Hull trending down.") ///< Ending Filler fill(Fi1, Fi2, title="Band Filler", color=hullColor) ///BARCOLOR barcolor(color = candleCol ? (switchColor ? hullColor : na) : na)