Highest / HighestAll problem in my little script

lolo

New member
Hello everyone,

I wanted to create a script that calculates the percentage difference between the Pre Market high preferably 04:00 a.m until 09:29 a.m. editable.

An error appeared, the text HighestAll (Period is highlighted in red.

Can someone fix this problem?

Python:
input period_Type = AggregationPeriod.DAY;
input PrestartTime = 0400;
input PreendTime = 0929;

def begin = Highest(period = period_Type);
def end = close(period = period_Type);
def NetChg = begin - end;
def PctChg = (begin / end) - 1;

AddLabel(yes, Concat("%PM High to open = " , end), color.white);
Thanks a lot.
 
Solution
i need a way to get the median of a var for all the bars on the chart.

something like medianAll doesn't exist
highestAll exists.

you can get "averageAll" by doing totalSum(var)/barnumber()
that gets you the average for all the bars

but i dont know how to get the median for all the bars.

EDIT -
this is not the median ,
it is a value from the middle bar, in a set of bars

a median number, requires the data set to be put in order, and i didn't do that in this code.

-------------------------------------
is this what you want?

median,
middle number of a set

Code:
def lastbar = !isnan(close) and isnan(close[-1]);
def barz = floor(barnumber()/2);
def med = if lastbar then getvalue(close, barz) else 0;
addlabel(1, med...
i need a way to get the median of a var for all the bars on the chart.

something like medianAll doesn't exist
highestAll exists.

you can get "averageAll" by doing totalSum(var)/barnumber()
that gets you the average for all the bars

but i dont know how to get the median for all the bars.

EDIT -
this is not the median ,
it is a value from the middle bar, in a set of bars

a median number, requires the data set to be put in order, and i didn't do that in this code.

-------------------------------------
is this what you want?

median,
middle number of a set

Code:
def lastbar = !isnan(close) and isnan(close[-1]);
def barz = floor(barnumber()/2);
def med = if lastbar then getvalue(close, barz) else 0;
addlabel(1, med, color.yellow);
#

untested

https://www.mathsisfun.com/median.html

https://www.khanacademy.org/math/st...n-median-basics/a/mean-median-and-mode-review
 
Last edited:
Solution

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

@halcyonguy
not sure i understand this solution.
a simpler way to ask my question is: how could i find the median volume on a chart?

the same way you could do:
highestAll(volume)

i wish i could do:
medianAll(volume)
to find the middle value of all the volumes.
 
@halcyonguy
not sure i understand this solution.
a simpler way to ask my question is: how could i find the median volume on a chart?

the same way you could do:
highestAll(volume)

i wish i could do:
medianAll(volume)
to find the middle value of all the volumes.

sorry, i jumped the gun , and answered too quickly on my cell.

a median number , is the middle number of an 'ordered' set of numbers.
i forgot the ordered part.. my code just finds the middle value, without reordering the data.

i will think on this...

-------

i can sort data and find the median.
just need to test a bit and clean it up
 
Last edited:
@halcyonguy
not sure i understand this solution.
a simpler way to ask my question is: how could i find the median volume on a chart?

the same way you could do:
highestAll(volume)

i wish i could do:
medianAll(volume)
to find the middle value of all the volumes.


is this what you want?

find median of all the volume bars (or some quantity from the last bar)

i have it as an upper study, now for testing, easier to see...

a sample

4WlNIjt.jpg



have to go, but will get back to this later....
 
@halcyonguy
thanks for giving it a go again, but not quite! that finds the median bar and then tells you its volume.

the median volume Value may not be the volume of the median bar. it may be some other bar.

for example for a chart with 5 bars on it, the median bar is the 3rd bar.

and lets say the volume values for the bars are:
5, 3 , 1 , 5 , 5

but the median bar's volume value would be 1

but the median volume value for all of them is 3.

i'm looking for the 3. the actual median volume value. it doesn't matter what bar its on.
 
This will get you the median volume on a lower plot:
Code:
declare lower;
input length = 50;
def v = volume;
plot median_volume = median(data = v, length = length);

There is no medianAll, but you can set the length to something lengthy and get an approximation of medianAll().

-mashume
 
@halcyonguy
thanks for giving it a go again, but not quite! that finds the median bar and then tells you its volume.

no, it doesn't.
but i guess it's hard to tell from a picture.
it resorts all the volume values ,
then finds the middle of that resorted list,
and reads a value from the resorted list,
NOT the middle volume bar.

the median volume Value may not be the volume of the median bar. it may be some other bar.

for example for a chart with 5 bars on it, the median bar is the 3rd bar.

and lets say the volume values for the bars are:
5, 3 , 1 , 5 , 5

but the median bar's volume value would be 1

but the median volume value for all of them is 3.

i'm looking for the 3. the actual median volume value. it doesn't matter what bar its on.

that's not median.
that's not what those links say that i posted.

-----

LOL, good grief , there is a median function?
i seem to find the hardest way to do things.....

will compare it to mine
 
This will get you the median volume on a lower plot:
Code:
declare lower;
input length = 50;
def v = volume;
plot median_volume = median(data = v, length = length);

There is no medianAll, but you can set the length to something lengthy and get an approximation of medianAll().

-mashume
indeed. i'm just looking for the value to adjust to the current median on a constant basis bcuz i'm using the variable in another function. has to be real time
 
indeed. i'm just looking for the value to adjust to the current median on a constant basis bcuz i'm using the variable in another function. has to be real time
You're gunna have to give us a bit more to work with than that. The better you describe (and provide code if you can) what you're trying to do, the better we'll be able to help you get where you want to be. Also, what do you mean by 'real time'? Since it is not using an xyzAll() function (which now only update once per bar) or put declare once_per_bar at the head of your script, it will update as the price changes.

You can use the value of median_volume anywhere else in your script you need, obviously. But now I'm just taking guesses at what you're thinking because I really don't know.

-mashume
 
@mashume
all i meant was,

for example on a 2m Today chart, during normal trading hours:

i need the median volume value for all bars, but the bars will keep appearing and increasing. so the fixed length in the median() function isn't getting me all the bars.

best !
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
342 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

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.

How do I get started?

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.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top