Author Message:
SuperTrend Volume [BigBeluga] is an advanced trend-following indicator that combines the traditional SuperTrend method with a normalized volume visualization inside trend bands, offering enhanced insight into market dynamics and volume activity.
CODE:
CSS:
#// Indicator For TOS
#// © BigBeluga
#indicator("SuperTrend Volume [BigBeluga]", overlay = true, max_lines_count = 50
# Converted by Sam4Cok@Samer800 - 12/2024
input atrLength = 25;
input multiplier = 4.0; #, "Bands", step = 0.01)
input VolumePlotType = {default "Bars", "Area"}; # "Volume Type", == "Bars"
input lookbackPeriod = 200;
def na = Double.NaN;
def bar = VolumePlotType == VolumePlotType."Bars";
Script supertrend {
input factor = 3;
input atrPeriod = 10;
def src = hl2;
def tr = if isNaN(high[1]) then (high - low) else
if !high[1] then (high - low) else TrueRange(high, close, low);
def atr = WildersAverage(tr, atrPeriod);
def upBand = src + factor * atr;
def loBand = src - factor * atr;
def lowerBand; def upperBand;
def prevLowerBand = if isNaN(lowerBand[1]) then loBand else
if !lowerBand[1] then loBand else lowerBand[1];
def prevUpperBand = if isNaN(upperBand[1]) then upBand else
if !upperBand[1] then upBand else upperBand[1];
lowerBand = if loBand > prevLowerBand or close[1] < prevLowerBand then loBand else prevLowerBand;
upperBand = if upBand < prevUpperBand or close[1] > prevUpperBand then upBand else prevUpperBand;
def _direction;
def superTrend;
def prevSuperTrend = superTrend[1];
if isNaN(atr[1]) {
_direction = 1;
} else if !atr[1] {
_direction = 1;
} else if prevSuperTrend == prevUpperBand {
_direction = if close > upperBand then -1 else 1;
} else {
_direction = if close < lowerBand then 1 else -1;
}
superTrend = if _direction == -1 then lowerBand else upperBand;
plot st = if isNaN(superTrend) then Double.NaN else superTrend;
plot dir = if isNaN(_direction) then Double.NaN else _direction;
}
#// CALCULATIONS
def supertrend = supertrend(multiplier, atrLength).st;
def direction = supertrend(multiplier, atrLength).dir;
def distance = Average(high - low, lookbackPeriod);
def supertrend1 = supertrend + distance * direction ;
def n_vol = Min(4, (volume / StDev(volume, lookbackPeriod)));
def step = (supertrend - supertrend1) / 4;
def trend_change = direction != direction[1];
def volLine = if !trend_change then supertrend1 + step * n_vol else na;
def hiVol = n_vol == 4;
#-- PLot Lines
plot ST_line1 = if !trend_change and supertrend1 then supertrend1 else na;
plot ST_line = if !trend_change and supertrend then supertrend else na;
ST_line1.SetLineWeight(2);
ST_line1.AssignValueColor(if direction < 0 then if hiVol then Color.CYAN else CreateColor(0, 128, 128) else
if hiVol then Color.MAGENTA else Color.PLUM);
ST_line.AssignValueColor(if direction < 0 then CreateColor(0, 128, 128) else Color.PLUM);
#-- Area
AddCloud(if bar then na else if hiVol then volLine else na, ST_line1, Color.CYAN , Color.MAGENTA);
AddCloud(if bar then na else volLine, ST_line1, Color.CYAN , Color.MAGENTA);
#-- Bars
def conUp1 = bar and !trend_change and direction < 0 and hiVol;
def conUp = bar and !trend_change and direction < 0 and !hiVol;
def conDn1 = bar and !trend_change and direction > 0 and hiVol;
def conDn = bar and !trend_change and direction > 0 and !hiVol;
AddChart(open = if conUp1 then volLine else na, high = ST_line1 ,
low = volLine , close = if conUp1 then ST_line1 else na,
type = ChartType.CANDLE, growcolor = Color.CYAN);
AddChart(open = if conUp then volLine else na, high = ST_line1 ,
low = volLine , close = if conUp then ST_line1 else na,
type = ChartType.CANDLE, growcolor = CreateColor(0, 128, 128));
AddChart(open = if conDn1 then ST_line1 else na, high = ST_line1 ,
low = if conDn1 then volLine else na, close = if conDn1 then volLine else na,
type = ChartType.CANDLE, growcolor = Color.MAGENTA);
AddChart(open = if conDn then ST_line1 else na, high = ST_line1,
low = if conDn then volLine else na, close = if conDn then volLine else na,
type = ChartType.CANDLE, growcolor = Color.PLUM);
#// Max Vol points
plot volDn = if hiVol and direction > 0 then high else na;
plot volUp = if hiVol and direction < 0 then low else na;
volUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
volDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
volUp.SetDefaultColor(Color.CYAN);
volDn.SetDefaultColor(Color.MAGENTA);
#-- END of CODE