Bar count todays High Low

ivctrader

New member
Hello everyone!
I would be very thankful for any help with the WATCHLIST script.
This script should show, in a watchlist column after Market Close: How many 1min bars from Market Open(9:30) was to the High of day and in another column how many 1min bars to the Low of day.
I was planing then converting this numbers to time in a excel for statistical purpose.


Example https://ibb.co/sgd0W1p
 
Last edited:
Solution
Hello mashume!
Thank you for a quick response and for tips!
I am sorry but I think you misunderstood me.
Basically, this script should count 1min bars To The High of Day from Market Open, and 1min bars To The Low of day.
For example after the market closed(16:00) we can see:
TSLA made high of day on 17s bar from open, and made low of day on 253 1min bar from open.
Try this
Ruby:
def bn = BarNumber();

def openbn  = if GetDay() == GetLastDay() and GetTime() crosses above RegularTradingStart(GetYYYYMMDD()) then bn else openbn[1];

def newhigh = if GetDay() == GetLastDay() and GetTime() crosses above RegularTradingStart(GetYYYYMMDD())
              then high
              else if GetTime() <= RegularTradingEnd(GetYYYYMMDD())...
I don't do much with watchlist scripts, but the basic idea would look like this:
Code:
def new_high = if HIGH > new_high[1] then 1 else 0;
def count = if new_high == 1 then 0 else count[1] + 1;
plot bars_since_high = count;

to break this down, the first line writes a series of 1s and 0s to indicate whether the bar has set a new high. (you could also SUM(new_high) and find out how many bars have set new highs through the day -- might be interesting.) The next line defines our count so that if the new_high is 1 then we reset the counter to 0 (you did say bars since the high, so the high doesn't count. change this line to 1 if you want the high to count as the first bar since). The last line plots it.

Hope that gets you started in the right direction.
Trade Happy,
mashume
 

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

I don't do much with watchlist scripts, but the basic idea would look like this:
Code:
def new_high = if HIGH > new_high[1] then 1 else 0;
def count = if new_high == 1 then 0 else count[1] + 1;
plot bars_since_high = count;

to break this down, the first line writes a series of 1s and 0s to indicate whether the bar has set a new high. (you could also SUM(new_high) and find out how many bars have set new highs through the day -- might be interesting.) The next line defines our count so that if the new_high is 1 then we reset the counter to 0 (you did say bars since the high, so the high doesn't count. change this line to 1 if you want the high to count as the first bar since). The last line plots it.

Hope that gets you started in the right direction.
Trade Happy,
mashume
Hello mashume!
Thank you for a quick response and for tips!
I am sorry but I think you misunderstood me.
Basically, this script should count 1min bars To The High of Day from Market Open, and 1min bars To The Low of day.
For example after the market closed(16:00) we can see:
TSLA made high of day on 17s bar from open, and made low of day on 253 1min bar from open.
 
Hello mashume!
Thank you for a quick response and for tips!
I am sorry but I think you misunderstood me.
Basically, this script should count 1min bars To The High of Day from Market Open, and 1min bars To The Low of day.
For example after the market closed(16:00) we can see:
TSLA made high of day on 17s bar from open, and made low of day on 253 1min bar from open.
Try this
Ruby:
def bn = BarNumber();

def openbn  = if GetDay() == GetLastDay() and GetTime() crosses above RegularTradingStart(GetYYYYMMDD()) then bn else openbn[1];

def newhigh = if GetDay() == GetLastDay() and GetTime() crosses above RegularTradingStart(GetYYYYMMDD())
              then high
              else if GetTime() <= RegularTradingEnd(GetYYYYMMDD())
              then Max(high, newhigh[1])
              else newhigh[1];

def newlow  = if GetDay() == GetLastDay() and GetTime() crosses above RegularTradingStart(GetYYYYMMDD())
              then low
              else if GetTime() <= RegularTradingEnd(GetYYYYMMDD())
              then Min(low, newlow[1])
              else newlow[1];

def hct = if high == HighestAll(newhigh) then bn else hct[1];
def lct = if low == LowestAll(newlow) then bn else lct[1];

AddLabel(1, "H: " + (hct - openbn ) + "; L: " + (lct - openbn ), Color.YELLOW);
 
Solution
Hello Sleepy Z!
Wow thank you very much!
The High count working very good(some counts a little of like 2-5 bars, but I will double check it)
But Low count stands 0.
High or Low will be zero if the first 0930 bar is the High or Low, as you said to count from open. If you want to count the first bar as part of the count then add + 1 to the counts. This scriipt only works during the regular trading session. If you have other issues, provide symbol info so I can see what is happening. Otherwise it seems to work on what I tested in OnDemand
 
High or Low will be zero if the first 0930 bar is the High or Low, as you said to count from open. If you want to count the first bar as part of the count then add + 1 to the counts. This scriipt only works during the regular trading session. If you have other issues, provide symbol info so I can see what is happening. Otherwise it seems to work on what I tested in OnDemand
Hello SleepyZ!
High of day count works great. But low of day stands all 0.
example: https://ibb.co/t3nJgbK

What do you think about counting 1min bars/closes from high/low of day to market close(16:00), maybe it is simpler to do?
 
Hello SleepyZ!
High of day count works great. But low of day stands all 0.
example: https://ibb.co/t3nJgbK

What do you think about counting 1min bars/closes from high/low of day to market close(16:00), maybe it is simpler to do?

The screenshot you provided is 11/25/2021, which is I believe is a non-trading day, so I am not sure what you were expecting and I cannot reproduce it in Ondemand. Again, if the low of the day is the open of regular trading, then the count will be 0, as I programmed it that way because I interpreted that you wanted the count to be since (after) the low, not including the low. Things look ok to me with the code on the charts. Make sure your watchlist code has extended hours checked as the code relies upon that be the case.
 
The screenshot you provided is 11/25/2021, which is I believe is a non-trading day, so I am not sure what you were expecting and I cannot reproduce it in Ondemand. Again, if the low of the day is the open of regular trading, then the count will be 0, as I programmed it that way because I interpreted that you wanted the count to be since (after) the low, not including the low. Things look ok to me with the code on the charts. Make sure your watchlist code has extended hours checked as the code relies upon that be the case.
I apologize ! I did not checked extended trading hours..... now everything works perfect!
Thank you again for the help!
https://ibb.co/sQrV2K2
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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