Strategy · Pine Script v6 · On the chart

PineForge Harbor Stop Limit

by pineforge-4pass· code credited to PineForge

A long-only breakout strategy that uses a stop-limit style entry.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code47
Settings6inputs
LicenceApache-2.0
Last update6 days ago23 Oct 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

47 lines of Pine Script v6 from validation/order-harbor-stop-limit-01/strategy.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

strategy.pine
//@version=6
// SPDX-License-Identifier: Apache-2.0
// Copyright 2026 PineForge
// PineForge Corporate Strategy: Harbor Stop Limit
// A stop-limit order requires breakout activation and a bounded maximum fill price.
strategy("PineForge — Harbor Stop Limit", overlay=true,
     initial_capital=100000,
     default_qty_type=strategy.percent_of_equity, default_qty_value=5,
     pyramiding=0, commission_type=strategy.commission.percent,
     commission_value=0.05, slippage=1,
     margin_long=100, margin_short=100,
     process_orders_on_close=false, calc_on_order_fills=false)

harborLength = input.int(35, "Harbor Range", minval=5, group="Signal")
atrLength = input.int(14, "ATR Length", minval=2, group="Signal")
activationAtr = input.float(0.10, "Activation Buffer ATR", minval=0, step=0.02, group="Execution")
limitAtr = input.float(0.28, "Maximum Fill Distance ATR", minval=0.05, step=0.01, group="Execution")
stopAtr = input.float(2.4, "Protective Stop ATR", minval=0.5, step=0.1, group="Risk")
maximumBars = input.int(64, "Maximum Hold Bars", minval=5, group="Risk")

atrValue = ta.atr(atrLength)
rangeHigh = ta.highest(high, harborLength)[1]
rangeMid = (ta.highest(high, harborLength)[1] + ta.lowest(low, harborLength)[1]) / 2.0
activationPrice = rangeHigh + atrValue * activationAtr
limitPrice = activationPrice + atrValue * limitAtr
validSetup = close > rangeMid and close < activationPrice
var int fillBar = na

if strategy.position_size == 0 and validSetup
    strategy.entry("Harbor Breakout", strategy.long,
         stop=activationPrice, limit=limitPrice)
else if strategy.position_size == 0
    strategy.cancel("Harbor Breakout")

if strategy.position_size > 0 and strategy.position_size[1] <= 0
    fillBar := bar_index
if strategy.position_size == 0
    fillBar := na

if strategy.position_size > 0
    strategy.exit("Harbor Guard", from_entry="Harbor Breakout",
         stop=strategy.position_avg_price - atrValue * stopAtr)
    if not na(fillBar) and bar_index - fillBar >= maximumBars
        strategy.close("Harbor Breakout", comment="Harbor time limit")

plot(rangeHigh, "Range High", color=color.blue)
plot(limitPrice, "Stop-Limit Ceiling", color=color.orange)

Overview

PineForge Harbor Stop Limit tracks the highest high of the previous 35 bars and the range midpoint, and arms an order when the close is above the midpoint but below an activation level set a fraction of ATR above that high. The order has a cap on the fill price. Each trade has an ATR-based protective stop and a maximum holding time in bars. Inputs set the range, ATR multiples and hold limit. Range high and the fill ceiling are plotted.

Details

Published by

pineforge-4pass on GitHub

Code credit

PineForge, as written in the script's header

Type

Strategy, Pine Script v6

Draws

On the price chart

Category

Breakout, Volatility & bands

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

algorithmic-tradingbacktestingparitypine-scriptpinescriptquantitative-financetest-corpustradingview

Settings

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

SettingTypeDefaultVariable
Harbor Rangeint35harborLength
ATR Lengthint14atrLength
Activation Buffer ATRfloat0.10activationAtr
Maximum Fill Distance ATRfloat0.28limitAtr
Protective Stop ATRfloat2.4stopAtr
Maximum Hold Barsint64maximumBars
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 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

Strategy v6 Volatility & bandsSupport & resistance
Updated 6 weeks ago · None stated GitHub repository of V1.6 ES - Futures 1M No Repaint
218 stars

This strategy detects price breakouts above rolling highest highs or below lowest lows over a customizable lookback period. It includes optional volume spike and ATR volatility threshold filters, along with bar confirmation rules. Positions are taken upon conf

Strategy v6 BreakoutVolatility & bands
Updated 3 months ago · None stated GitHub repository of Breakout Strategy Template

Bollinger Breakout

by hackingthemarkets
189 stars

This price-chart strategy plots a simple moving average and upper and lower bands built from the standard deviation of close, scaled by separate offset inputs. It enters a fixed quantity long when close crosses above the upper band and a fixed quantity short w

Strategy v4 Volatility & bandsBreakout
Updated 3 years ago · None stated GitHub repository of Bollinger Breakout

2 Candles Inside ATR

by hasnocool
106 stars

2 Candles Inside ATR is an overlay script that measures volatility compression across two consecutive candles. It calculates a smoothed Average True Range (ATR) and compares it against the combined high and low range of the current and previous bars. When the

Strategy v4 Volatility & bandsBreakout
Updated 2 years ago · GPL-3.0 GitHub repository of 2 Candles Inside ATR

均线突破交易系统

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 均线突破交易系统

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