Strategy · Pine Script v6 · On the chart

52-Week High 115/70/52

by trustdan· code credited to TrendLab - Generated from Strategy Artifact

A long-only strategy generated from the TrendLab research project, drawn on the price chart.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code58
Settings3inputs
LicenceMIT
Last update9 months ago31 Jan 2026

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

58 lines of Pine Script v6 from pine-scripts/strategies/52wk_high/115_70_52.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

115_70_52.pine
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © TrendLab - Generated from Strategy Artifact

//@version=6
strategy("52-Week High 115/70/52", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=100000, commission_type=strategy.commission.percent, commission_value=0.1, slippage=1)

// =============================================================================
// INPUTS
// =============================================================================
lookbackPeriod = input.int(115, "Lookback Period", minval=1)
entryPct = input.float(70.0, "Entry Threshold %", minval=1, maxval=100) / 100
exitPct = input.float(52.0, "Exit Threshold %", minval=1, maxval=100) / 100

// =============================================================================
// INDICATOR CALCULATION
// =============================================================================
// Calculate the highest high over the lookback period
periodHigh = ta.highest(high, lookbackPeriod)

// Calculate entry and exit thresholds
entryThreshold = periodHigh * entryPct
exitThreshold = periodHigh * exitPct

// =============================================================================
// STRATEGY LOGIC
// =============================================================================
// Entry: Close >= 70% of the 115-day period high
// This means: enter when price is within 30% of its recent high (showing strength)
entryCondition = close >= entryThreshold

// Exit: Close < 52% of the 115-day period high
// This means: exit when price has dropped more than 48% from its recent high
exitCondition = close < exitThreshold

// Position management
isFlat = strategy.position_size == 0
isLong = strategy.position_size > 0

if entryCondition and isFlat
    strategy.entry("Long", strategy.long)

if exitCondition and isLong
    strategy.close("Long")

// =============================================================================
// PLOTTING
// =============================================================================
// Plot the period high and thresholds
plot(periodHigh, "Period High", color=color.blue, linewidth=1)
plot(entryThreshold, "Entry Threshold (70%)", color=color.green, linewidth=1, style=plot.style_stepline)
plot(exitThreshold, "Exit Threshold (52%)", color=color.red, linewidth=1, style=plot.style_stepline)

// Fill between thresholds for visual clarity
fill(plot(entryThreshold, display=display.none), plot(exitThreshold, display=display.none), color=color.new(color.yellow, 90))

// Plot entry/exit signals
plotshape(entryCondition and isFlat, "Entry Signal", shape.triangleup, location.belowbar, color.green, size=size.small)
plotshape(exitCondition and isLong, "Exit Signal", shape.triangledown, location.abovebar, color.red, size=size.small)

Overview

52-Week High 115/70/52 tracks the highest high over a 115-bar lookback. It buys when the close is at or above 70 percent of that high and sells when the close falls below 52 percent of it. The lookback, entry threshold and exit threshold are inputs. The tester settings include commission and slippage, and sizing uses the full account equity. There is no separate stop loss beyond the exit threshold.

Details

Published by

trustdan on GitHub

Code credit

TrendLab - Generated from Strategy Artifact, as written in the script's header

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Trend, Breakout

Markets

Stocks

Timeframes

H4 and above

Risk Notes

  • The strategy enters trades without a stop loss

Settings

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

SettingTypeDefaultVariable
Lookback Periodint115lookbackPeriod
Entry Threshold %float70.0entryPct
Exit Threshold %float52.0exitPct
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

This trend-following strategy executes a classic Donchian channel breakout system designed to cross-validate backtest results against external framework benchmarks. It triggers a long entry when the closing price breaks above the highest high of the prior entr

Strategy v6 BreakoutTrend
Updated yesterday · AGPL-3.0 GitHub repository of Forven S01509 - Simple Donchian 20/10 Breakout
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

12/26-IT Strategy

by hasnocool
106 stars

This strategy executes trades based on crossovers between a 12-period and a 26-period exponential moving average (EMA). Long positions can be filtered by pivot resistance breakouts and RSI boundary ranges. For trade management, it provides two configurable par

Strategy v5 TrendMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of 12/26-IT Strategy

均线突破交易系统

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 5 months ago · None stated GitHub repository of 均线突破交易系统
53 stars

This strategy enters long or short on the price chart when price is on the correct side of a 200-period EMA, MACD agrees, RSI is not at the opposing extreme, ADX exceeds a threshold, volume beats a 20-bar average, and close breaks the recent high or low. A tim

Strategy v6 TrendOscillators & momentum
Updated 2 months ago · MPL-2.0 GitHub repository of BTCUSD 5M Optimized Strategy

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