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...
@lolo A quick review of the Highest() function in the Thinkscript Learning Center will answer your question... Bookmark the Learning Center as you'll spend plenty of time there... I have a browser tab open there 24/7... Hint: period is part of price...
Thanks for your hint, I found it.
Now I tried to put it in percentage, I can't do it with AsPercent there is an error so in this code I remove it and
he shows it to me in Net Change.
I think there is an error in the NetChg result

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

def begin = Highest(high, 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);
 
@lolo Shouldn't it be:
Ruby:
def PctChg = NetChg / begin;
@rad14733 Yes thanks but the label is not visible the label is not visible since I changed End to PctChg in AddLabel

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

def begin = Highest(high, period_Type);
def end = close(period = period_Type);
def NetChg = begin - end;
def PctChg = ((NetChg / begin) * 100);

AddLabel(yes, Concat("%PM High to open = " , PctChg), color.white);
 
Last edited:
@lolo The issue was that you didn't follow the parameter syntax for Highest() as I pointed out earlier... Unfortunately, the parser was unable to throw the error experienced within the function itself... The Learning Center is your friend... When in doubt, Copy & Paste code from there and edit as needed... You may need to adjust the length parameter...

Ruby:
input period_Type = AggregationPeriod.DAY;
input length = 12;
input PrestartTime = 0400;
input PreendTime = 0929;

def begin = Highest(high(period = period_Type), length);
def end = close(period = period_Type);
def NetChg = begin - end;
def PctChg = ((NetChg / begin) * 100);

AddLabel(yes, Concat("%PM High to open = " , PctChg), color.white);
 
My code works, but it doesn't give me the right result and I don't know why. I would like him to calculate the difference between the highest in premarket and the current price included in the timetables 04:00 a.m until 09:29 a.m

If you can look at the problem I would be very grateful

Thank you in advance

Python:
#Label

#% Change PreMarket High to Open

#27-07-2021 from Lolo

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

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

AddLabel(yes, "%PM high to open: " + NetChg + " (" + AsPercent(PctChg) + ")", if NetChg > 0 then Color.GREEN else if NetChg < 0 then color.WHITE else color.LIGHT_GRAY);
 
@lolo The issue was that you didn't follow the parameter syntax for Highest() as I pointed out earlier... Unfortunately, the parser was unable to throw the error experienced within the function itself... The Learning Center is your friend... When in doubt, Copy & Paste code from there and edit as needed... You may need to adjust the length parameter...

Ruby:
input period_Type = AggregationPeriod.DAY;
input length = 12;
input PrestartTime = 0400;
input PreendTime = 0929;

def begin = Highest(high(period = period_Type), length);
def end = close(period = period_Type);
def NetChg = begin - end;
def PctChg = ((NetChg / begin) * 100);

AddLabel(yes, Concat("%PM High to open = " , PctChg), color.white);
yes i know it is "missing length" i guess it is bar count. But precisely, I want this code to work as well at 04:30 as at 08:40 for example, that's why I don't want to define a number of bars by default
 
Here is the new structure but it does not work yet there is no error reported

Python:
#Label

#% Change PreMarket High to Open

#27-07-2021 from Lolo

input OpenTime          = 0400;
input CloseTime         = 0929;
def secondsFromOpen     = SecondsFromTime( OpenTime );
def secondsTillClose    = SecondsTillTime( CloseTime );
def marketOpen          = secondsFromOpen >= 0 and secondsTillClose >= 0;

def begin = Highest(high(period = marketOpen),1);
def end = close(period = marketOpen);
def NetChg = end - begin;
def PctChg = (NetChg / begin);

AddLabel(yes, "%PM high to open: " + NetChg + " (" + AsPercent(PctChg) + ")", if NetChg > 0 then Color.GREEN else if NetChg < 0 then color.WHITE else color.LIGHT_GRAY);
 
@lolo Your code probably won't work because your new var, marketOpen can only be a valid aggregation period... I don't have time to look deeper into this at the moment but, as I stated, you probably need to rethink your overall logic... To be honest, I don't do much with the whole premarket/aftermarket thing, only some minor time constraints... My trading style doesn't require much time or barcount manipulation... However, we do have a few members who excel in those areas and perhaps one of them will have time to step in and assist - otherwise I will try to delve deeper once I am caught up...
 
This works on 30 min chart.
Ruby:
input prestartTime = 0400;

# Use 5 in next statement as on 30 min chart there are 5 bars between 0400 and 0930

def preMarketHigh = if SecondsFromTime(preStartTime) == 5.5 * 60 * 60 then Highest(high, 5) else preMarketHigh[1];
def marketOpen = if secondsFromTime(0930) == 0 then open else marketOpen[1];

addlabel(1,"%PM High to Bar Open:"+(100*((marketOpen-premarketHigh)/marketOpen))+"%");
 
@lolo Your code probably won't work because your new var, marketOpen can only be a valid aggregation period... I don't have time to look deeper into this at the moment but, as I stated, you probably need to rethink your overall logic... To be honest, I don't do much with the whole premarket/aftermarket thing, only some minor time constraints... My trading style doesn't require much time or barcount manipulation... However, we do have a few members who excel in those areas and perhaps one of them will have time to step in and assist - otherwise I will try to delve deeper once I am caught up...
@rad14733 thank you for you Help. I would have learned things thanks to you, I am starting on TOS. Good luck and thank you
 
This works on 30 min chart.
Ruby:
input prestartTime = 0400;

# Use 5 in next statement as on 30 min chart there are 5 bars between 0400 and 0930

def preMarketHigh = if SecondsFromTime(preStartTime) == 5.5 * 60 * 60 then Highest(high, 5) else preMarketHigh[1];
def marketOpen = if secondsFromTime(0930) == 0 then open else marketOpen[1];

addlabel(1,"%PM High to Bar Open:"+(100*((marketOpen-premarketHigh)/marketOpen))+"%");
@_Merch_Man_ thank you very much for this script, i will try it out and surely try to modify it to work on any type of time unit from the different charts.
 
I tested this code, the result is not the right one by a few percent which is still important as a deviation.

I would like to create a script that continuously calculates the percentage difference between the high of the premarket and the current market price until the open is 09:30 a.m. Can be used on a 1 min or 5 min charts.

If anyone has any ideas, I'm interested.

Thanks in advance,

Lolo
 
I continued my research and restructured my script. But the result is still not the right one
Ruby:
# % Change Pre Market to Open

#  28-07-2021

# Created by Lolo

def PreMktOpen = GetYYYYMMDD() != GetYYYYMMDD()[1];
def PreMktHrs = GetTime() < RegularTradingStart(GetYYYYMMDD());
def RegMktHrs = (GetTime() >= RegularTradingStart(GetYYYYMMDD())) and (GetTime() < RegularTradingEnd(GetYYYYMMDD()));

def pHigh = if PreMktOpen and PreMktHrs then high
            else if PreMktOpen and RegMktHrs then Double.NaN
            else if PreMktHrs and high > pHigh[1] then high
            else pHigh[1];
def lastPrice = close(priceType = PriceType.LAST);
def NetChg = pHigh - lastPrice;
def PctChg = (NetChg / pHigh);

AddLabel(yes, "%PM high to open: " + NetChg + " (" + AsPercent(PctChg) + ")", if NetChg > 0 then Color.WHITE else if NetChg < 0 then color.WHITE else color.LIGHT_GRAY);
 
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.
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
506 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