Strategy · Pine Script v6 · Own pane

Matrix Eigen PCA

by pineforge-4pass· code credited to PineForge contributors 2026

This strategy computes a 2x2 covariance matrix from short-term differences in close-open and high-low ranges.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code43
Settings1inputs
LicenceApache-2.0
Last update5 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

43 lines of Pine Script v6 from validation/matrix-covariance-eigen-pca-01/strategy.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

strategy.pine
// This Pine Script® code is licensed under Apache-2.0
// SPDX-License-Identifier: Apache-2.0
// © PineForge contributors 2026
//
// PF probe 33 — matrix.new<float>() covariance + largest-eigenvalue extraction
// Purpose: parity test for `var matrix<float>` cell mutations (`m.set(i,j,v)`)
// driven by per-bar ta.sma covariance entries, then eigenvalue derivation.
//
//@version=6
strategy("Matrix Eigen PCA", overlay=false, initial_capital=1000000, process_orders_on_close=false, pyramiding=1, commission_type=strategy.commission.percent, commission_value=0, slippage=0, default_qty_type=strategy.fixed, default_qty_value=1)

length = input.int(14, "Length", minval=2)
v1 = close - open
v2 = high - low

// Covariance matrix simulation over `length`
v1_mean = ta.sma(v1, length)
v2_mean = ta.sma(v2, length)

cov11 = ta.sma((v1 - v1_mean) * (v1 - v1_mean), length)
cov12 = ta.sma((v1 - v1_mean) * (v2 - v2_mean), length)
cov21 = cov12
cov22 = ta.sma((v2 - v2_mean) * (v2 - v2_mean), length)

var m = matrix.new<float>(2, 2, 0.0)
m.set(0, 0, cov11)
m.set(0, 1, cov12)
m.set(1, 0, cov21)
m.set(1, 1, cov22)

covReady = not na(cov11) and not na(cov12) and not na(cov22)

// Largest eigenvalue = principal variance (always >= 0); compare to its SMA so crosses are meaningful
float lam = na
if covReady
    lam := array.size(m.eigenvalues()) > 0 ? array.get(m.eigenvalues(), 0) : na

lamSma = ta.sma(lam, length)

if covReady and not na(lam) and not na(lamSma) and ta.crossover(lam, lamSma)
    strategy.entry("Long", strategy.long)
if covReady and not na(lam) and not na(lamSma) and ta.crossunder(lam, lamSma)
    strategy.entry("Short", strategy.short)

Overview

Matrix Eigen PCA extracts the largest eigenvalue of the matrix as a volatility measure and compares it to its own simple moving average. When the largest eigenvalue crosses above the moving average it opens a long position. When it crosses below the moving average it opens a short position. The strategy uses fixed position sizing and no stop-loss. The length input controls the lookback period for all moving averages and the matrix update.

Details

Published by

pineforge-4pass on GitHub

Code credit

PineForge contributors 2026, as written in the script's header

Type

Strategy, Pine Script v6

Draws

Separate pane below the chart

Category

Volatility & bands, Oscillators & momentum, Moving averages

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy can add several entries in the same direction
  • 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
Lengthint14length
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 captures strong bullish momentum by combining a 200-period SMA baseline, a custom Bollinger Band, the True Strength Index (TSI) smoothed with WMAs, and the ADX trend strength indicator. It initiates long positions when price is above the 200 SMA,

Strategy v4 TrendOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of ADX_TSI_Bol Band Trend Chaser

EMA Ribbon MACD

by iamrichardD
57 stars

This strategy combines an EMA ribbon with MACD confirmation and plots in a separate pane. It enters when ribbon alignment, optional MACD zero or signal crosses, volume, smart-money, and multi-timeframe filters agree, then exits with percentage stop loss and ta

Strategy v6 TrendMoving averages
Updated 1 year ago · Apache-2.0 GitHub repository of EMA Ribbon MACD
25 stars

This Pine Script strategy calculates Bayesian probabilities of price breaking up or down relative to Bollinger Bands and a Simple Moving Average. It plots these breakout and breakdown probability lines as oscillators in a separate pane. Long entries trigger wh

Strategy v4 Oscillators & momentumVolatility & bands
Updated 6 years ago · None stated GitHub repository of Bayesian BBSMA Oscillator Strategy

Greeffer BB Strategy

by SammyEnigma
18 stars

This strategy combines Bollinger Bands, Bollinger Band Width, and the Relative Strength Index (RSI) for mean-reversion trades. It enters long when price crosses below the lower band with oversold RSI, or when band width contracts under low volatility. Short en

Strategy v4 Mean reversionOscillators & momentum
Updated 6 years ago · None stated GitHub repository of Greeffer BB Strategy

AwesomeADX

by koradiyakaushal
12 stars

AwesomeADX is a Pine Script v4 strategy that combines an Awesome Oscillator, ADX directional movement, and Bollinger percent B with an optional four-length moving-average trend filter. It sizes each position as a percentage of equity and can limit trades to a

Strategy v4 Oscillators & momentumMoving averages
Updated 5 years ago · MIT GitHub repository of AwesomeADX

Alper

by avatar-lavventura
2 stars

Alper is a multi-indicator trading strategy combining a WaveTrend oscillator, RSI, and Squeeze Momentum logic based on Bollinger Bands and Keltner Channels. Operating within a user-defined backtest time window, it plots WaveTrend lines, overbought and oversold

Strategy v4 Oscillators & momentumVolatility & bands
Updated 7 months ago · None stated GitHub repository of Alper

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