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
Warehouse
@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
Warehouse
@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
Warehouse
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
Warehouse
@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
Warehouse
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:

Top