New High/Low Bar Counter

static

New member
I am looking for a script that would count new highs or lows bar by bar based on the timeframe that's been set.

See example below, each time the 15 min bar made a new high above the previous high, the counter would be indexed up.

Not looking for this to be drawn on the chart, just a simple numerical counter that could be used for scanning purposes.

NdPKqSy.png


Inputs:
Aggregation Time: 1 min, 5 min, 1 hr, 1 day, or whatever
Start Time: 9:30 AM
End Time: 4 PM

Output:
Number of new highs from start time to current time
+ would indicate new highs
- would indicate new lows

If anyone can help, I really appreciate it

Thank you
 
Solution
@static this should fit your needs. You choose your aggregation period when setting up the scan.
Ruby:
input Start_Time = 0930;
input Hide_Plots = yes;

def H = if SecondsTillTime(Start_Time) == 0 then high else if high > H[1] then high else H[1];
def HCount = if SecondsTillTime(Start_Time) == 0 then 0 else if H <> H[1] then HCount[1] + 1 else HCount[1];
plot HCP = HCount;
HCP.setpaintingStrategy(paintingStrategy.VALUES_ABOVE);
HCP.SetHiding(Hide_Plots);

def L = if SecondsTillTime(Start_Time) == 0 then low else if low < L[1] then low else L[1];
def LCount = if SecondsTillTime(Start_Time) == 0 then 0 else if L <> L[1] then LCount[1] - 1 else LCount[1];
plot LCP = LCount;
LCP.setpaintingStrategy(paintingStrategy.VALUES_BELOW)...
@static this should fit your needs. You choose your aggregation period when setting up the scan.
Ruby:
input Start_Time = 0930;
input Hide_Plots = yes;

def H = if SecondsTillTime(Start_Time) == 0 then high else if high > H[1] then high else H[1];
def HCount = if SecondsTillTime(Start_Time) == 0 then 0 else if H <> H[1] then HCount[1] + 1 else HCount[1];
plot HCP = HCount;
HCP.setpaintingStrategy(paintingStrategy.VALUES_ABOVE);
HCP.SetHiding(Hide_Plots);

def L = if SecondsTillTime(Start_Time) == 0 then low else if low < L[1] then low else L[1];
def LCount = if SecondsTillTime(Start_Time) == 0 then 0 else if L <> L[1] then LCount[1] - 1 else LCount[1];
plot LCP = LCount;
LCP.setpaintingStrategy(paintingStrategy.VALUES_BELOW);
LCP.SetHiding(Hide_Plots);
 
Solution

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

@Svanoy how do you change color of values above or below? is this correct?

input Start_Time = 0930;
input Hide_Plots = yes;

def H = if SecondsTillTime(Start_Time) == 0 then high else if high > H[1] then high else H[1];
def HCount = if SecondsTillTime(Start_Time) == 0 then 0 else if H <> H[1] then HCount[1] + 1 else HCount[1];
plot HCP = HCount;
HCP.setpaintingStrategy(paintingStrategy.VALUES_ABOVE);
HCP.SetHiding(Hide_Plots);
HCP.SetDefaultColor(Color.white);


def L = if SecondsTillTime(Start_Time) == 0 then low else if low < L[1] then low else L[1];
def LCount = if SecondsTillTime(Start_Time) == 0 then 0 else if L <> L[1] then LCount[1] - 1 else LCount[1];
plot LCP = LCount;
LCP.setpaintingStrategy(paintingStrategy.VALUES_BELOW);
LCP.SetHiding(Hide_Plots);
LCP.SetDefaultColor(Color.white);
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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