Strategy · Pine Script v6 · On the chart

Courier UDT Return Method

by pineforge-4pass· code credited to PineForge

A long-only strategy that builds a volatility envelope from an EMA centre and an ATR width using a custom type and a method.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code46
Settings4inputs
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

46 lines of Pine Script v6 from validation/udt-courier-return-method-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 Owned Strategy: Courier UDT Return Method
// A typed factory returns a volatility envelope used immediately by a method.
strategy("PineForge — Courier UDT Return Method", overlay=true,
     initial_capital=100000,
     default_qty_type=strategy.fixed, default_qty_value=2,
     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)

type CourierEnvelope
    float center
    float width
    int createdAt

buildEnvelope(float source, int centerLength, int rangeLength) =>
    centerValue = ta.ema(source, centerLength)
    widthValue = ta.atr(rangeLength)
    CourierEnvelope.new(centerValue, widthValue, bar_index)

method upperGate(CourierEnvelope self, float multiplier) =>
    self.center + self.width * multiplier

centerLength = input.int(37, "Envelope Center Length", minval=5, group="Envelope")
rangeLength = input.int(16, "Envelope Range Length", minval=2, group="Envelope")
entryMultiplier = input.float(1.15, "Entry Width", minval=0.1, step=0.05, group="Envelope")
maximumAtrLoss = input.float(2.4, "Maximum ATR Loss", minval=0.5, step=0.1, group="Risk")

CourierEnvelope activeEnvelope = buildEnvelope(close, centerLength, rangeLength)
upperBoundary = activeEnvelope.upperGate(entryMultiplier)
ageIsValid = bar_index - activeEnvelope.createdAt == 0

enterLong = ageIsValid and ta.crossover(close, upperBoundary)
envelopeEnded = close < activeEnvelope.center
riskExceeded = strategy.position_size > 0 and close < strategy.position_avg_price - activeEnvelope.width * maximumAtrLoss

if strategy.position_size == 0 and enterLong
    strategy.entry("Courier Long", strategy.long)
else if strategy.position_size > 0 and (envelopeEnded or riskExceeded)
    strategy.close("Courier Long", comment=riskExceeded ? "ATR risk" : "Envelope ended")

plot(activeEnvelope.center, "Envelope Center", color=color.orange)
plot(upperBoundary, "Envelope Gate", color=color.blue)

Overview

Courier UDT Return Method enters long when the close crosses above the centre plus a multiple of the width. It exits when the close falls below the centre, or when price drops a set multiple of the width below the average entry. The centre and upper gate are drawn on the price chart.

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

Volatility & bands, Breakout

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

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
Envelope Center Lengthint37centerLength
Envelope Range Lengthint16rangeLength
Entry Widthfloat1.15entryMultiplier
Maximum ATR Lossfloat2.4maximumAtrLoss
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