Separate early profit-taking from the remaining trade
A two-target strategy divides an entry into separately managed exit quantities. This Pine Script v6 example uses a two-unit long position with one unit assigned to each bracket. It keeps both stop distances fixed and does not move the second stop to breakeven when the first target fills. The purpose is to test the trade-off between early realization and participation in a longer move.
Signal and bracket arithmetic
Enter when the confirmed close crosses above the rolling highest high of the prior 20 bars, while the strategy is flat. Assume an illustrative fill at 100 and tick size 0.25. An eight-tick stop is 98; the first target eight ticks above entry is 102, and the second target sixteen ticks above entry is 104. If both targets fill, gross price gain across two units is six price-unit equivalents. If the first target fills and the other unit reaches its original stop, the gross result is zero before costs, assuming exact fills and equal unit value.

Hypothetical two-unit trade with an eight-tick stop and two distinct targets. The second leg retains its original stop.
Pine Script v6 example
//@version=6
strategy("Two target breakout", overlay = true,
pyramiding = 0, process_orders_on_close = false)
int stopTicks = input.int(8, "Stop ticks", minval = 1)
int target1 = input.int(8, "Target 1 ticks", minval = 1)
int target2 = input.int(16, "Target 2 ticks", minval = 1)
float resistance = ta.highest(high, 20)[1]
bool signal = ta.crossover(close, resistance)
if barstate.isconfirmed and strategy.position_size == 0 and signal
strategy.entry("L", strategy.long, qty = 2)
strategy.exit("Leg1", "L", qty = 1,
loss = stopTicks, profit = target1)
strategy.exit("Leg2", "L", qty = 1,
loss = stopTicks, profit = target2)
plot(resistance, "Prior range high", color = color.blue)
Each strategy.exit call reserves one unit for its bracket; the profit and loss arguments are tick distances relative to the entry. Create both brackets with the entry rather than resubmitting the first target after a partial exit. Use a symbol that supports the specified quantity. TradingView's strategy documentation explains order reservation, bracket management and the broker emulator. Default historical market entry typically fills on the next available tick, usually the next bar open.
Execution assumptions and testing
Compare a single two-unit target with the split version using the same initial risk, commissions and slippage. Record first-target hit rate, second-target hit rate, average trade, drawdown and net return. Examine bars touching both a stop and target; enable Bar Magnifier where available and compare results with default OHLC assumptions. Live brokerage or alert-based execution requires independent position reconciliation, partial-fill handling, order cancellation and risk controls. Emulator fills differ from live fills. This educational code has not been compiled or backtested here. No target or stop guarantees a particular return or fill price.
For custom execution and strategy rules, see Custom TradingView strategy Development Services.