Strategy · Pine Script v6 · On the chart

PineForge Heliograph While Channel

by pineforge-4pass· code credited to PineForge

This strategy calculates a linearly weighted moving average centerline explicitly using a while loop, accompanied by a standard deviation upper band.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code58
Settings5inputs
LicenceApache-2.0
Last update7 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

58 lines of Pine Script v6 from validation/control-heliograph-while-channel-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: Heliograph While Channel
// A recency-weighted centerline is calculated explicitly with a while loop.
strategy("PineForge — Heliograph While Channel", 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)

channelLength = input.int(28, "Channel Length", minval=5, maxval=120, group="Signal")
bandWidth = input.float(1.25, "Band Width", minval=0.25, step=0.05, group="Signal")
atrLength = input.int(17, "ATR Length", minval=2, group="Risk")
stopAtr = input.float(2.4, "Stop ATR", minval=0.5, step=0.1, group="Risk")
maximumHoldBars = input.int(160, "Maximum Hold Bars", minval=8, group="Risk")

float weightedSum = 0.0
float weightTotal = 0.0
int cursor = 0
while cursor < channelLength
    sample = close[cursor]
    weight = channelLength - cursor
    if not na(sample)
        weightedSum += sample * weight
        weightTotal += weight
    cursor += 1

center = weightTotal > 0 ? weightedSum / weightTotal : na
dispersion = ta.stdev(close, channelLength)
upperBand = center + dispersion * bandWidth
atrValue = ta.atr(atrLength)

var int openedAt = na
if strategy.position_size > 0 and strategy.position_size[1] == 0
    openedAt := bar_index

entrySignal = ta.crossover(close, upperBand)
exitSignal = ta.crossunder(close, center)
holdExpired = strategy.position_size > 0 and not na(openedAt) and bar_index - openedAt >= maximumHoldBars

if entrySignal
    strategy.entry("Heliograph Long", strategy.long)

if strategy.position_size > 0 and (exitSignal or holdExpired)
    strategy.close("Heliograph Long", comment=holdExpired ? "Maximum hold" : "Centerline exit")

if strategy.position_size > 0
    strategy.exit("Heliograph Guard", from_entry="Heliograph Long",
         stop=strategy.position_avg_price - atrValue * stopAtr)

if strategy.position_size == 0
    openedAt := na

plot(center, "Weighted Center", color=color.yellow)
plot(upperBand, "Upper Band", color=color.orange)

Overview

PineForge Heliograph While Channel enters a long position when the close crosses over the upper band. Exits occur when the price crosses back under the centerline, when a maximum holding period expires, or when an ATR-based stop loss is hit. Key settings control channel length, band width, ATR length, stop multiple, and maximum hold duration. It plots the centerline and upper band on the price chart.

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 Lengthint28channelLength
Band Widthfloat1.25bandWidth
ATR Lengthint17atrLength
Stop ATRfloat2.4stopAtr
Maximum Hold Barsint160maximumHoldBars
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

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

Bollinger bands examples

by tradingstrategy-ai
53 stars

This strategy plots exponential-moving-average Bollinger bands on the price chart and calculates RSI. It opens a long position when close crosses above the upper band while RSI is at or above a threshold, the date filter allows trading, and no position is open

Strategy v5 Volatility & bandsOscillators & momentum
Updated 3 years ago · None stated GitHub repository of Bollinger bands examples

Keltner Channels Strategy

by TWODS-CAPITAL
37 stars

This strategy builds Keltner-style bands around an exponential or simple moving average of the chosen source. Band width uses average true range, raw true range, or a smoothed high-low range, scaled by a multiplier. When the source crosses above the upper band

Strategy v5 Volatility & bandsBreakout
Updated 3 years ago · MIT GitHub repository of Keltner Channels 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 12 months ago · None stated GitHub repository of Seykota Alt 10: Profit Targets

More Breakout 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