Join useThinkScript to post your question to a community of 21,000+ developers and traders.
yes this works
if (today - first trading date >= 365)
then
highest(volume,today-first trading date)
else
highest(volume,365)
declare lower;
plot enhancedVolume = volume;
enhancedVolume.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
def highestVolYear = highest(volume,252);
enhancedVolume.assignValueColor(if volume == highestVolYear then COLOR.WHITE);
declare lower;
plot enhancedVolume = volume;
enhancedVolume.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
def highestVolYear = highest(volume,252);
enhancedVolume.assignValueColor(if volume == highestVolYear then COLOR.WHITE else COLOR.GRAY);
## Highest Volume in the past XYZ bars v1.0
## Works with recently listed IPOs and Trading Instruments
## Default is 252 Days which is Highest Volume in past Year
## Set to Day Agreggation
## By XeoNoX via usethinkscript.com April 02,2021
declare lower;
Input BarsAgo = 252;
def hv = if volume > hv[1] then volume else hv[1];
def highestVolYear = if isnan(highest(volume,barsago)) then hv else highest(volume,barsago);
AddLabel (yes, "Highest Volume " + (highestVolYear ) );
plot scan = highestVolYear;
its not a number so you must use ISNAN
remember to leave a thumbs up if you found this post useful
here is what you originally requested:
Highest Volume in the past XYZ bars (version 1.0)
Works with recently listed IPOs and Trading Instruments
Default is 252 Days which is Highest Volume in past Year
Set to Day Aggregation
Code:## Highest Volume in the past XYZ bars v1.0 ## Works with recently listed IPOs and Trading Instruments ## Default is 252 Days which is Highest Volume in past Year ## Set to Day Agreggation ## By XeoNoX via usethinkscript.com April 02,2021 declare lower; Input BarsAgo = 252; def hv = if volume > hv[1] then volume else hv[1]; def highestVolYear = if isnan(highest(volume,barsago)) then hv else highest(volume,barsago); AddLabel (yes, "Highest Volume " + (highestVolYear ) ); plot scan = highestVolYear;
explanation:
if volume is greater then the previous volume then use that volume else keep searching
def hv = if volume > hv[1] then volume else hv[1];
if the highest volume from the past 252 bars is not a number then use HV else if it is a number then use highest volume from past 252 bars
def highestVolYear = if isnan(highest(volume,barsago)) then hv else highest(volume,barsago);
Yes, I get a label, but no volume histogram. You can see where the cursor is over the NewStudy2 the value is N/A over on the right axis.
Thanks for your help on this.
#Example Highest Volume within Last barsago
#Usethinkscript request
#Workaround to handle charts with less than barsago input bars
#Sleepyz
#Use at least on a 2 YEAR DAILY CHART
input barsago = 252;
input showlabel = yes;
def lastbar = if IsNaN(close[-1]) and !IsNaN(close) then BarNumber() else Double.NaN;
def range = CompoundValue(1, if Between(BarNumber(), HighestAll(lastbar) - barsago, HighestAll(lastbar)) then 1 else 0, 1);
#Highest Volume on a chart with more bars than barsago
def vol = if range[1] == 0 and range == 1
then volume
else if volume > vol[1]
then volume
else vol[1];
def volext = if BarNumber() > HighestAll(lastbar) then volext[1] else vol;
def volb = if range == 1 and volume == vol
then BarNumber()
else Double.NaN;
plot v252_end = if HighestAll(lastbar) > barsago and BarNumber() >= HighestAll(volb)
then volext
else Double.NaN;
v252_end.setdefaultColor(color.yellow);
v252_end.setpaintingStrategy(paintingStrategy.HORIZONTAL);
#Highest Volume on a chart with less bars than barsago
def r = if HighestAll(lastbar) < barsago then 1 else 0;
def volh = if BarNumber() == 1 and !IsNaN(range)
then volume
else if volume > volh[1]
then volume
else volh[1];
def volhext = if BarNumber() > HighestAll(lastbar) then volhext[1] else volh;
def volb1 = if volume == volh
then barnumber()
else Double.NaN;
plot v1_end = if isnan(r) or r then volhext else double.nan;
v1_end.setdefaultColor(color.yellow);
v1_end.setpaintingStrategy(paintingStrategy.HORIZONTAL);
AddLabel(showlabel, "Highest Volume" + (if r==1 then " Less than " else " ") + barsago + " days ago == " + (if r==1 then volh else vol), Color.YELLOW);
addverticalLine(if r==1 then barnumber()==highestall(volb1) else barnumber()==highestall(volb),"",color.yellow);
Thanks for taking the time to respond @SleepyZ. I am still trying to fully understand the code and how I could use it to get the desired bar color effects. Thanks again.See if this helps. This is a workaround some of thinkscript's limitations when dealing with symbols opened less than the 'barsago' days. As mentioned, there may be simpler solutions, but this may be what you are requesting. The attached chart shows the same study in both the upper and lower panes.
Code:#Example Highest Volume within Last barsago #Usethinkscript request #Workaround to handle charts with less than barsago input bars #Sleepyz #Use at least on a 2 YEAR DAILY CHART input barsago = 252; input showlabel = yes; def lastbar = if IsNaN(close[-1]) and !IsNaN(close) then BarNumber() else Double.NaN; def range = CompoundValue(1, if Between(BarNumber(), HighestAll(lastbar) - barsago, HighestAll(lastbar)) then 1 else 0, 1); #Highest Volume on a chart with more bars than barsago def vol = if range[1] == 0 and range == 1 then volume else if volume > vol[1] then volume else vol[1]; def volext = if BarNumber() > HighestAll(lastbar) then volext[1] else vol; def volb = if range == 1 and volume == vol then BarNumber() else Double.NaN; plot v252_end = if HighestAll(lastbar) > barsago and BarNumber() >= HighestAll(volb) then volext else Double.NaN; v252_end.setdefaultColor(color.yellow); v252_end.setpaintingStrategy(paintingStrategy.HORIZONTAL); #Highest Volume on a chart with less bars than barsago def r = if HighestAll(lastbar) < barsago then 1 else 0; def volh = if BarNumber() == 1 and !IsNaN(range) then volume else if volume > volh[1] then volume else volh[1]; def volhext = if BarNumber() > HighestAll(lastbar) then volhext[1] else volh; def volb1 = if volume == volh then barnumber() else Double.NaN; plot v1_end = if isnan(r) or r then volhext else double.nan; v1_end.setdefaultColor(color.yellow); v1_end.setpaintingStrategy(paintingStrategy.HORIZONTAL); AddLabel(showlabel, "Highest Volume" + (if r==1 then " Less than " else " ") + barsago + " days ago == " + (if r==1 then volh else vol), Color.YELLOW); addverticalLine(if r==1 then barnumber()==highestall(volb1) else barnumber()==highestall(volb),"",color.yellow);
input displace = 0;
input SMA3 = 252;
def MaxGain = ROUND(((Highest(high, displace+1) / open)-1),4)*100;
def MaxLoss = ROUND(((lowest(low, displace+1) / open)-1),4)*100;
def VolFactor = (MaxGain - MaxLoss);
Plot Avg = Average(VolFactor,SMA3)[1]
def DayCount= BarNumber()
Plot test = If DayCount < 252 then TotalSum(VolFactor) / DayCount else Average(VolFactor,252)[1];
Start a new thread and receive assistance from our community.
useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.
We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.
If you are new, or just looking for guidance, here are some helpful links to get you started.