Strategy testing and trading software · Germanycontact@stratcorealpha.com · DE
All public work

Compiler-verified open-source Pine Script v6 diagnostic

Pine v6 Partial Exit State Inspector

A deterministic Pine Script diagnostic that makes initial-versus-remaining quantity semantics explicit for 50%, 33% and 25% partial exits and emits each tier once on a confirmed bar.

The engineering problem

Why this tool exists

A request to sell 50%, then 33%, then 25% is incomplete until the percentage base is frozen. If all three refer to the initial position they total 108%; if they refer to the remaining quantity, a 100-unit fixture exits 50, 16.5 and 8.375 units and leaves 25.125.

Published capabilities

  • Initial-versus-remaining quantity mode
  • Deterministic 100 → 50 → 33.5 → 25.125 state ladder
  • Explicit error when initial-position percentages exceed 100%
  • Confirmed-bar tier transitions
  • One event per tier with alerts disabled by default

Engineering evidence

  • Original MPL-2.0 Pine v6 source published on GitHub
  • Exact source saved in TradingView without a compile error on 2026-08-12
  • Public documentation freezes the formula, expected values and limitations
  • A reproducible 100-unit fixture exposes the quantity contract before implementation

What this case study does not claim

  • The script is a state diagnostic; it does not create entries, operate a broker account or claim trading performance.
  • The TradingView Basic-plan indicator cap prevented an on-chart transport test, so no chart, alert or broker acceptance is claimed.
  • The remaining-quantity model is a contract fixture; broker lot steps, fills and slippage remain outside scope.

Need related custom work?

Pine Partial Exit Audit — Written decision after contact

Review scope and boundaries

Trading risk disclosure

Futures and forex trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing one's financial security or lifestyle. Only risk capital should be used for trading, and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results.

Hypothetical performance disclosure

Hypothetical performance results have many inherent limitations. No representation is being made that any account will or is likely to achieve profits or losses similar to those shown. There are frequently sharp differences between hypothetical performance results and the actual results subsequently achieved by any particular trading program. Hypothetical results are generally prepared with the benefit of hindsight, do not involve financial risk, and cannot completely account for the impact of financial risk in actual trading. Market conditions, the ability to withstand losses, and adherence to a trading program can all materially affect actual results.

NinjaTrader trademark disclosure

NinjaTrader® is a registered trademark of NinjaTrader Group, LLC. No NinjaTrader company has any affiliation with the owner, developer, or provider of the products or services described herein, or any interest, ownership or otherwise, in any such product or service, or endorses, recommends or approves any such product or service.

Testimonials, when shown, may not represent the experience of other clients and are not a guarantee of future performance or success. Virtual-currency trading carries additional risks. See the CFTC customer advisories. Read the full financial risk disclaimer.