Strategy · Pine Script v6 · On the chart

Aperture COG LinReg

by pineforge-4pass· code credited to PineForge

A long-only strategy that combines the Center of Gravity oscillator with a linear regression path.

View on GitHub

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

37 lines of Pine Script v6 from validation/ta-aperture-cog-linreg-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: Aperture COG LinReg
// Center-of-gravity rotation is admitted only with a rising regression path.
strategy("PineForge — Aperture COG LinReg", 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)

cogLength = input.int(13, "COG Length", minval=3, group="Cycle")
cogSignalLength = input.int(7, "COG Signal Length", minval=2, group="Cycle")
regressionLength = input.int(38, "Regression Length", minval=5, group="Trend")
atrLength = input.int(20, "ATR Length", minval=2, group="Risk")
maximumAtrLoss = input.float(2.5, "Maximum ATR Loss", minval=0.5, step=0.1, group="Risk")

cogValue = ta.cog(close, cogLength)
cogSignal = ta.ema(cogValue, cogSignalLength)
regressionNow = ta.linreg(close, regressionLength, 0)
regressionPrior = ta.linreg(close, regressionLength, 1)
atrValue = ta.atr(atrLength)
regressionRising = regressionNow > regressionPrior

enterLong = ta.crossover(cogValue, cogSignal) and regressionRising and close > regressionNow
cycleEnded = ta.crossunder(cogValue, cogSignal) or not regressionRising
riskExceeded = strategy.position_size > 0 and close < strategy.position_avg_price - atrValue * maximumAtrLoss

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

plot(regressionNow, "Regression Path", color=color.fuchsia)
plot(cogValue, "COG", color=color.teal, display=display.data_window)

Overview

Aperture COG LinReg enters long when the oscillator crosses above its EMA signal while the regression line is rising and price sits above it. It exits when the oscillator crosses back below, the regression stops rising, or price falls a set multiple of ATR below the average entry. Lengths and the ATR multiple are adjustable. It plots the regression line 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

Oscillators & momentum, Trend

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
COG Lengthint13cogLength
COG Signal Lengthint7cogSignalLength
Regression Lengthint38regressionLength
ATR Lengthint20atrLength
Maximum ATR Lossfloat2.5maximumAtrLoss
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

330 stars

2 EMA/SMA + RSI Strategy [Alorse] combines three configurable moving averages with a short-period Relative Strength Index filter. It plots fast, slow, and trend moving averages on the price chart. Long entries trigger when the fast moving average is above the

Strategy v4 TrendOscillators & momentum
Updated 2 months ago · None stated GitHub repository of 2 EMA/SMA + RSI Strategy [Alorse]

Acrypto - Weighted Strategy

by AlbertoCuadra
318 stars

This strategy plots on the price chart and opens long or short positions when a weighted score from MACD, Stochastic RSI, RSI, Supertrend and a moving-average crossover exceeds a user-set trigger. Each component has its own weight and candle delay. Entries can

Strategy v5 TrendOscillators & momentum
Updated 3 years ago · Custom licence GitHub repository of Acrypto - Weighted Strategy
285 stars

Mean Reversion Strategy is an overlay strategy that identifies pullbacks using a long-term EMA, RSI, and candlestick patterns. It generates long signals when a bullish engulfing candle forms below the EMA while RSI is oversold, and short signals when a bearish

Strategy v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Strategy
218 stars

This strategy generates trading signals based on a selectable momentum engine, supporting MACD, RSI, Stochastic, or Rate of Change. Entries trigger on signal crosses, zero-line crosses, or threshold crosses, with an optional moving average trend filter. Risk m

Strategy v6 Oscillators & momentumTrend
Updated 3 months ago · None stated GitHub repository of Momentum Strategy Template

255 EMA Strategy

by hasnocool
106 stars

255 EMA Strategy combines an exponential moving average with Average True Range bands and standard MACD crossovers to generate entry signals. Drawn directly on the price chart, it plots the central 255 EMA along with upper and lower volatility envelopes. Trade

Strategy v4 Moving averagesOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of 255 EMA 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