Hello. New to the community!! I'm wondering if it's possible to resize the VolumeAVG study when placing it on the Price chart? Reason I would like to do this is so there is little to no overlap on the price candles. I'd like the study to be anchored to the bottom of the price chart & have the tops of the volume bars no higher than 15-20% from the bottom of the price chart. I also remove the moving average plot from this study so its just the volume bars... Is something like this possible with thinkScript? Or maybe something like this is available already to the community? Appreciate anyones help. Cheers!!
hello and welcome
here is one way,
this draws volume bars on the main chart.
it finds the price range of price bars,
pick 2 percentages, for height and bottom of bars,
then scale the volume bars
this determines the height of volume bars, a % of the price range of candles, lowest to highest.
..input vol_ht_per_of_prices = 25;
this determines the base of volume bars, a % of the price range of candles, lowest to highest.
this price number is subtracted from the lowest price level.
..input vol_per_pos_from_price_lowest = -30;
...if set to 50, it would put the bottom of volume bars in the middle of the chart.
Code:
# vol_bars_on_main_00
# https://usethinkscript.com/threads/resize-volumeavg-to-prevent-overlap-w-price-for-thinkorswim.13212/
# Resize VolumeAVG study on Price chart
def bn = barnumber();
def na = double.nan;
def iscls = !isnan(close);
#input averagetype = averagetype.simple;
#input length = 5;
#def avg = movingaverage(averagetype, close, length);
def hihi = highestall(high);
def lolo = lowestall(low);
def hilorng = hihi - lolo;
input vol_ht_per_of_prices = 25;
input vol_per_pos_from_price_lowest = -30;
def vol_ht = hilorng * (vol_ht_per_of_prices/100);
def vol_base = lolo + (hilorng * (vol_per_pos_from_price_lowest/100));
def vol_top = vol_base + vol_ht;
input show_line_levels = no;
plot zh = if iscls then hihi else na;
plot zl = if iscls then lolo else na;
plot zv2 = if iscls then vol_top else na;
plot zv1 = if iscls then vol_base else na;
zh.SetHiding(!show_line_levels);
zl.SetHiding(!show_line_levels);
zv2.SetHiding(!show_line_levels);
zv1.SetHiding(!show_line_levels);
zh.SetDefaultColor(Color.gray);
zl.SetDefaultColor(Color.gray);
zv2.SetDefaultColor(Color.cyan);
zv1.SetDefaultColor(Color.white);
# x.setlineweight(1);
# x.hidebubble();
#------------------------------
def v = volume;
def vol_max = highestall(v);
def vol_adj_top = vol_base + (vol_ht * (v/vol_max));
def vol_adj_bot = vol_base;
def c = vol_adj_bot;
def o = vol_adj_top;
def l = c;
def h = o;
AddChart(high = h, low = l, open = o, close = c, growcolor = color.blue, fallcolor = color.yellow, type = ChartType.CANDLE);
#
in this image, i have lines turned on, that define the price range highest and lowest, and the range of volume bars