Strategy · Pine Script v6 · On the chart

Advanced Trade Metrics

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

Advanced Trade Metrics is an overlay breakout strategy that uses a 20-bar Donchian channel to generate trade signals.

View on GitHub

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

37 lines of Pine Script v6 from validation/ta-closedtrades-risk-introspection-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 35 — strategy.closedtrades / strategy.risk introspection
// Purpose: parity test for `strategy.risk.max_drawdown(...)` plus
// `strategy.closedtrades` / `strategy.closedtrades.profit(N)` lookback driving
// per-trade qty sizing.
//
//@version=6
strategy("Advanced Trade Metrics", overlay=true, 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)

strategy.risk.max_drawdown(20, strategy.percent_of_equity)

// Basic Donchian breakout
hh = ta.highest(high, 20)
ll = ta.lowest(low, 20)

// Risk sizing based on past performance
qty = 1.0
if strategy.closedtrades > 0
    last_profit = strategy.closedtrades.profit(strategy.closedtrades - 1)
    if last_profit < 0
        qty := 0.5
    else
        qty := 2.0

if close > hh[1]
    strategy.entry("Long", strategy.long, qty=qty)
if close < ll[1]
    strategy.entry("Short", strategy.short, qty=qty)

if strategy.opentrades > 0
    open_dd = strategy.opentrades.max_drawdown(0)
    if open_dd > 1000
        strategy.close("Long")
        strategy.close("Short")

Overview

Advanced Trade Metrics opens long positions when the closing price breaches the prior 20-bar high and short positions when it drops below the 20-bar low. Position sizing dynamically adjusts based on the outcome of the previous closed trade, scaling down after a loss and scaling up after a win. Exits trigger if open trade drawdown exceeds 1,000 units or if total equity drawdown hits the 20% risk limit. It lacks fixed stop-loss orders.

Details

Published by

pineforge-4pass on GitHub

Code credit

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

Draws

On the price chart

Category

Breakout, Trend

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

  • The strategy enters trades without a stop loss

Topics

algorithmic-tradingbacktestingparitypine-scriptpinescriptquantitative-financetest-corpustradingview

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

This trend-following strategy executes a classic Donchian channel breakout system designed to cross-validate backtest results against external framework benchmarks. It triggers a long entry when the closing price breaks above the highest high of the prior entr

Strategy v6 BreakoutTrend
Updated 2 days ago · AGPL-3.0 GitHub repository of Forven S01509 - Simple Donchian 20/10 Breakout
257 stars

This strategy plots running pivot highs as red R circles and pivot lows as blue S circles directly on the price chart. It computes an EMA 3 and a Cto trend line from close prices, then generates long signals on upward EMA-Cto crossovers combined with price pos

Strategy v6 TrendMoving averages Repaints
Updated 7 weeks ago · None stated GitHub repository of Best Chart 1m Strategy Candle Bar

12/26-IT Strategy

by hasnocool
106 stars

This strategy executes trades based on crossovers between a 12-period and a 26-period exponential moving average (EMA). Long positions can be filtered by pivot resistance breakouts and RSI boundary ranges. For trade management, it provides two configurable par

Strategy v5 TrendMoving averages
Updated 2 years ago · GPL-3.0 GitHub repository of 12/26-IT Strategy

均线突破交易系统

by tangly1024
76 stars

This strategy trades long breakouts of a fast and a slow moving average on the price chart. It opens a long position when price crosses above either average, using a percentage of equity as size. It reduces the position by a set share when the high reaches the

Strategy v5 TrendMoving averages
Updated 5 months ago · None stated GitHub repository of 均线突破交易系统
53 stars

This strategy enters long or short on the price chart when price is on the correct side of a 200-period EMA, MACD agrees, RSI is not at the opposing extreme, ADX exceeds a threshold, volume beats a 20-bar average, and close breaks the recent high or low. A tim

Strategy v6 TrendOscillators & momentum
Updated 2 months ago · MPL-2.0 GitHub repository of BTCUSD 5M Optimized Strategy

More Breakout 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