Strategy · Pine Script v6 · On the chart

PineForge — Revision Exit Replacement

by pineforge-4pass· code credited to PineForge

This strategy enters one long position when a fast exponential moving average crosses above a slow one.

View on GitHub

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

53 lines of Pine Script v6 from validation/bracket-revision-exit-replace-01/strategy.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

strategy.pine
//@version=6
// SPDX-License-Identifier: Apache-2.0
// Copyright 2026 PineForge
// PineForge Owned Strategy: Revision Exit Replacement
// One same-ID bracket narrows after a measured holding period.
strategy("PineForge — Revision Exit Replacement", overlay=true,
     initial_capital=100000,
     default_qty_type=strategy.fixed, default_qty_value=2,
     pyramiding=0, commission_type=strategy.commission.percent,
     commission_value=0.05, slippage=1,
     margin_long=100, margin_short=100,
     process_orders_on_close=false, calc_on_order_fills=false)

fastLength = input.int(20, "Fast EMA Length", minval=2, group="Signal")
slowLength = input.int(61, "Slow EMA Length", minval=5, group="Signal")
atrLength = input.int(17, "ATR Length", minval=2, group="Bracket")
revisionBars = input.int(14, "Revision Hold Bars", minval=2, group="Bracket")
wideStopAtr = input.float(2.8, "Initial Stop ATR", minval=0.5, step=0.1, group="Bracket")
wideTargetAtr = input.float(4.2, "Initial Target ATR", minval=0.5, step=0.1, group="Bracket")
narrowStopAtr = input.float(1.4, "Revised Stop ATR", minval=0.2, step=0.1, group="Bracket")
narrowTargetAtr = input.float(2.4, "Revised Target ATR", minval=0.5, step=0.1, group="Bracket")

fastLine = ta.ema(close, fastLength)
slowLine = ta.ema(close, slowLength)
atrValue = ta.atr(atrLength)
enterLong = ta.crossover(fastLine, slowLine)

var int admittedAt = na
if strategy.position_size == 0 and enterLong
    strategy.entry("Revision Long", strategy.long)

if strategy.position_size > 0 and strategy.position_size[1] <= 0
    admittedAt := bar_index
if strategy.position_size == 0
    admittedAt := na

heldBars = na(admittedAt) ? 0 : bar_index - admittedAt
if strategy.position_size > 0 and heldBars < revisionBars
    strategy.exit("Revision Guard", from_entry="Revision Long",
         stop=strategy.position_avg_price - atrValue * wideStopAtr,
         limit=strategy.position_avg_price + atrValue * wideTargetAtr,
         comment="Initial bracket")
else if strategy.position_size > 0
    strategy.exit("Revision Guard", from_entry="Revision Long",
         stop=strategy.position_avg_price - atrValue * narrowStopAtr,
         limit=strategy.position_avg_price + atrValue * narrowTargetAtr,
         comment="Revised bracket")

if strategy.position_size > 0 and ta.crossunder(fastLine, slowLine)
    strategy.close("Revision Long", comment="Trend ended")

plot(fastLine, "Fast EMA", color=color.blue)
plot(slowLine, "Slow EMA", color=color.orange)

Overview

While the trade is open, it keeps an ATR stop and target under the same exit identifier. For the first revision hold bars those distances stay wide; afterward the same exit is replaced with a narrower stop and target. A fast-below-slow cross closes the long. Both averages plot on the price chart. Quantity is fixed and pyramiding is off.

Details

Published by

pineforge-4pass on GitHub

Code credit

PineForge, 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-tradingbacktestingparitypine-scriptpinescriptquantitative-financetest-corpustradingview

Settings

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

SettingTypeDefaultVariable
Fast EMA Lengthint20fastLength
Slow EMA Lengthint61slowLength
ATR Lengthint17atrLength
Revision Hold Barsint14revisionBars
Initial Stop ATRfloat2.8wideStopAtr
Initial Target ATRfloat4.2wideTargetAtr
Revised Stop ATRfloat1.4narrowStopAtr
Revised Target ATRfloat2.4narrowTargetAtr
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 overlay strategy offers two selectable entry modes: a Bollinger squeeze on typical price and a simple moving-average cross. It filters trades by weekday, session, date range, and an optional news window, and can restrict direction or invert the side. Risk

Strategy v5 Volatility & bandsMoving averages
Updated 2 days ago · None stated GitHub repository of Boilerplate Configurable Strategy [Yosiet]
257 stars

This overlay strategy targets one-minute ES futures and plots volume-weighted moving-average bands from the open, scaled by a standard-deviation multiple, plus a slower band from ten-minute opens. A higher-timeframe exponential moving average can filter trades

Strategy v6 Moving averagesVolatility & bands
Updated 7 weeks ago · None stated GitHub repository of ES - Futures 1M No Repaint
228 stars

The Mean Reversion Strategy Template calculates a baseline mean using SMA, EMA, or VWAP alongside upper and lower deviation bands based on standard deviation, ATR, or percentage offsets. It generates long and short entries when price touches, bounces from, or

Strategy v6 Mean reversionMoving averages
Updated 3 months ago · None stated GitHub repository of Mean Reversion Strategy Template

STRG-BBForce

by harryguiacorn
220 stars

STRG-BBForce is a Bollinger Bands trend-following strategy. It calculates standard Bollinger Bands and tracks directional alignment across the upper, lower, and basis lines. When all three lines slope upward, it opens a long position and closes short positions

Strategy v5 TrendVolatility & bands
Updated 1 year ago · None stated GitHub repository of STRG-BBForce

Bollinger Breakout

by hackingthemarkets
189 stars

This price-chart strategy plots a simple moving average and upper and lower bands built from the standard deviation of close, scaled by separate offset inputs. It enters a fixed quantity long when close crosses above the upper band and a fixed quantity short w

Strategy v4 Volatility & bandsBreakout
Updated 3 years ago · None stated GitHub repository of Bollinger Breakout

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