Strategy · Pine Script v6 · On the chart

PineForge — Cadence Matrix Pairing

by pineforge-4pass· code credited to PineForge

The Cadence Matrix Pairing strategy calculates price direction changes and volume confirmation across short, medium, and long horizons using close comparisons and simple moving averages of volume.

View on GitHub

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

59 lines of Pine Script v6 from validation/matrix-cadence-transpose-pairs-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: Cadence Matrix Pairing
// A transposed grid pairs price direction and volume confirmation by horizon.
strategy("PineForge — Cadence Matrix Pairing", 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)

shortHorizon = input.int(6, "Short Horizon", minval=2, group="Pair Grid")
mediumHorizon = input.int(18, "Medium Horizon", minval=3, group="Pair Grid")
longHorizon = input.int(54, "Long Horizon", minval=5, group="Pair Grid")
requiredPairs = input.int(2, "Required Confirmed Pairs", minval=1, maxval=3, group="Pair Grid")
trendLength = input.int(43, "Trend EMA Length", minval=5, group="Trend")
atrLength = input.int(16, "ATR Length", minval=2, group="Risk")
maximumAtrLoss = input.float(2.4, "Maximum ATR Loss", minval=0.5, step=0.1, group="Risk")

shortPriceUp = close > close[shortHorizon] ? 1.0 : 0.0
mediumPriceUp = close > close[mediumHorizon] ? 1.0 : 0.0
longPriceUp = close > close[longHorizon] ? 1.0 : 0.0
shortVolumeFirm = volume > ta.sma(volume, shortHorizon) ? 1.0 : 0.0
mediumVolumeFirm = volume > ta.sma(volume, mediumHorizon) ? 1.0 : 0.0
longVolumeFirm = volume > ta.sma(volume, longHorizon) ? 1.0 : 0.0

var matrix<float> factorRows = matrix.new<float>(2, 3, 0.0)
factorRows.set(0, 0, shortPriceUp)
factorRows.set(0, 1, mediumPriceUp)
factorRows.set(0, 2, longPriceUp)
factorRows.set(1, 0, shortVolumeFirm)
factorRows.set(1, 1, mediumVolumeFirm)
factorRows.set(1, 2, longVolumeFirm)
horizonPairs = matrix.transpose(factorRows)

int confirmedPairs = 0
for horizonIndex = 0 to 2
    priceVote = horizonPairs.get(horizonIndex, 0)
    volumeVote = horizonPairs.get(horizonIndex, 1)
    if priceVote == 1.0 and volumeVote == 1.0
        confirmedPairs += 1

trendLine = ta.ema(close, trendLength)
atrValue = ta.atr(atrLength)
consensusReady = confirmedPairs >= requiredPairs

enterLong = consensusReady and not consensusReady[1] and close > trendLine
consensusEnded = confirmedPairs == 0 or close < trendLine
riskExceeded = strategy.position_size > 0 and close < strategy.position_avg_price - atrValue * maximumAtrLoss

if strategy.position_size == 0 and enterLong
    strategy.entry("Cadence Long", strategy.long)
else if strategy.position_size > 0 and (consensusEnded or riskExceeded)
    strategy.close("Cadence Long", comment=riskExceeded ? "ATR risk" : "Pair consensus")

plot(trendLine, "Trend EMA", color=color.orange)
plot(confirmedPairs, "Confirmed Horizon Pairs", color=color.blue, display=display.data_window)

Overview

PineForge — Cadence Matrix Pairing assembles these binary votes into a transposed matrix and tallies matching pairs that satisfy the required confirmed pairs threshold. When consensus is achieved and price exceeds the EMA trend line, it enters a long position. The trade exits on loss of consensus or when price falls below the average entry by the maximum ATR-based loss. It draws the trend EMA and confirmed pairs count on the price chart. Main inputs adjust the horizons, required pairs, trend length, ATR length, and risk multiplier. The strategy uses fixed position sizing with no pyramiding.

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

  • 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
Short Horizonint6shortHorizon
Medium Horizonint18mediumHorizon
Long Horizonint54longHorizon
Required Confirmed Pairsint2requiredPairs
Trend EMA Lengthint43trendLength
ATR Lengthint16atrLength
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

228 stars

This strategy enters long when a faster moving average crosses above a slower one and short when it crosses below, unless long-only mode is on. An optional volume filter requires volume above a 20-bar average times a multiplier. Exits use a percentage stop los

Strategy v6 TrendMoving averages
Updated 3 months ago · None stated GitHub repository of MA Cross Strategy Template

4x EMA + Volume

by hasnocool
106 stars

This strategy plots four exponential moving averages on the price chart and filters trades with a smoothed Ease of Movement oscillator. In the default mode it opens a long when price and the four averages are stacked upward and Ease of Movement is positive, th

Strategy v4 TrendMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of 4x EMA + Volume

This strategy enters long or short when eight conditions align over the last two bars. It requires EMA 10 and EMA 55 alignment on the one-hour, four-hour and daily charts, a positive ADX slope, matching monitor direction, and price relative to a 400-bar point

Strategy v5 TrendMoving averages
Updated 1 year ago · None stated GitHub repository of Ruckard ABCBitcoin TradingLatino B002
12 stars

This strategy enters long when a fast EMA crosses above a slow EMA and RSI, ADX, and volume all clear their thresholds. It sizes the order from a percentage of equity and an ATR stop distance, then sets a partial profit target at a multiple of that risk. After

Strategy v5 TrendMoving averages
Updated 4 months ago · None stated GitHub repository of BTC 4H Institutional Trend
8 stars

This overlay strategy combines three distinct SuperTrend levels with multiple moving averages and volume profile analytics on the main price chart. It calculates trend directions using three configurable ATR periods and multipliers alongside SMA, EMA, and HMA

Strategy v5 TrendVolatility & bands
Updated 4 years ago · None stated GitHub repository of ATR 3Lvls VP Strategy

This strategy calculates trade signals by evaluating a daily session Volume Weighted Average Price relative to 90-period Exponential Moving Averages requested from 1-day and 4-hour higher timeframes. Long and short entries occur when VWAP crosses over or under

Strategy v5 Moving averagesTrend Repaints
Updated 3 years ago · MIT GitHub repository of 1D Bullish Buy 4H Bearish Sell Session EMA

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