plot count candles below highest high

I want to plot the count of the number of candles that a stock fails to break above all time highs such that each candle will have a plot point returning a value of zero if a new highest high is made and 1 if it fails, accumulating that count each candle that fails.

so if you look at QQQ as of 1/14/22 it should have a plot point value of 37 because for the last 37 stock trading days it has failed to break over 408.71 the latest highest high on the daily set on 11/22/22

if QQQ breaks over 408.71 the highest high, then the plot point resets to 0; if the next day it breaks again a new highest high then that too would have a plot point of zero.

this will be great to track certain instruments to see how long they take to let bag holders who top tick, cash out and break even.

I am still trying to research the syntax for controlling the count and how to implement Count = count +1;

I have the logic sketched out, I don't get the syntax.

declare lower;
declare once_per_bar;

input length = 252; #number of trading days in one year on the daily chart

def BreakOutTarget = Highest(high[1], length);

plot countFail = if high[0] < BreakOutTarget then countFail = countFail + 1, else 0;


# plots the number of days a stock fails to make a new yearly high on the daily chart. will reset the plot to 0 each day it makes a new high. and count up one point for each day it fails.
 
I want to plot the count of the number of candles that a stock fails to break above all time highs such that each candle will have a plot point returning a value of zero if a new highest high is made and 1 if it fails, accumulating that count each candle that fails.

so if you look at QQQ as of 1/14/22 it should have a plot point value of 37 because for the last 37 stock trading days it has failed to break over 408.71 the latest highest high on the daily set on 11/22/22

if QQQ breaks over 408.71 the highest high, then the plot point resets to 0; if the next day it breaks again a new highest high then that too would have a plot point of zero.

this will be great to track certain instruments to see how long they take to let bag holders who top tick, cash out and break even.

I am still trying to research the syntax for controlling the count and how to implement Count = count +1;

I have the logic sketched out, I don't get the syntax.

declare lower;
declare once_per_bar;

input length = 252; #number of trading days in one year on the daily chart

def BreakOutTarget = Highest(high[1], length);

plot countFail = if high[0] < BreakOutTarget then countFail = countFail + 1, else 0;


# plots the number of days a stock fails to make a new yearly high on the daily chart. will reset the plot to 0 each day it makes a new high. and count up one point for each day it fails.

your line fixed.
Code:
plot countFail = if high[0] < BreakOutTarget then (countFail[1] + 1)  else 0;


or this.
i like to check first for changed conditions, then alter the value.
if no conditions are triggered, then the last section passes the previous value onto the current bar.

the first part of the countFail formula checks if the current high is equal to or higher than BreakOutTarget. if it is, then it sets the counter to 0.
if it isn't higher, then it must be lower. the second part of the formula reads the previous value of countFail, by using an offset of 1, and adds 1 to it.


Code:
input length = 252;
def BreakOutTarget = Highest(high[1], length);

plot countFail = 
if high >= BreakOutTarget then 0
else countFail[1] + 1;
 
I will try this to fix that error

declare lower;
declare once_per_bar;

input length = 252;
def BreakOutTarget = Highest(high[1], length);

def CountFail = 0;
plot CF = countFail and if high >= BreakOutTarget then 0
else countFail[1] + 1;

# this fixes the error but still produces no result. gives value 0 without doing any counting.
 

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
418 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