This long-only trend-following strategy identifies breakout trades by requiring price to breach a 250-bar high while aligned with 50-period, 150-period, and 200-period Simple Moving Averages.
1Copy the scriptPress Copy script above, or the copy button on the code below.
2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
3Paste over the templateCreate a new strategy, select all of the template text and paste. Press Save and give it a name.
4Add it to the chartPress Add to chart. The trades and results appear in the Strategy Tester tab; adjust the settings with the gear icon.
Source Code
57 lines of Pine Script v4 from 365 Day High Breakout Strategy.pine, published under GPL-3.0. Keep the author's credit and licence lines when you reuse it.
365 Day High Breakout Strategy.pine
//@version=4
strategy("365 Day High Breakout Strategy", overlay = true,
commission_type=strategy.commission.percent, commission_value= 0.15)
//------------------------------------------------------------------------------
// MOVING AVERAGE
len1 = input(50, minval=1, title="MA 50")
MA50 = sma(close, len1)
//plot(MA50, color=#00d8ff, linewidth=1, title="MA 50")
len2 = input(150, minval=1, title="MA 150")
MA150 = sma(close, len2)
//plot(MA150, color=color.purple, linewidth=1, title="MA 150")
len3 = input(200, minval=1, title="MA 200")
MA200 = sma(close, len3)
//plot(MA200, color=color.white, linewidth=1, title="MA 200")
//------------------------------------------------------------------------------
// RELATIVE STRENGTH
comparativeTickerId = input("NSE:NIFTY", type=input.symbol, title="Comparative Symbol") // ANY OTHER INDEX CAN BE USED
length = input(50, type=input.integer, minval=1, title="Comparative Period")
baseSymbol = security(syminfo.tickerid, timeframe.period, close)
comparativeSymbol = security(comparativeTickerId, timeframe.period, close)
RS = baseSymbol / baseSymbol[length] /
(comparativeSymbol / comparativeSymbol[length]) - 1
//------------------------------------------------------------------------------
// STRATEGY ENTRY / EXIT
//------------------------------------------------------------------------------
is_buy =
close > highest(high, 250 )[1]
and RS > 0
and MA50 > MA150 and MA150 > MA200
and close > MA50 and close > MA200
//------------------------------------------------------------------------------
//ATR Trailing Stop
ATRPeriod = input(14)
ATRMultip = input(3.5)
xATR = atr(ATRPeriod)
nLoss = ATRMultip * xATR
xATRTrailingStop = close
xATRTrailingStop := iff(close > nz(xATRTrailingStop[1], 0) and close[1] > nz(xATRTrailingStop[1], 0), max(nz(xATRTrailingStop[1]), close - nLoss),
iff(close < nz(xATRTrailingStop[1], 0) and close[1] < nz(xATRTrailingStop[1], 0), min(nz(xATRTrailingStop[1]), close + nLoss),
iff(close > nz(xATRTrailingStop[1], 0), close - nLoss, close + nLoss)))
//------------------------------------------------------------------------------
// PROFIT %
//longProfitPerc = input(title="Take Profit (%)", defval = 10, type = input.float ) / 100
//longExitPrice = strategy.position_avg_price * (1 + longProfitPerc)
// STOP LOSS %
//Long_sl = input(title="Loss (%)", defval = 4, type = input.float ) /100
//Long_stop_level = strategy.position_avg_price * (1 - Long_sl)
//------------------------------------------------------------------------------
buy_close =
( close < xATRTrailingStop[1] and not is_buy[1] )
//close > longExitPrice
//or close < Long_stop_level
//------------------------------------------------------------------------------
strategy.entry("Long", true, when = (is_buy and strategy.opentrades==0 ) )
strategy.close("Long", when = buy_close )
Expand (82 lines)
Overview
365 Day High Breakout Strategy calculates relative strength against a comparative market benchmark like NSE:NIFTY. Entries occur when relative strength is positive and moving averages are in bullish alignment. Positions exit using an ATR-based trailing stop. Users can adjust moving average lengths, benchmark symbol, and ATR trailing stop parameters directly in the settings. There is no fixed emergency stop loss defined.
The inputs you can change from the gear icon on the chart. Defaults are the author's.
Setting
Type
Default
Variable
MA 50
int
50
len1
MA 150
int
150
len2
MA 200
int
200
len3
Comparative Symbol
symbol
NSE:NIFTY
comparativeTickerId
Comparative Period
int
50
length
ATRPeriod
int
14
ATRPeriod
ATRMultip
float
3.5
ATRMultip
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 running pivot highs as red R circles and pivot lows as blue S circles directly on the price chart. It computes an EMA 3 and a Cto trend line from close prices, then generates long signals on upward EMA-Cto crossovers combined with price pos
This strategy trades long breakouts of a fast and a slow moving average on the price chart. It opens a long position when price crosses above either average, using a percentage of equity as size. It reduces the position by a set share when the high reaches the
This strategy executes trades on short-term cryptocurrency charts using a combination of pivot support and resistance levels and a multi-pole smoothed trend filter. Entries trigger when price crosses the smoothed trend line and confirms above or below a short-
This strategy trades longs and shorts on the price chart. Long entries require a close above the prior Donchian high, a close above a long-term SMA, and RSI above a threshold, with size set as a percentage of equity. Long exits use a stop at the prior Donchian
This strategy plots Donchian channels, trailing stops, and profit targets directly on the price chart. It enters breakout trades using a 55-bar Donchian channel and sizes positions according to an ATR-based risk percentage per unit. The system adds units as pr
This strategy trades Nikkei 225 futures during a configurable overnight session, defaulting to 19:00–03:00 ET. It builds long and short trend conditions from an 8/21 EMA pair and a 200-period SMA, with RSI, momentum, an ATR-scaled breakout range, and a volume