// 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.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
Timeframe
timeframe
D
res
Risk:Reward
float
1.0
rr
Stop Multiplier
float
1.0
stopMultiplier
Stop Lookback
int
1
lookback
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.
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
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
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
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
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
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