Strategy · Pine Script v4 · On the chart

365 Day High Breakout Strategy

by hasnocool

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.

View on GitHub

GitHub stars106on the repository
Pine versionv4older, still runs
Lines of code57
Settings7inputs
LicenceGPL-3.0
Last update2 years ago18 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 strategy, select all of the template text and paste. Press Save and give it a name.
  4. 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.

Details

Published by

hasnocool on GitHub

Type

Strategy, Pine Script v4

Draws

On the price chart

Category

Trend, Breakout, Moving averages

Markets

Stocks, Indices

Timeframes

H4 and above, M15-H1

Risk Notes

  • The strategy enters trades without a stop loss

Topics

analysisbtcusdtcryptocurrencydatapandaspythonsimulationtradingtradingview

Settings

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

SettingTypeDefaultVariable
MA 50int50len1
MA 150int150len2
MA 200int200len3
Comparative SymbolsymbolNSE:NIFTYcomparativeTickerId
Comparative Periodint50length
ATRPeriodint14ATRPeriod
ATRMultipfloat3.5ATRMultip
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

257 stars

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

Strategy v6 TrendMoving averages Repaints
Updated 6 weeks ago · None stated GitHub repository of Best Chart 1m Strategy Candle Bar

均线突破交易系统

by tangly1024
76 stars

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

Strategy v5 TrendMoving averages
Updated 4 months ago · None stated GitHub repository of 均线突破交易系统
43 stars

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-

Strategy v5 TrendBreakout Repaints
Updated 2 years ago · None stated GitHub repository of SOL 1m - Strategy Candle Bar

ADA4H Optuna Strategy

by skywalker0803r
42 stars

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

Strategy v5 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of ADA4H Optuna Strategy
16 stars

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

Strategy v6 TrendBreakout
Updated 11 months ago · None stated GitHub repository of Seykota Alt 10: Profit Targets

More strategys

Trade Your Charts With a Regulated Broker

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

Compare brokers