Indicator · Pine Script v6 · Own pane

Test Block Pattern Reference

by MoDarK-MK· code credited to test-block-pattern

This script acts as a reference template for testing assertion blocks in Pine Script.

View on GitHub

GitHub stars1on the repository
Pine versionv6current
Lines of code67
Settings1inputs
LicenceMPL-2.0
Last update7 weeks ago4 Sep 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

67 lines of Pine Script v6 from assets/templates/test_block_template.pine, published under MPL-2.0. Keep the author's credit and licence lines when you reuse it.

test_block_template.pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © test-block-pattern

//@version=6
// This file is a RUNNABLE REFERENCE for the assertion-counter test pattern used
// throughout this skill's scaffolded templates. It is not meant to be scaffolded
// as a real project — copy the pieces you need into your own script's testMode
// section. Tallying pass/fail counts in a small table (instead of one label per
// assertion per bar) avoids spending your label/plot-count budget on a long
// backtest, and gives an at-a-glance summary instead of a wall of markers.
indicator("Test Block Pattern Reference", overlay=false)

// ————— Inputs
bool testModeInput = input.bool(true, "Test Mode", group="Debug/Test")

// ————— Calculations
// Keep this in sync with the number of assertFailed() calls below.
int TEST_COUNT = 2
var int passCount = 0
var int failCount = 0

// @function Draws a failure marker and RETURNS 1 on failure, 0 on pass.
//
// The shape matters: Pine forbids a function from modifying a variable declared
// at global scope (compile error CE10088), so an assertion helper CANNOT
// increment the counters itself — it has to return a number the caller adds up.
// A helper that also needs both if/else branches to yield the same type
// (CE10235) is a second reason to end the function on one plain expression.
assertFailed(bool condition, string description) =>
    if not condition
        label.new(
             bar_index, high, "FAIL: " + description, color=#f23645,
             textcolor=color.white, style=label.style_label_down, size=size.tiny
             )
    condition ? 0 : 1

// Example assertions — replace with real checks about your own script's values.
// Keep them cheap (no repainting side effects) since they run every bar.
if testModeInput
    int fails = 0
    fails += assertFailed(not na(close), "close should never be na")
    fails += assertFailed(bar_index >= 0, "bar_index should never be negative")
    failCount += fails
    passCount += TEST_COUNT - fails

// ————— Visuals
// Every cell sets text_color explicitly: Pine defaults cell text to BLACK, so a
// cell without it is invisible on a dark chart — and a table with no bgcolor is
// fully transparent, which makes that worse.
color PASS_COLOR  = #089981
color FAIL_COLOR  = #f23645
color MUTED_COLOR = #b2b5be
color PANEL_COLOR = #131722

var table testDashboard = table.new(
     position.bottom_left, 2, 2, border_width=1,
     bgcolor=color.new(PANEL_COLOR, 15),
     frame_color=color.new(MUTED_COLOR, 70), frame_width=1)
if testModeInput and barstate.islast
    testDashboard.cell(0, 0, "Passed", text_size=size.small, text_color=MUTED_COLOR,
         text_halign=text.align_left)
    testDashboard.cell(1, 0, str.tostring(passCount), text_color=PASS_COLOR,
         text_size=size.small, text_halign=text.align_right)
    testDashboard.cell(0, 1, "Failed", text_size=size.small, text_color=MUTED_COLOR,
         text_halign=text.align_left)
    testDashboard.cell(1, 1, str.tostring(failCount), text_size=size.small,
         text_color=failCount > 0 ? FAIL_COLOR : PASS_COLOR, text_halign=text.align_right)

Overview

Test Block Pattern Reference calculates pass and fail counts for assertions and displays them in a table dashboard at the bottom left of the chart. When test mode is enabled, it runs assertions on values like close and bar_index, updating counters and showing results in a table with color-coded pass and fail counts. It draws failure markers on the chart and a test dashboard table in a separate pane. The testModeInput setting toggles the visibility of the dashboard and test logic.

Details

Published by

MoDarK-MK on GitHub

Code credit

test-block-pattern, as written in the script's header

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Screeners & dashboards

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

ci-cdindicatorslinterpine-scriptpythonstrategiestradingview

Settings

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

SettingTypeDefaultVariable
Test ModebooltruetestModeInput
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

948 stars

This indicator measures the chart symbol’s percentage change from the opening price at the start of each US presidential term and plots those values as histogram columns in a separate pane. Columns are offset so each administration appears separately, with a s

Indicator v6 Screeners & dashboards
Updated 10 days ago · GPL-3.0 GitHub repository of Presidents Performance

This indicator scans a pasted list of symbols for RSI directional momentum and shows matching long and short signals in a table in a separate pane. The user chooses continuous break, continuous retracement, flip break, flip retracement, divergence, or hidden d

Indicator v6 Oscillators & momentumDivergence
Updated 1 year ago · MPL-2.0 GitHub repository of Momentum Setup - RSI Directional Momentum Scanner

Tables-001

by ricardosantos79
261 stars

This indicator builds a TradingView table in a separate pane and fills its cells with fixed placeholder text according to whether each row and column index is even or odd. Users set the table position, the number of rows and columns, and the background, frame,

Indicator v4 Screeners & dashboards
Updated 4 years ago · None stated GitHub repository of Tables-001
257 stars

Donald SPX - Options Trading is an indicator designed to assist SPX index option traders by tracking session benchmarks and multi-timeframe moving average data. It calculates a 200-period weighted moving average (WMA) and requests multi-timeframe bar data from

Indicator v5 Moving averagesScreeners & dashboards Repaints
Updated 6 weeks ago · None stated GitHub repository of Donald SPX - Options Trading

Index Member Distribution

by TradersPost
218 stars

Calculates and plots a weighted histogram of constituent returns for major market indices (NDX, SPX, DJIA, and RUT) in a separate pane. Each histogram bin reflects the summed weights of members within that percentage return bracket. The script renders vertical

Indicator v6 Screeners & dashboards
Updated 3 months ago · None stated GitHub repository of Index Member Distribution

KamaFama

by Mastaaa1987
141 stars

KamaFama is an indicator that translates a Freqtrade trading strategy into Pine Script for visualization. It combines Kaufman Adaptive Moving Average (KAMA), MAMA/FAMA calculations derived via Hilbert Transform, Williams %R, and correlation trend filters to ev

Indicator v6 Moving averagesOscillators & momentum
Updated 6 weeks ago · MIT GitHub repository of KamaFama

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers