Plot high and low of highest volume within X bar?

X

XeoNoX

New member
Hi, i was wondering if someone could help make this thinkscript, its just drawing HORIZONTAL lines at the price high and price low of the highest volume bar within the last 240 bars as pictured below. I get tired of manually having to do this all the time. Much appreciation if someone can help with this. Example below.

i can get this far in finding the highest volume bar, but i dont know how to plot it with the price lines.

Code:
input barsago = 240;

def HighestVolume =  Highest(volume, barsago);
 
Last edited:
markos

markos

Well-known member
VIP
@XeoNoX Try this snippet. Hacked from @tomsk share.
I'm sure this is incorrect, but I don't have access to the editor.

Code:
input period = 240;

def HighestVolume =  Highest (volume, period);

plot highLine = HighestAll (if isNaN then high (period) else Double.NaN);
plot LowLine = LowestAll (if isNaN then high (period) else Double.NaN);
 
X

XeoNoX

New member
markos that didnt work. and it returned some errors, I need it to plot at the largest volume bar, hence thats my dilema that i cant figure out. Anyone have any suggestions? i know it can be done, i just cant figure it out.
 
Last edited:
T

tomsk

Well-known member
VIP
@markos Hey, a valiant effort! It is probably easiest to capture the bar number where that high volume occurred and then note the high/low levels. AFter which you can then plot the lines forward from the bar number identified. I am working on this, should have this done in 5, maybe 10 minutes.
 
X

XeoNoX

New member
i tried this and it doesnt work, but it grabs atleast the volume bar, lol, my brain is going crazy trying to figure it out
Code:
declare upper;

input period = 240;
def na = Double.NaN;
def HighestVolume =  Highest (volume, period);

plot highLine = HighestAll (if na  then HighestAll (period) else Double.NaN);
plot LowLine = LowestAll (if na then Lowest (period) else Double.NaN);

highline.SetDefaultColor(GetColor(9));
highline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
addlabel(yes, highestvolume);
i tried this and it doesnt work, but it grabs atleast the volume bar, lol, my brain is going crazy trying to figure it out, ill wait for you @tomsk and thanks if you can figure it out!
 
T

tomsk

Well-known member
VIP
Hi, i was wondering if someone could help make this thinkscript, its just drawing HORIZONTAL lines at the price high and price low of the highest volume bar within the last 240 bars as pictured below. I get tired of manually having to do this all the time. Much appreciation if someone can help with this. Example below.


i can get this far in finding the highest volume bar, but i dont know how to plot it with the price lines.


Code:
input barsago = 240;

def HighestVolume =  Highest(volume, barsago);


@XeoNoX Per your request, here is your COMPLETED study. I have used the input of 240 bars that you mentioned in your description. This can be configurable in the user interface.

Here is the methodology - As with most things in the ThinkScript world, it would simplify things if you captured the bar number when the event took place. Then take note of the high/low at the bar number. Then you can do your plots forward from that bar number to the end of the chart. I have tested this against both intraday as well as daily, and ran it against charts of PCG (think that was your exmaple), AAPL, FB, etc

Here then is your study

Code:
# Plots High/Low Price at Highest Volume
# tomsk
# 12.4.2019

input barsago = 240;

def bar = barNumber();
def HighVolBar = if ((volume - Lowest(volume, barsago)) / 
                     (Highest(volume, barsago) - Lowest(volume, barsago))) >= 1
                 then bar
                 else Double.NaN;
def VolHighLevel = if !IsNaN(HighVolBar) then high else VolHighLevel[1];
def VolLowLevel = if !IsNaN(HighVolBar) then low else VolLowLevel[1];

plot HighLine = if bar >= HighestAll(HighVolBar) then VolHighLevel else Double.NaN;
plot LowLine = if bar >= HighestAll(HighVolBar) then VolLowLevel else Double.NaN;

HighLine.SetDefaultColor(Color.CYAN);
HighLine.SetLineWeight(3);
LowLine.SetDefaultColor(Color.YELLOW);
LowLine.SetLineWeight(3);
# End Plots High/Low Price at Highest Volume
 
X

XeoNoX

New member
yup, i would have never figured that out, thats advanced coding, brother @tomsk you are gifted, thank you very much. i am in amazment you did that in 10 minutes. i been trying for 2 days. And my average studies take me about a week and are no where near this complex. thanks again brother for your time.
 
T

tomsk

Well-known member
VIP
@XeoNoX I have seen your intermediate work, really nice to see you try different things.
Keep at it, I have no doubt that you'll be a master very soon.

Actually I was helping a user in another chatroom code something not too dissimilar - He was looking at plotting a horizontal line when there was a 50/200 EMA crossover. Same concept applies but different variables need to be tracked.
 
X

XeoNoX

New member
i have a few questions if you dont mind explaining. Why did you VOLUME MINUS LOWEST VOLUME from previous 240 bars? what does this do? in regular English it sounds like you subtracted the highest and lowest volume bar from 240 bars ago??? im so confused mind teaching me in a quick explination if you have time?

and what does the "/" and ">=1" do? And im still trying to figure out how the Double.NaN is used. Can you explain by any chance? thanks @tomsk

 
T

tomsk

Well-known member
VIP
That is a standard way of comparing range of high-low volumes across an extended period.
Compute the ratio divided by the range of the high-low volume.

If the value that is returned is > 1 then you got your higher volume scenario.
Let's say the ratio returned is 0.4, then you immediately know that you're running at 40% of the high-low volume

It does this computation as it works through every single bar across the chart
Double.NaN is the standard ThinkScript way of assigning NO VALUE
It's just the way I've learnt to do this.

EDIT: I thought it might be instructive to illustrate this by way of a simple example
Let's say you are trading AMZN and want to know how it is performing relative to it's high to low range
Run the following script and you'll see that it is at 18%, so not doing too good today.
Compare that with a ticker symbol of AAPL, it is running at about 68% so is doing good today
That is the general principle I was using in my calculations above.

Code:
# Range Performance
# tomsk
# 12.5.2019

input symb = "AMZN";

def h = high(symbol = symb, period = AggregationPeriod.DAY);
def l = low(symbol = symb, period = AggregationPeriod.DAY);
def c = close(symbol = symb, period = AggregationPeriod.DAY);
def R = (c - l) / (h - l);

AddLabel(1, symb + " currently at " + AsPercent(R) + " of daily range", Color.Yellow);
# End Range Performance
 
Last edited:
T

tradeking313

New member
@tomsk you are the man!!!! i was wondering if its a way to make a chart label on the daily chart of the highest total volume day of the year and also have the actual day it happened as well?
 
korygill

korygill

Active member
VIP
Just saw this thread. Could this indicator be used to achieve what you are looking for?

 
T

tomsk

Well-known member
VIP
@tomsk you are the man!!!! i was wondering if its a way to make a chart label on the daily chart of the highest total volume day of the year and also have the actual day it happened as well?

@tradeking313 Per your request here is a chart label that displays highest volume of the year together with the date that was traded.
make sure you run this on a DAILY aggregation. Interesting to note that on a stock like AAPL, the highest volume was precisely one year ago, on 1/3/2019. Have fun running this against your favorite stocks!

Code:
# Highest Daily Volume Label
# tomsk
# 1.3.2020

declare hide_on_intraday;

def H = volume == HighestAll(volume);
def HV = if H then volume else HV[1];
def MM = HighestAll(if H then GetMonth() else Double.NaN);
def DD = HighestAll(if H then GetDayOfMonth(GetYYYYMMDD()) else Double.NaN);
def YY = HighestAll(if H then GetYear() else Double.NaN);
AddLabel(1, "Highest Daily Volume (" + HV + ") Traded On " + MM + "/" + DD + "/" + AsPrice(YY), Color.Yellow);
# End Highest Daily Volume Label
 
T

tradeking313

New member
@XeoNoX @tomsk i love the plotting of the highest volume bar on the Daily chart. Great work!!!..Now im wondering if theres a way to create a scanner that finds stocks that has hit its highest volume bar on the Daily aggregation within X bars ago. ( i.e. 5 days ago)
 
T

tomsk

Well-known member
VIP
@XeoNoX @tomsk i love the plotting of the highest volume bar on the Daily chart. Great work!!!..Now im wondering if theres a way to create a scanner that finds stocks that has hit its highest volume bar on the Daily aggregation within X bars ago. ( i.e. 5 days ago)

@tradeking313 Sure thing - place the following code directly in the scanner. It will find the highest daily volume that triggered within the last 5 bars. Running this scan against the S&P 500 I obtained 1 result and for the NASDAQ Comp, there were 56 results.

Code:
volume == HighestAll(volume) within 5 bars
 
T

tradeking313

New member
@tomsk thanks so much...you the man!!!!!!!!!!!!!!!
 

Top