10 bar avg range

offshore

Member
I have a real simple indicator im trying to make...just something that notifies me of the avg range of the last 10 bars on a 5 minute chart.
I have this code which ive been messing with to get it t actually produce something but cant get it to work... any help would be appreciated. Thanks
def cond = (high - low) > Average((high - low), 10)
 
Solution
I have a real simple indicator im trying to make...just something that notifies me of the avg range of the last 10 bars on a 5 minute chart.
I have this code which ive been messing with to get it t actually produce something but cant get it to work... any help would be appreciated. Thanks
def cond = (high - low) > Average((high - low), 10)

you didn't say what you want to see, so i guessed from your formula,
(high - low) > Average((high - low),
it looks like you want to know when todays high-low range is higher (or lower) than the average.

when i compared the range to the average,
def isup = (rng > avg[1]);
i used an offset on avg[1] , so it uses the average value from the previous bar, so the average doesn't include todays...
I have a real simple indicator im trying to make...just something that notifies me of the avg range of the last 10 bars on a 5 minute chart.
I have this code which ive been messing with to get it t actually produce something but cant get it to work... any help would be appreciated. Thanks
def cond = (high - low) > Average((high - low), 10)

you didn't say what you want to see, so i guessed from your formula,
(high - low) > Average((high - low),
it looks like you want to know when todays high-low range is higher (or lower) than the average.

when i compared the range to the average,
def isup = (rng > avg[1]);
i used an offset on avg[1] , so it uses the average value from the previous bar, so the average doesn't include todays range.

this displays a label, with todays range and the average. the label turns green or red or gray , depending on it todays range is above, below, or the same as the average.

Code:
input len = 10;
def rng = high - low;
def avg = average(rng, len);
def isup = (rng > avg[1]);
def isdwn = (rng < avg[1]);
addlabel(1, "bar range " + rng + " is " +
(if isup then "above" else "below") +
" average " + avg
, ( if isup then color.green else if isdwn then color.red else color.gray));
#
 
Solution
Hey @halcyonguy thanks for the help...i ran the code and it looks good but I just want the small indicator in the upper left hand corner that tells me the avg range of last 10 bars. I was going to remove the painted bars in the code... would i just remove the last line of code to remove the painted bars?
 
Hey @halcyonguy thanks for the help...i ran the code and it looks good but I just want the small indicator in the upper left hand corner that tells me the avg range of last 10 bars. I was going to remove the painted bars in the code... would i just remove the last line of code to remove the painted bars?
my code in post2 only creates 1 label. it doesn't change colors of any bars. sounds like you have another study loaded causing that.
disable each study, 1 by 1, to find which one is doing that.
 
This indictor has been working great... I was just wondering if I could tweak it so I could see 10 bar avg range based off previous bars. So if I hover over a random bar on a 5 minute chart it could show me 10 bar avg range from that point.

Thanks
 
Hey @halcyonguy I was wondering if could add an update from the original code that would allow me to hover over any bar on the 5 minute chart to see the avg bar range of the last 10 bars? Is this an easy change?

Thanks
 

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