Long Bar Highlighter For ThinkOrSwim

The author states:
The Long Bar Highlighter is designed to detect long bars that exhibit significant price expansion beyond recent price levels. It highlights bars that exceed the length of the previous four bars, marking them for their potential importance in market movements. Additionally, the indicator plots directional shapes based on the closing prices, which helps traders visualize potential upward or downward momentum. An optional ATR crossover setting refines these signals, focusing on stronger trends for more optimal trading opportunities.
KXQgwKA.png


https://www.tradingview.com/v/dpwrfWNA/
 
Last edited by a moderator:

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

https://www.tradingview.com/v/dpwrfWNA/

Code:
//@version=5
indicator("Long Bar Highlighter", overlay=true)
// Inputs for ATR crossover length settings
length = input.int(title="Short Length", defval=3, minval=1, group = "ATR Input")
length2 = input.int(title="Long Length", defval=13, minval=1, group = "ATR Input")
showShape = input.bool(title="Show Shapes", defval=true, group="Display Options")
showWithoutTrend = input.bool(title="Show Shapes Without Strong Trend", defval=false, group="Display Options")

// Calculate the length of the current bar
current_bar_length = high - low
prev_bar_length = high[1] - low[1]
prev_bar_length2 = high[2] - low[2]
prev_bar_length3 = high[3] - low[3]
prev_bar_length4 = high[4] - low[4]
// Calculate the average range of the previous four bars using ATR
atr_length = request.security(syminfo.tickerid, "", ta.atr(10))
// Check if the current bar is longer than the previous four bars
long_bar = current_bar_length > atr_length and
           current_bar_length > prev_bar_length and
           current_bar_length > prev_bar_length2 and
           current_bar_length > prev_bar_length3 and
           current_bar_length > prev_bar_length4
// Determine if there is a strong trend based on ATR crossover
strongTrend = ta.crossover(ta.atr(length), ta.atr(length2))
// Plot blue bars where the condition is met
barcolor(long_bar ? color.blue : na)
// Check if close is higher or lower than the previous close
higher_close = close > close[1]
lower_close = close < close[1]
// Conditions based on user selection
conditionUp = showWithoutTrend ? (long_bar and higher_close) : (long_bar and higher_close and strongTrend)
conditionDown = showWithoutTrend ? (long_bar and lower_close) : (long_bar and lower_close and strongTrend)
// Plot arrows based on close position relative to the blue bars
plotshape(showShape ? conditionUp : na, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(showShape ? conditionDown : na, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)
check the below:

CSS:
#//@version=5
#indicator("Long Bar Highlighter", overlay=true)
# Converted by Sam4Cok@Samer800    - 05/2024
#// Inputs for ATR crossover length settings
input ShortLength = 3; #(title="Short Length", defval=3, minval=1, group = "ATR Input")
input LongLength = 13; #(title="Long Length", defval=13, minval=1, group = "ATR Input")
input showShape = yes; #(title="Show Shapes", defval=true, group="Display Options")
input showShapesWithoutStrongTrend = no; #(title="Show Shapes Without Strong Trend", defval=false, group="Display Options")

def na = Double.NaN;
#// Calculate the length of the current bar
def current_bar_length = high - low;
def prev_bar_length = high[1] - low[1];
def prev_bar_length2 = high[2] - low[2];
def prev_bar_length3 = high[3] - low[3];
def prev_bar_length4 = high[4] - low[4];

#// Calculate the average range of the previous four bars using ATR
def atr_length = Atr(Length = 10);

#// Check if the current bar is longer than the previous four bars
def long_bar = current_bar_length > atr_length and
           current_bar_length > prev_bar_length and
           current_bar_length > prev_bar_length2 and
           current_bar_length > prev_bar_length3 and
           current_bar_length > prev_bar_length4;

#// Determine if there is a strong trend based on ATR crossover
def strongTrend = atr(Length = ShortLength) Crosses Above atr(Length = LongLength);

#// Check if close is higher or lower than the previous close
def higher_close = close > close[1];
def lower_close = close < close[1];

#// Conditions based on user selection
def conditionUp = if showShapesWithoutStrongTrend then (long_bar and higher_close) else (long_bar and higher_close and strongTrend);
def conditionDown = if showShapesWithoutStrongTrend then (long_bar and lower_close) else (long_bar and lower_close and strongTrend);

#// Plot arrows based on close position relative to the blue bars
plot barUp = if showShape and conditionUp then low else na; #, "L", Color.green, no);
plot barDn = if showShape and conditionDown then high else na; #, "S", Color.red);
barUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
barDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
barUp.SetDefaultColor(Color.CYAN);
barDn.SetDefaultColor(Color.MAGENTA);
#// Plot blue bars where the condition is met
AssignPriceColor(if long_bar then
                 if conditionUp then Color.CYAN else
                 if conditionDown then Color.MAGENTA else Color.GRAY else Color.CURRENT);

#-- END of CODE
 
check the below:

CSS:
#//@version=5
#indicator("Long Bar Highlighter", overlay=true)
# Converted by Sam4Cok@Samer800    - 05/2024
#// Inputs for ATR crossover length settings
input ShortLength = 3; #(title="Short Length", defval=3, minval=1, group = "ATR Input")
input LongLength = 13; #(title="Long Length", defval=13, minval=1, group = "ATR Input")
input showShape = yes; #(title="Show Shapes", defval=true, group="Display Options")
input showShapesWithoutStrongTrend = no; #(title="Show Shapes Without Strong Trend", defval=false, group="Display Options")

def na = Double.NaN;
#// Calculate the length of the current bar
def current_bar_length = high - low;
def prev_bar_length = high[1] - low[1];
def prev_bar_length2 = high[2] - low[2];
def prev_bar_length3 = high[3] - low[3];
def prev_bar_length4 = high[4] - low[4];

#// Calculate the average range of the previous four bars using ATR
def atr_length = Atr(Length = 10);

#// Check if the current bar is longer than the previous four bars
def long_bar = current_bar_length > atr_length and
           current_bar_length > prev_bar_length and
           current_bar_length > prev_bar_length2 and
           current_bar_length > prev_bar_length3 and
           current_bar_length > prev_bar_length4;

#// Determine if there is a strong trend based on ATR crossover
def strongTrend = atr(Length = ShortLength) Crosses Above atr(Length = LongLength);

#// Check if close is higher or lower than the previous close
def higher_close = close > close[1];
def lower_close = close < close[1];

#// Conditions based on user selection
def conditionUp = if showShapesWithoutStrongTrend then (long_bar and higher_close) else (long_bar and higher_close and strongTrend);
def conditionDown = if showShapesWithoutStrongTrend then (long_bar and lower_close) else (long_bar and lower_close and strongTrend);

#// Plot arrows based on close position relative to the blue bars
plot barUp = if showShape and conditionUp then low else na; #, "L", Color.green, no);
plot barDn = if showShape and conditionDown then high else na; #, "S", Color.red);
barUp.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_DOWN);
barDn.SetPaintingStrategy(PaintingStrategy.BOOLEAN_WEDGE_UP);
barUp.SetDefaultColor(Color.CYAN);
barDn.SetDefaultColor(Color.MAGENTA);
#// Plot blue bars where the condition is met
AssignPriceColor(if long_bar then
                 if conditionUp then Color.CYAN else
                 if conditionDown then Color.MAGENTA else Color.GRAY else Color.CURRENT);

#-- END of CODE
@samer800 thank you some much for your help!
 
I love this indicator and it would go well with my current set up! However, I use a range bar which this doesn’t seem to work. That being said, unfortunately I don’t know how to code so would there be anybody in this group they could help to make it usable on a range bar? I greatly appreciate it.!! I really hope someone could figure it out. Thanks.:)
 
Last edited by a moderator:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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