I have the below script
https://usethinkscript.com/threads/time-based-volume-indicator-for-thinkorswim.124/
that looks at average volume over a period of 100 days compared to current bar. i want the volume it gets to only display on the prior bar. can someone adjust the script to only display for previous bar?
# source: Time Based Volume
# original author: Robert Payne
declare lower;
input LookBack = 20;
def nMinutes = GetAggregationPeriod() / 60000;
def nBars = RoundUp(390 / nMinutes, 0);
def pvSum = fold idx = 1 to LookBack + 1 with a=0 do a + GetValue(volume, idx * nBars, LookBack * nBars);
def pvAvg = pvSum / LookBack;
def VolPct = (volume / pvAvg) * 100;
AddLabel(
yes,"Volume Buzz: " +
VolPct,
Color.green
);
plot avgLine = 100;
avgLine.SetDefaultColor(Color.GRAY);
avgLine.SetStyle(Curve.LONG_DASH);
def lastUp = if IsNaN(lastUp[1]) then 0 else if (close > open) then VolPct else lastUp[1];
def lastDn = if IsNaN(lastDn[1]) then 0 else if (close < open) then VolPct else lastDn[1];
plot Vol = VolPct;
Vol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Vol.SetLineWeight(3);
Vol.DefineColor("Bullish", Color.GREEN);
Vol.DefineColor("Bullish Smaller", Color.DARK_GREEN);
Vol.DefineColor("Bearish", Color.RED);
Vol.DefineColor("Bearish Smaller", Color.DARK_RED);
Vol.AssignValueColor(if (close > open) and (VolPct > lastUp[1]) then Vol.Color("bullish" ) else if close > open then Vol.Color("bullish smaller" ) else if close < open and VolPct > lastDn[1] then Vol.Color("bearish" ) else Vol.Color("bearish smaller" ));
AssignPriceColor(if (close > open) and (VolPct > lastUp[1]) then Vol.Color("bullish" ) else if close > open then Vol.Color("bullish smaller" ) else if close < open and VolPct > lastDn[1] then Vol.Color("bearish" ) else Vol.Color("bearish smaller" ));
https://usethinkscript.com/threads/time-based-volume-indicator-for-thinkorswim.124/
that looks at average volume over a period of 100 days compared to current bar. i want the volume it gets to only display on the prior bar. can someone adjust the script to only display for previous bar?
# source: Time Based Volume
# original author: Robert Payne
declare lower;
input LookBack = 20;
def nMinutes = GetAggregationPeriod() / 60000;
def nBars = RoundUp(390 / nMinutes, 0);
def pvSum = fold idx = 1 to LookBack + 1 with a=0 do a + GetValue(volume, idx * nBars, LookBack * nBars);
def pvAvg = pvSum / LookBack;
def VolPct = (volume / pvAvg) * 100;
AddLabel(
yes,"Volume Buzz: " +
VolPct,
Color.green
);
plot avgLine = 100;
avgLine.SetDefaultColor(Color.GRAY);
avgLine.SetStyle(Curve.LONG_DASH);
def lastUp = if IsNaN(lastUp[1]) then 0 else if (close > open) then VolPct else lastUp[1];
def lastDn = if IsNaN(lastDn[1]) then 0 else if (close < open) then VolPct else lastDn[1];
plot Vol = VolPct;
Vol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Vol.SetLineWeight(3);
Vol.DefineColor("Bullish", Color.GREEN);
Vol.DefineColor("Bullish Smaller", Color.DARK_GREEN);
Vol.DefineColor("Bearish", Color.RED);
Vol.DefineColor("Bearish Smaller", Color.DARK_RED);
Vol.AssignValueColor(if (close > open) and (VolPct > lastUp[1]) then Vol.Color("bullish" ) else if close > open then Vol.Color("bullish smaller" ) else if close < open and VolPct > lastDn[1] then Vol.Color("bearish" ) else Vol.Color("bearish smaller" ));
AssignPriceColor(if (close > open) and (VolPct > lastUp[1]) then Vol.Color("bullish" ) else if close > open then Vol.Color("bullish smaller" ) else if close < open and VolPct > lastDn[1] then Vol.Color("bearish" ) else Vol.Color("bearish smaller" ));
Last edited by a moderator: