//Updated June 2023 to comply with 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
strategy(title="Breakout Strategy", overlay=true, currency="USD")
// Import ZenLibrary
import ZenAndTheArtOfTrading/ZenLibrary/5 as zen
// 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
// Get ATR
atr = ta.atr(14)
// Check for breakouts
bullishBO = close > dailyHigh and close[1] <= dailyHigh and not bullishBreakoutToday and not na(atr) and strategy.position_size == 0
bearishBO = close < dailyLow and close[1] >= dailyLow and not bearishBreakoutToday and not na(atr) and strategy.position_size == 0
// 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)
// Save stop & target
var float t_stop = na
var float t_target = na
// If bullish breakout detected today, disable any future signals for today
if bullishBO
bullishBreakoutToday := true
t_stop := longStop
t_target := longTarget
stopLabelText = str.tostring(longStopDist / syminfo.mintick / 10, "#.#")
strategy.entry(id="Long", direction=strategy.long, comment="Long (SL=" + stopLabelText + " pips)")
// If bearish breakout detected today, disable any future signals for today
if bearishBO
bearishBreakoutToday := true
t_stop := shortStop
t_target := shortTarget
stopLabelText = str.tostring(shortStopDist / syminfo.mintick / 10, "#.#")
strategy.entry(id="Short", direction=strategy.short, comment="Short (SL=" + stopLabelText + " pips)")
// Check long stops & targets being hit
strategy.exit(id="Long Exit",
from_entry="Long",
limit=t_target,
stop=t_stop,
comment="Long Exit (Equity: " + str.tostring(strategy.equity, "###,###,###") + ")")
// Check short stops & targets being hit
strategy.exit(id="Short Exit",
from_entry="Short",
limit=t_target,
stop=t_stop,
comment="Short Exit (Equity: " + str.tostring(strategy.equity, "###,###,###") + ")")
// 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(strategy.position_size != 0 ? t_stop : na, color=color.red, style=plot.style_linebr, title="Trade Stop")
plot(strategy.position_size != 0 ? t_target : na, color=color.green, style=plot.style_linebr, title="Trade Target")
Overview
When the close crosses above the higher-timeframe high or below its low, it enters long or short, limiting execution to one breakout per direction each day. Stop losses are calculated using swing extremes adjusted by an ATR multiplier, while profit targets are derived via a configurable risk-to-reward ratio. It overlays the breakout levels, trade signals, stop loss, and target levels directly on the price chart.
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 strategy plots VWMA-based Bollinger bands on the 1-minute ES futures price chart for volatility analysis and potential breakout identification. It calculates dynamic long and short stop loss and take profit levels using percentage inputs relative to entry
This strategy trades Donchian breakouts measured on weekly bars while orders execute on the chart timeframe. It allows long and short entries when price breaks the prior weekly channel and exits against the shorter weekly channel. Position size risks a set per
Calculates upper and lower Donchian Channel bands over a customizable lookback length and plots them on the main price chart. At a specified exchange hour, the strategy places a long buy stop order at the upper Donchian Channel level. Unfilled pending orders a
This overlay strategy builds independent timed session ranges and marks range, trendline, mean, VWAP, and high-low levels when those displays are enabled. It enters on range breakouts and exits with strategy exits, choosing among range, ATR, fixed-point, and r
Donchian Channel Breakout is a Pine Script v5 strategy drawn on the price chart. It enters long when close crosses above the previous upper Donchian band and short when close crosses below the previous lower band, reversing with the opposite signal. An ATR tra
The Range Percent Breakout Strategy identifies range contraction and inside bar patterns where the current bar's range is within a specified percentage threshold of the previous bar. When this condition is met while flat, breakout levels are established above