Indicator · Pine Script v5 · On the chart

Breakout Indicator

by Web3Degenerate

Breakout Indicator plots high and low threshold levels for a chosen timeframe, such as daily, directly on the price chart.

View on GitHub

GitHub stars2on the repository
Pine versionv5runs as is
Lines of code69
Settings4inputs
LicenceNone statedfile: MPL-2.0
Last update2 years ago13 Sep 2024

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

69 lines of Pine Script v5 from advanced-pine-script/6.Timeframes-And-Markets/7.Daily-Breakout-Indicator.pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

7.Daily-Breakout-Indicator.pine
// This lesson shows how to create a breakout indicator which will alert you whenever price action breaks above/below a previous day's high/low, and will also draw your stops & targets onto the chart.

// Note: you can change the "Timeframe" setting to anything - it doesn't only need to be Daily breakouts!

// Update 20th June 2023: I changed the security function call to reflect the latest 'best practice' for non-repainting code as mentioned in the TradingView Docs: https://www.tradingview.com/pine-script-docs/en/v5/concepts/Repainting.html#repainting-request-security-calls

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/

// @version=5
indicator(title="Breakout Indicator", overlay=true)

// Get user input
res = input.timeframe(title="Timeframe", defval="D")
rr = input.float(title="Risk:Reward", defval=1.0)
stopMultiplier = input.float(title="Stop Multiplier", defval=1.0)
lookback = input.int(title="Stop Lookback", defval=1)

// Get highs and lows
dailyHigh = request.security(syminfo.tickerid, res, high[barstate.isrealtime ? 1 : 0])[barstate.isrealtime ? 0 : 1]
dailyLow  = request.security(syminfo.tickerid, res, low[barstate.isrealtime ? 1 : 0])[barstate.isrealtime ? 0 : 1]

// Detect unique breakout for today
var bullishBreakoutToday = false
var bearishBreakoutToday = false
newDay = ta.change(time("D"))
if newDay
    bullishBreakoutToday := false
    bearishBreakoutToday := false

// Check for breakouts
bullishBO = close > dailyHigh and close[1] <= dailyHigh and not bullishBreakoutToday
bearishBO = close < dailyLow and close[1] >= dailyLow and not bearishBreakoutToday

// If bullish breakout detected today, disable any future signals for today
if bullishBO
    bullishBreakoutToday := true

// If bearish breakout detected today, disable any future signals for today
if bearishBO
    bearishBreakoutToday := true
    
// Get ATR
atr = ta.atr(14)

// Get stops & targets
longStop  = ta.lowest(low, lookback) - (atr * stopMultiplier)
shortStop = ta.highest(high, lookback) + (atr * stopMultiplier)
longStopDist  = close - longStop
shortStopDist = shortStop - close
longTarget  = close + (longStopDist * rr)
shortTarget = close - (shortStopDist * rr)

// Draw highs and lows to the chart
plot(dailyHigh, color=color.red, linewidth=2)
plot(dailyLow, color=color.green, linewidth=2)

// Draw signals
plotshape(bearishBO, title="Bearish Breakout", style=shape.triangledown, location=location.abovebar, color=color.red)
plotshape(bullishBO, title="Bullish Breakout", style=shape.triangleup, location=location.belowbar, color=color.green)

// Draw stops & targets
plot(bearishBO ? shortStop : na, color=color.red, style=plot.style_linebr)
plot(bearishBO ? shortTarget : na, color=color.green, style=plot.style_linebr)
plot(bullishBO ? longStop : na, color=color.red, style=plot.style_linebr)
plot(bullishBO ? longTarget : na, color=color.green, style=plot.style_linebr)

// Trigger alerts
alertcondition(bullishBO, title="Bullish Breakout!", message="Long breakout detected for {{ticker}}")
alertcondition(bearishBO, title="Bearish Breakout!", message="Short breakout detected for {{ticker}}")

Overview

When price closes above the high or below the low, the indicator displays a breakout shape and marks ATR-based stop loss and take profit levels calculated using the configured risk-to-reward ratio. It limits signals to one bullish and one bearish breakout per day to reduce noise. Settings allow customization of the timeframe, stop lookback period, stop loss ATR multiplier, and risk-to-reward target ratio.

Details

Published by

Web3Degenerate on GitHub

Type

Indicator, Pine Script v5

Draws

On the price chart

Category

Breakout, Support & resistance, Volatility & bands

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
TimeframetimeframeDres
Risk:Rewardfloat1.0rr
Stop Multiplierfloat1.0stopMultiplier
Stop Lookbackint1lookback
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

Donchian Channels (DC)

by mihakralj
99 stars

This indicator calculates and plots Donchian Channels directly on the price chart. It determines the highest high and lowest low over a user-selected lookback period using an optimized monotonic deque algorithm, as well as a middle basis line computed as their

Indicator v6 Volatility & bandsSupport & resistance
Updated 4 weeks ago · Apache-2.0 GitHub repository of Donchian Channels (DC)
47 stars

The Donchian Channels indicator plots the middle basis line as the average of the high and low over the user-defined period. It also draws the upper band as the highest high and the lower band as the lowest low across the same period on the price chart. The ma

Indicator v6 Volatility & bandsSupport & resistance
Updated 8 months ago · MIT GitHub repository of Donchian Channels (DCHANNEL)
43 stars

This indicator plots Donchian channel bands and a midline on the price chart. It finds the highest and lowest values over a user-set length, then draws the upper band, lower band, and their average as the basis. The source setting chooses high and low, or the

Indicator v4 Volatility & bandsBreakout
Updated 1 year ago · None stated GitHub repository of Donchian Channels Experiment

Zen ABR Against

by Zen-Tim
29 stars

This overlay indicator measures average bar range as a simple moving average of high minus low, then draws short horizontal ticks at one to four times that range above and below the close. The user chooses which multipliers appear, their colors, and the line w

Indicator v6 Volatility & bandsSupport & resistance
Updated 2 weeks ago · MIT GitHub repository of Zen ABR Against

This indicator identifies and plots price compression zones directly on the price chart using multi-module scoring. It measures ATR compression, ADX chop levels, boundary touches, volume dry-up, and historical pivot levels to identify consolidation areas and s

Indicator v6 BreakoutSupport & resistance
Updated yesterday · MIT GitHub repository of CoilForge Zones [WavesUnchained]

Dereköy-Darvas

by Kalumur
4 stars

The Dereköy-Darvas indicator combines Darvas Box boundary levels with dual Bollinger Bands plotted directly on the main price chart. It calculates top and bottom box lines based on recent high and low extremes to outline price consolidation zones. Simultaneous

Indicator v5 Volatility & bandsSupport & resistance
Updated 2 years ago · None stated GitHub repository of Dereköy-Darvas

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers