Indicator · Pine Script v6 · On the chart

SCA EA Parity Demo SMA 3/5

by arnjesix· code credited to StratCoreAlpha

A small demonstration indicator that marks crossovers between a 3-period and a 5-period simple moving average on completed bars, with a triangle below the bar for a bullish cross and above it for a bearish cross.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code101
Settings4inputs
LicenceMIT
Last update4 days ago25 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 indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

101 lines of Pine Script v6 from src/parity/sca_ea_parity_demo.pine, published under MIT. Keep the author's credit and licence lines when you reuse it.

sca_ea_parity_demo.pine
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © StratCoreAlpha — owned sample. No customer case, no live track record, no profit claim.

//@version=6
indicator("SCA EA Parity Demo — SMA(3)/SMA(5) [StratCoreAlpha]", overlay = true, max_labels_count = 0)

// Frozen rule (must match README + MQL5 + fixture_ohlc.csv):
// completed-bar SMA(3) vs SMA(5) on close; BULL = prevFast <= prevSlow and fast > slow;
// BEAR = prevFast >= prevSlow and fast < slow; first eligible bar index 5; one bar one event.
int   FAST_LEN = input.int(3, "Fast SMA length", minval = 1)
int   SLOW_LEN = input.int(5, "Slow SMA length", minval = 2)
bool  SHOW_FIXTURE_TABLE = input.bool(true, "Show owned-fixture parity table")
bool  PLOT_LIVE_SIGNALS  = input.bool(true, "Plot live-chart crossover markers")

// ---- Live-chart rule path (confirmed historical bars; forming bar never decides) ----
float liveFast = ta.sma(close, FAST_LEN)
float liveSlow = ta.sma(close, SLOW_LEN)
bool  liveBull = liveFast[1] <= liveSlow[1] and liveFast > liveSlow
bool  liveBear = liveFast[1] >= liveSlow[1] and liveFast < liveSlow

plotshape(PLOT_LIVE_SIGNALS and liveBull, title = "Live BULL cross", style = shape.triangleup, location = location.belowbar, color = color.teal, size = size.small)
plotshape(PLOT_LIVE_SIGNALS and liveBear, title = "Live BEAR cross", style = shape.triangledown, location = location.abovebar, color = color.red, size = size.small)

// ---- Owned fixture path: 12 explicit closes, byte-identical to fixture_ohlc.csv ----
array<float> FX_CLOSE = array.from(10.0, 10.0, 10.0, 10.0, 10.0, 12.0, 12.0, 12.0, 8.0, 8.0, 8.0, 8.0)
array<string> FX_DATE = array.from("01-05 09:00", "01-05 10:00", "01-05 11:00", "01-05 12:00", "01-05 13:00", "01-05 14:00", "01-05 15:00", "01-05 16:00", "01-05 17:00", "01-05 18:00", "01-05 19:00", "01-05 20:00")

fxSMA(array<float> a, int idx, int len) =>
    float s = na
    if idx + 1 >= len
        float sum = 0.0
        for k = idx - len + 1 to idx
            sum := sum + array.get(a, k)
        s := sum / len
    s

var int    fxCount = 0
var int    fxFirstIdx = -1
var int    fxFirstVal = 0
var int    fxSecondIdx = -1
var int    fxSecondVal = 0
var string fxList = ""
var bool   fxDone = false

if barstate.islast and not fxDone
    for i = 0 to 11
        float fNow = fxSMA(FX_CLOSE, i, FAST_LEN)
        float sNow = fxSMA(FX_CLOSE, i, SLOW_LEN)
        int sig = 0
        if i >= 5 and i >= 1 and not na(fNow) and not na(sNow)
            float fPrev = fxSMA(FX_CLOSE, i - 1, FAST_LEN)
            float sPrev = fxSMA(FX_CLOSE, i - 1, SLOW_LEN)
            if not na(fPrev) and not na(sPrev)
                bool bull = fPrev <= sPrev and fNow > sNow
                bool bear = fPrev >= sPrev and fNow < sNow
                if bull and not bear
                    sig := 1
                if bear and not bull
                    sig := -1
        if sig != 0
            fxCount += 1
            fxList := fxList + (str.length(fxList) > 0 ? ", " : "") + str.tostring(i) + ":" + (sig > 0 ? "BULL" : "BEAR")
            if fxFirstIdx == -1
                fxFirstIdx := i
                fxFirstVal := sig
            else if fxSecondIdx == -1
                fxSecondIdx := i
                fxSecondVal := sig
    fxDone := true

bool acc01 = fxFirstIdx >= 5
bool acc02 = fxFirstIdx == 5 and fxFirstVal == 1
bool acc03 = fxCount == 2 and fxSecondIdx == 8 and fxSecondVal == -1
bool allPass = acc01 and acc02 and acc03
string verdict = allPass ? "PASS" : "FAIL"

// Visible on ANY TradingView chart: compares this embedded fixture run to the
// frozen expectation [5:BULL, 8:BEAR]. Browser check needs no broker data.
var table fxTable = table.new(position.bottom_right, 3, 6, border_width = 1)
if barstate.islast and SHOW_FIXTURE_TABLE
    table.cell(fxTable, 0, 0, "SCA fixture parity", text_color = color.white, bgcolor = color.new(color.blue, 20))
    table.cell(fxTable, 1, 0, "expected", text_color = color.white, bgcolor = color.new(color.blue, 20))
    table.cell(fxTable, 2, 0, "computed", text_color = color.white, bgcolor = color.new(color.blue, 20))
    table.cell(fxTable, 0, 1, "ACC-01 warmup 0-4 silent", text_color = color.white, bgcolor = color.new(color.black, 10))
    table.cell(fxTable, 1, 1, "none < idx5", text_color = color.white, bgcolor = color.new(color.black, 10))
    table.cell(fxTable, 2, 1, acc01 ? "silent" : "LEAK", text_color = acc01 ? color.teal : color.red, bgcolor = color.new(color.black, 10))
    table.cell(fxTable, 0, 2, "ACC-02 bull", text_color = color.white, bgcolor = color.new(color.black, 10))
    table.cell(fxTable, 1, 2, "5:BULL", text_color = color.white, bgcolor = color.new(color.black, 10))
    table.cell(fxTable, 2, 2, acc02 ? "5:BULL" : "MISMATCH", text_color = acc02 ? color.teal : color.red, bgcolor = color.new(color.black, 10))
    table.cell(fxTable, 0, 3, "ACC-03 bear", text_color = color.white, bgcolor = color.new(color.black, 10))
    table.cell(fxTable, 1, 3, "8:BEAR", text_color = color.white, bgcolor = color.new(color.black, 10))
    table.cell(fxTable, 2, 3, acc03 ? "8:BEAR" : "MISMATCH", text_color = acc03 ? color.teal : color.red, bgcolor = color.new(color.black, 10))
    table.cell(fxTable, 0, 4, "Ordered list [" + fxList + "]", text_color = color.white, bgcolor = color.new(color.black, 10))
    table.cell(fxTable, 1, 4, "[5:BULL, 8:BEAR]", text_color = color.white, bgcolor = color.new(color.black, 10))
    table.cell(fxTable, 2, 4, verdict, text_color = allPass ? color.teal : color.red, bgcolor = allPass ? color.new(color.teal, 85) : color.new(color.red, 85))
    table.cell(fxTable, 0, 5, "Note: static fixture parity; live-chart markers use broker bars, not this fixture.", text_color = color.white, bgcolor = color.new(color.black, 10))
    table.cell(fxTable, 1, 5, "fixture: 12 owned H1 bars", text_color = color.white, bgcolor = color.new(color.black, 10))
    table.cell(fxTable, 2, 5, "SMA(3)/SMA(5) close", text_color = color.white, bgcolor = color.new(color.black, 10))

if barstate.islast and not SHOW_FIXTURE_TABLE
    table.clear(fxTable, 0, 0, 2, 5)

Overview

SCA EA Parity Demo SMA 3/5 also checks a fixed set of twelve sample closes held in the script and shows a table comparing the crossovers found against expected results. The lengths and both display options can be changed. It is intended for rule-parity testing, not trading.

Details

Published by

arnjesix on GitHub

Code credit

StratCoreAlpha, 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-tradingexpert-advisorforexfreelancermetatrader5mql5pine-scripttrading-automationtradingviewmql5-script

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Fast SMA lengthint3FAST_LEN
Slow SMA lengthint5SLOW_LEN
Show owned-fixture parity tablebooltrueSHOW_FIXTURE_TABLE
Plot live-chart crossover markersbooltruePLOT_LIVE_SIGNALS
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

947 stars

The Adaptive Laguerre Filter calculates a smoothed, dynamically adjusted trendline plotted directly on the main price chart. It dynamically adjusts its damping factor (alpha) based on recent price range variations and median percentile calculations over a spec

Indicator v4 TrendMoving averages
Updated 11 days ago · GPL-3.0 GitHub repository of Adaptive Laguerre Filter

This overlay indicator plots a Supertrend from an ATR length and factor, four exponential moving averages, and a selectable VWAP or TWAP taken from a chosen timeframe on the price chart. It also shows MACD and stochastic with adjustable lengths, smoothing, ver

Indicator v5 Oscillators & momentumMoving averages
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup: Vijay Thakare Option Buying Scalping Setup
330 stars

This script plots three moving averages on the price chart: a fast EMA or SMA with 10 periods, a slow EMA or SMA with 20 periods, and a trend EMA or SMA with 100 periods. It signals trend changes by drawing a white cross when the fast moving average crosses ab

Indicator v4 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of 3 EMA/SMA + Cross [Alorse]
318 stars

This indicator plots four customizable moving averages directly on the main price chart using default lengths of 3, 8, 21, and 50 periods. It fills the space between adjacent averages in green or maroon depending on trend alignment. Additionally, it computes B

Indicator v5 Moving averagesTrend
Updated 2 months ago · MIT GitHub repository of Multiple Moving Averages
285 stars

Mean Reversion Study is an indicator that identifies trade setups combining exponential moving averages, RSI extremes, and engulfing candlestick patterns. It highlights bullish setups when a bullish engulfing candle forms below the EMA while RSI is oversold, a

Indicator v4 Mean reversionCandlestick patterns
Updated 3 years ago · None stated GitHub repository of Mean Reversion Study

NVDA Trend Ribbon

by longsurf-ai
280 stars

This indicator plots three exponential moving averages and ATR volatility envelopes on the price chart. It compares the fast and slow EMAs to shade a trend ribbon and marks confirmed upward and downward crossovers with triangle labels. Settings change the thre

Indicator v6 TrendMoving averages
Updated 2 days ago · MIT GitHub repository of NVDA Trend Ribbon

More Moving averages 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