Help Creating Mid of Bar and ATR Code

akoplan

New member
Hello, looking for code to do two things 1. Show a line at Or show a label of the value of the mid of a bar (based on chart time, ie, 1-minute, or 5-minute, etc.). I think a nice, fat line right in the middle of the bar would be my preference so it is visually noticeable. 2. Change a bar color to bright purple when the range of the bar is larger or smaller than the ATR of the prior X (default to 10) bars for the chart period by a user's input value, like .5%, 1.2%, 50%, etc. of the ATR, whatever the user's preference. So if I am looking for a bar on a one-minute chart that has a range of 1.5x the ATR of the prior 10 bars, it will appear as a bright purple bar on my screen. Thank you for any help.


An additional attribute to 1. above is to have a few inputs so you could show lines at the .618, .5, and .272 levels of the bar.
 
Last edited by a moderator:
Solution
Hello, looking for code to do two things 1. Show a line at Or show a label of the value of the mid of a bar (based on chart time, ie, 1-minute, or 5-minute, etc.). I think a nice, fat line right in the middle of the bar would be my preference so it is visually noticeable. 2. Change a bar color to bright purple when the range of the bar is larger or smaller than the ATR of the prior X (default to 10) bars for the chart period by a user's input value, like .5%, 1.2%, 50%, etc. of the ATR, whatever the user's preference. So if I am looking for a bar on a one-minute chart that has a range of 1.5x the ATR of the prior 10 bars, it will appear as a bright purple bar on my screen. Thank you for any help.


An additional attribute to 1...
Hello, looking for code to do two things 1. Show a line at Or show a label of the value of the mid of a bar (based on chart time, ie, 1-minute, or 5-minute, etc.). I think a nice, fat line right in the middle of the bar would be my preference so it is visually noticeable. 2. Change a bar color to bright purple when the range of the bar is larger or smaller than the ATR of the prior X (default to 10) bars for the chart period by a user's input value, like .5%, 1.2%, 50%, etc. of the ATR, whatever the user's preference. So if I am looking for a bar on a one-minute chart that has a range of 1.5x the ATR of the prior 10 bars, it will appear as a bright purple bar on my screen. Thank you for any help.


An additional attribute to 1. above is to have a few inputs so you could show lines at the .618, .5, and .272 levels of the bar.

Try this

Capture.jpg
Ruby:
plot midbar = hl2;
midbar.SetDefaultColor(Color.YELLOW);
midbar.SetLineWeight(5);
midbar.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

input percent = 1.5;
input length  = 10;
def atr = ATR(length)[1];
input showatrcolor = yes;
AssignPriceColor(if !showatrcolor
                 then Color.CURRENT
                 else if (high - low) > atr * percent
                 then Color.MAGENTA   
                 else Color.CURRENT);

####################
input test = yes;
AddChartBubble(test, low - TickSize() * 5,
                    "HL: "  + (high - low) +
                    "\nATR: " + AsText(atr) +
                    "\nATR*%: " + AsText(atr * percent) ,
                    if (high - low) > atr * percent
                    then Color.MAGENTA   
                    else Color.GRAY, no);
 
Solution

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

Awesome, just now checking. Will review today and appreciate it very much!


That is really nice, but can you make so the label prints only for the bar that meets the ATR criteria? Otherwise, it has too many labels for me.

Here is the bubbles for just the magenta bars. You can now move those at the user input bubble_updown.

I usually include bubbles just for testing only. If you want to keep them, I would suggest removing/reducing the names in the bubbles to avoid blocking other candles.

Ruby:
plot midbar = hl2;
midbar.SetDefaultColor(Color.YELLOW);
midbar.SetLineWeight(5);
midbar.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

input percent = 1.5;
input length  = 10;
def atr = ATR(length)[1];
input showatrcolor = yes;
AssignPriceColor(if !showatrcolor
                 then Color.CURRENT
                 else if (high - low) > atr * percent
                 then Color.MAGENTA   
                 else Color.CURRENT);

####################
input test = yes;
input bubble_updown = 5;
AddChartBubble(test and (high - low) > atr * percent, low - TickSize() * bubble_updown,
                    "HL: "  + (high - low) +
                    "\nATR: " + AsText(atr) +
                    "\nATR*%: " + AsText(atr * percent) ,
                    if (high - low) > atr * percent
                    then Color.MAGENTA   
                    else Color.GRAY, no);
 
That is really, really wonderful code...thank you so much. Helps me identify scalp zones and initiative moves in ES futures. I do not know how to reduce the text size in the bubble, but moving it low enough seems okay. Super cool, thank you.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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