Strategy · Pine Script v6 · On the chart

PF probe 97a - tp/sl bracket isolate

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

This strategy identifies trend changes using a dual moving average crossover.

View on GitHub

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

64 lines of Pine Script v6 from validation/bracket-tp-sl-oca-reduce-isolate-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 97a — TP/SL OCA-reduce bracket (isolated from probe 97)
// Clean-room: written from validation goal, not from source.
//
// Purpose: isolate the OCA-reduce bracket surface from probe 97. Drops
// the gap/range-expansion gate, drops the pending stop entry, drops the
// max_intraday_filled_orders cap. Uses a plain dual-MA crossover to
// trigger entries so the bracket is the only non-trivial surface under
// test. If TV vs engine diverge here, the OCA-reduce bracket math
// (TP+SL share an OCA group; when one fills, the other auto-reduces by
// filled qty) is the bug locus.
//
// Validation goal: bit-exact trade list. Pass = identical exits because
// OCA-reduce arithmetic at the mintick boundary matches TV.
//
// TV setup: 15m chart, ETH-USDT-USDT (Binance USDT-M Perpetual). Full
// window matching corpus/data/ohlcv_ETH-USDT-USDT_15m.csv. Strategy
// properties: leave defaults. Export "List of trades" → tv_trades.csv.
//@version=6
strategy("PF probe 97a - tp/sl bracket isolate", shorttitle="PF_p97a_BRK",
     overlay=true, initial_capital=1000000,
     commission_type=strategy.commission.percent, commission_value=0,
     slippage=0, default_qty_type=strategy.fixed, default_qty_value=1,
     pyramiding=1, process_orders_on_close=false, calc_on_order_fills=false)

// ---- inputs --------------------------------------------------------
int i_fast    = input.int(9,  "Fast MA",         minval=2)
int i_slow    = input.int(21, "Slow MA",         minval=3)
int i_tp_ticks = input.int(10, "Take profit (ticks)", minval=1)
int i_sl_ticks = input.int(10, "Stop loss (ticks)",   minval=1)

// ---- entry signal: dual MA cross ----------------------------------
float fast = ta.sma(close, i_fast)
float slow = ta.sma(close, i_slow)
bool  go_long  = ta.crossover(fast, slow)
bool  go_short = ta.crossunder(fast, slow)

if go_long and strategy.position_size <= 0
    strategy.entry("L", strategy.long, comment="ma cross up")

if go_short and strategy.position_size >= 0
    strategy.entry("S", strategy.short, comment="ma cross dn")

// ---- bracket: TP + SL sharing an OCA reduce group ------------------
float pos_qty   = math.abs(strategy.position_size)
int   pos_dir   = strategy.position_size > 0 ? 1 : (strategy.position_size < 0 ? -1 : 0)
float entry_px  = strategy.position_avg_price
float tp_px     = entry_px + pos_dir * i_tp_ticks * syminfo.mintick
float sl_px     = entry_px - pos_dir * i_sl_ticks * syminfo.mintick

bool  in_position = pos_qty > 0
exit_dir = pos_dir > 0 ? strategy.short : strategy.long

if in_position
    strategy.order("BracketTP", exit_dir, qty=pos_qty, limit=tp_px,
         oca_name="bracket97a", oca_type=strategy.oca.reduce, comment="TP")
    strategy.order("BracketSL", exit_dir, qty=pos_qty, stop=sl_px,
         oca_name="bracket97a", oca_type=strategy.oca.reduce, comment="SL")
else
    strategy.cancel("BracketTP")
    strategy.cancel("BracketSL")

Overview

PF probe 97a - tp/sl bracket isolate computes fast and slow simple moving averages of the close price and generates long entry signals on fast SMA crossover above slow and short signals on crossover below. Upon entry it calculates take profit and stop loss prices offset by user-defined tick distances from the average entry price. It then places limit and stop orders that belong to the same OCA reduce group so that if one order fills the other reduces by the filled quantity. The main input settings adjust the fast MA length, slow MA length, take profit ticks, and stop loss ticks. The strategy plots its buy and sell signals on the price chart overlay.

Details

Published by

pineforge-4pass on GitHub

Code credit

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

Draws

On the price chart

Markets

Crypto

Timeframes

M15-H1

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
Fast MAint9i_fast
Slow MAint21i_slow
Take profit (ticks)int10i_tp_ticks
Stop loss (ticks)int10i_sl_ticks
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

Omar Edited WF

by Alorse
330 stars

Omar Edited WF is a trading strategy overlay built around Williams Fractals and multiple Exponential Moving Averages. It detects high and low fractal pivot points over configurable lookback periods alongside three adjustable EMA trendlines. Long entries are ma

Strategy v5 TrendMoving averages
Updated 2 months ago · None stated GitHub repository of Omar Edited WF
257 stars

This strategy calculates dynamic support and resistance levels using pivot highs and lows alongside a custom smoothed trend filter and a 3-period EMA. It identifies entry opportunities when price breaks out relative to the trend filter and short-term EMA cross

Strategy v5 TrendSupport & resistance Repaints
Updated 7 weeks ago · None stated GitHub repository of 30s - ES 1m Strategy Candle Bar

This strategy overlays the price chart and looks for VWAP pullbacks. It goes long when a short SMA crosses above VWAP after RSI has been oversold within ten bars, and short on the opposite cross after RSI has been overbought. Optional Minervini-style moving-av

Strategy v5 TrendOscillators & momentum
Updated 2 years ago · GPL-3.0 GitHub repository of Advanced VWAP-Momentum Pullback Trend Qualifier
104 stars

This strategy combines three Exponential Moving Averages with Williams Fractals to execute trend-following or mean-reverting trades. It analyzes price structure using short, medium, and long-term EMAs along with fractal highs and lows. Entries trigger when fra

Strategy v5 TrendMoving averages
Updated 3 years ago · MIT GitHub repository of 3MA and Fractals Strategy

This strategy executes trades based on pivot levels, an exponential moving average, and a multi-stage smoothing trend line. It identifies support and resistance points from pivot highs and lows, combining them with price relationship rules against a custom smo

Strategy v5 TrendMoving averages Repaints
Updated 2 years ago · None stated GitHub repository of Binancash - Candle Strategy Futures on Binance
13 stars

This strategy generates entry signals using pivot points and uses custom Curie moving average closing lines for exiting positions. It features risk management components including percentage-based stop loss, take profit, trailing stops, and break-even levels,

Strategy v5 TrendMoving averages
Updated 1 year ago · None stated GitHub repository of BitLa PivotPoints A002

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