Strategy · Pine Script v6 · On the chart

PineForge — Keystone UDF Tuple

by pineforge-4pass· code credited to PineForge

This strategy calculates an EMA basis line surrounded by ATR volatility bands using a custom tuple function.

View on GitHub

GitHub stars3on the repository
Pine versionv6current
Lines of code39
Settings3inputs
LicenceApache-2.0
Last update4 days ago20 Nov 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

39 lines of Pine Script v6 from validation/composite-keystone-udf-tuple-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: Keystone UDF Tuple
strategy("PineForge — Keystone UDF Tuple", overlay=true,
     initial_capital=100000,
     default_qty_type=strategy.percent_of_equity, default_qty_value=7,
     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)

channel(float source, int length, float widthMultiplier) =>
    float basis = ta.ema(source, length)
    float width = ta.atr(length) * widthMultiplier
    float upper = basis + width
    float lower = basis - width
    [basis, upper, lower, width]

channelLength = input.int(27, "Channel Length", minval=3, group="Signal")
widthMultiplier = input.float(1.6, "Channel Width ATR", minval=0.25, step=0.05, group="Signal")
targetMultiplier = input.float(2.1, "Target Widths", minval=0.5, step=0.1, group="Risk")

[basis, upperBand, lowerBand, channelWidth] = channel(close, channelLength, widthMultiplier)

if ta.crossover(close, upperBand)
    strategy.entry("Keystone Long", strategy.long)

if ta.crossunder(close, basis)
    strategy.close("Keystone Long", comment="Return through basis")

if strategy.position_size > 0
    strategy.exit("Keystone Risk", from_entry="Keystone Long",
         stop=strategy.position_avg_price - channelWidth,
         limit=strategy.position_avg_price + channelWidth * targetMultiplier)

plot(basis, "Basis", color=color.gray)
plot(upperBand, "Upper", color=color.green)
plot(lowerBand, "Lower", color=color.red)

Overview

PineForge — Keystone UDF Tuple plots the basis line, upper band, and lower band directly on the price chart. A long position enters when price crosses above the upper channel band. The trade exits when price drops back below the EMA basis line, with risk managed by a stop loss and limit target based on the ATR channel width. Settings configure channel length, ATR width multiplier, and target multiplier.

Details

Published by

pineforge-4pass on GitHub

Code credit

PineForge, as written in the script's header

Draws

On the price chart

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
Channel Lengthint27channelLength
Channel Width ATRfloat1.6widthMultiplier
Target Widthsfloat2.1targetMultiplier
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

106 stars

This strategy runs on the price chart and enters long when a fast simple moving average crosses above a slow one, and short on the opposite cross, while closing the other side. Entries also need ATR above a filter, a pullback check, a minimum candle-body chang

Strategy v5 TrendMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of 9:22 5 MIN 15 MIN BANKNIFTY

均线突破交易系统

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 均线突破交易系统
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 1 year ago · None stated GitHub repository of Seykota Alt 10: Profit Targets
4 stars

This strategy executes trend-following trades based on Bollinger Band breakouts confirmed by a long-term moving average filter. A long position opens when the price crosses above the upper Bollinger Band, provided the band spread meets a minimum threshold and

Strategy v5 Volatility & bandsTrend
Updated 2 years ago · None stated GitHub repository of Bollinger Trend - Strategy V1
4 stars

The Keltner Channel Strategy is a breakout system plotted directly on the main price chart. It calculates upper and lower channel bands around an exponential or simple moving average using ATR, True Range, or bar range multiplied by a specified factor. A long

Strategy v5 TrendVolatility & bands
Updated 5 months ago · None stated GitHub repository of Keltner Channel Strategy

More Trend scripts

Related on ForexR

Trade Your Charts With a Regulated Broker

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

Compare brokers