# alt_volume_histo_01 modified
# alt volume chart
# show volume bars only up to a certain level
# This indicator goes in the lower subgraph (not on the main price chart)
declare lower;
# ===== BASIC DEFINITIONS =====
def bn = barnumber(); # Current bar number (not used in this script)
def na = double.nan; # Define NaN (Not a Number) for hiding plots
def dat = volume; # Store volume data in 'dat' variable
def vmax = highestall(dat); # Find the highest volume across ALL bars in the chart
# ===== VOLUME CUTOFF TYPE SELECTOR =====
# User can choose between two methods to set the cutoff level
input vol_cutoff_type = { default level , percent_of_max };
# ===== METHOD 1: FIXED LEVEL =====
input vol_level = 1000000; # User-defined cutoff level (default 1 million)
def sethi = (vmax < vol_level); # Check if max volume is less than user's cutoff
def vol_level2 = if sethi then vmax else vol_level; # If max < cutoff, lower cutoff to max
# This prevents setting a cutoff higher than any bar
# ===== METHOD 2: PERCENT OF MAX =====
input percent_of_maxvol = 60; # User-defined percentage (default 60%)
def per = (percent_of_maxvol / 100); # Convert percentage to decimal (60 -> 0.60)
# ===== DETERMINE WHICH METHOD TO USE =====
def num; # Variable to track which method is active (1 or 2)
def vlevel; # The actual cutoff level that will be used
switch (vol_cutoff_type) {
case level: # If user selected "level" method
num = 1;
vlevel = vol_level2; # Use the fixed level (possibly adjusted)
case percent_of_max: # If user selected "percent_of_max" method
vlevel = floor(per * vmax); # Calculate cutoff as % of max, round down
num = 2;
}
# ===== IDENTIFY BARS EXCEEDING CUTOFF =====
def big = (dat > vlevel); # TRUE if current bar's volume exceeds cutoff
# ===== PLOT ZERO LINE =====
plot z = 0; # Horizontal line at zero
z.SetDefaultColor(Color.gray);
# ===== PLOT CUTOFF LINE (OPTIONAL) =====
input show_cutoff_line = yes; # User option to show/hide cutoff line
plot zhi = if show_cutoff_line then vlevel else na; # Show horizontal line at cutoff level
zhi.SetDefaultColor(Color.gray);
# ===== PLOT MODIFIED VOLUME HISTOGRAM =====
# This is the main visual - shows volume bars capped at the cutoff level
# plot a mod histo of vol
plot vmod = if big then vlevel else dat;
vmod.SetPaintingStrategy(PaintingStrategy.histogram);
# Define colors for up/down volume
vmod.DefineColor("up", color.green); # Green for up days
vmod.DefineColor("down", color.red); # Red for down days
vmod.DefineColor("hi", color.cyan); # Cyan for volume exceeding cutoff
# Color based on price direction and volume level
vmod.AssignValueColor(
if (dat > vlevel) then vmod.color("hi") # Cyan if exceeds cutoff
else if (close > close[1]) then vmod.color("up") # Green if price up
else vmod.color("down") # Red if price down/flat
);
# ===== SHOW ACTUAL VALUES FOR BIG BARS (OPTIONAL) =====
input show_big_values = yes; # User option to display actual values
plot bigval = if (show_big_values and big) then round(dat/1000000, 2) else na;
# Show volume in millions (rounded to 2 decimals)
# Only for bars that exceed cutoff
bigval.SetPaintingStrategy(PaintingStrategy.values_below); # Display number below the bar
bigval.SetDefaultColor(Color.white);
# ===== CHART LABELS (OPTIONAL) =====
input show_labels = yes; # User option to show/hide all labels
# Labels for METHOD 1 (fixed level):
addlabel( show_labels and num == 1, "set level " + vol_level, color.yellow);
# Show the user's input level
addlabel( show_labels and num == 1 and sethi, "cutoff level lowered to", color.cyan);
# Warning that cutoff was auto-lowered
addlabel( show_labels and num == 1 and !sethi, "cutoff level " + vlevel, color.cyan);
# Show the actual cutoff being used
# Labels for METHOD 2 (percentage):
addlabel( show_labels and num == 2, "cutoff level " + vlevel, color.cyan);
# Show calculated cutoff level
addlabel( show_labels and num == 2, "is " + percent_of_maxvol + "% of", color.yellow);
# Show what percentage was used
# Label always shown (when labels enabled):
addlabel( show_labels, "max " + vmax, color.orange);
# Always show the maximum volume on the chart