Specify a state change that stays armed
Use this explicit long-trade rule as a test specification: buy 10 shares at an actual $100 fill, begin with a $95 stop, and arm price breakeven after a confirmed close at or above $105. Initial price risk is $5 per share, so the trigger is +1R and planned gross risk is $50. This is a hypothetical rule, not a recommended threshold.
- Choose a confirmed-close trigger or an intrabar touch trigger in advance. A high of $105 with a close of $103 does not arm this close-based example.
- Freeze initial risk when the trade opens. Recalculating R from the revised stop makes risk zero at price breakeven and destroys the original comparison.
- For a short filled at $100 with a $105 initial stop, the mirrored +1R close trigger is $95 or lower; price breakeven is still $100.
- This rule retains the entire position until exit. It does not require a partial take-profit. If scaling in or out is allowed, define how average entry, remaining quantity and previously realized P/L change the rule.
| State | Condition | Protective stop |
|---|
| Open, unarmed | Entry filled; trigger not confirmed | $95 |
| Armed | Position survives the bar and closes at or above $105 | Revise to $100 for the next bar |
| Still armed | Price falls below $105 without an exit | Keep $100; do not restore $95 |
| Closed | Stop or another exit fills | Reset state before the next trade |
Calculate what covering costs would require
For a fixed-size share position, let E be the actual entry fill, Q the positive share count, C total entry-plus-exit fees in dollars, and d assumed adverse exit slippage in dollars per share. A long stop intended to produce zero net P/L is B = E + C / Q + d. For a short it is B = E - C / Q - d. These formulas assume the stop fills exactly d away from B and exclude financing, taxes and currency conversion.
- With a $0.01 tick, $100.22 is valid. With a hypothetical $0.05 tick, round a long threshold up to $100.25; round a short threshold down. Rounding to the nearest tick can leave costs uncovered.
- The mirrored short example uses a $99.78 stop and a $99.80 assumed buyback fill: (100 - 99.80) × 10 - 2 = $0.
- Use actual entry fills so entry slippage is not counted twice. Percentage commissions depend on turnover; compute those fees from the assumed fills instead of treating $2 as universal.
- For linear contracts, replace Q in the cost adjustment with Q × point value, using a common currency. The share formula does not directly price inverse contracts or replace broker margin rules.
- Reject zero quantity, an invalid tick size, or an unknown fee model. If the desired long stop is already above the current market when the update is sent, it cannot provide the intended future pullback protection.
| Assumption or result | Long example |
|---|
| Actual entry and quantity | $100 × 10 shares |
| Total fees and adverse exit slippage | $2 per round trip; $0.02 per share |
| Stop at entry | $100 trigger; assumed $99.98 fill |
| Net P/L at that fill | (99.98 - 100) × 10 - 2 = -$2.20 |
| Stop intended to cover costs | 100 + 2 / 10 + 0.02 = $100.22 |
| Net P/L at assumed $100.20 fill | (100.20 - 100) × 10 - 2 = $0 |
A trigger and a reversal inside one bar need an order sequence
Suppose the unarmed long exists before a bar with open $101, high $106, low $99 and close $105.50. Its active stop is $95. Under the close-based rule above, the position survives, arms at the close, and uses $100 from the next bar. The earlier $99 low cannot retrospectively fill an order that did not exist yet.
- An intrabar-touch rule answers a different question. On the hypothetical path 101 → 106 → 99 → 105.50, an immediately updated $100 stop could exit on the decline. On 101 → 99 → 106 → 105.50, the early low occurred before activation, so it cannot cause that exit.
- TradingView uses historical price-path assumptions unless finer bar data is available. Record both calculation settings and historical bar detail. More detailed fills do not make an order active before the script creates or modifies it.
- Checking a bar high at its close does not prove the script moved the stop at that high. Inspect the trigger timestamp, order update and fill separately.
- If the initial $95 stop fills earlier in the bar, a later $105 close cannot reopen that trade or arm its breakeven rule. Evaluate existing exits before changing the state of a surviving position.
Compare all three exits on one fixed sample
The following three independent paths are invented arithmetic examples, not historical results. Each starts with 10 shares already filled at $100 and a $95 stop active. There are no gaps, re-entries, partial exits or targets. All variants receive the same entry and terminal deadline on each path. A survivor is assumed liquidated at that deadline price; this is an explicit fill assumption, not the default timing of a Pine market order.
- All paths start with bar 1 open/high/low/close = 100/105/100/105. At its close the breakeven and trailing variants both set $100 for bar 2.
- Path A: bar 2 is 105/110/105/110; bar 3 is 110/110/104/104. The trail rises to $105 after bar 2, then exits there. Fixed and breakeven versions survive to the $104 deadline.
- Path B: bar 2 is 105/106/99/106, with the $106 deadline at its close. Both adjusted stops exit at $100 during the pullback. The fixed stop survives the $99 low and exits at $106.
- Path C: bar 2 is 105/105/94/94. Both adjusted stops exit at $100; the fixed stop exits at $95. No surviving position reaches the deadline.
| Variant | Activation and updates |
|---|
| Do not move the stop | Keep $95 until exit or the common deadline |
| Price breakeven | After a surviving close ≥ $105, set $100 for the next bar and retain it |
| Close-based trailing exit | Activate at the same close ≥ $105; next stop = max(previous stop, highest close since entry - $5) |
Read the paired results before choosing a rule
Gross P/L is (exit - 100) × 10. For the net comparison, deduct the same hypothetical $2 round-trip fee plus $0.02 adverse exit slippage per share, or $2.20 per trade. The entry remains the actual $100 fill. These price-breakeven results do not use the separate $100.22 cost-covering stop.
- Breakeven saves $50 relative to the fixed stop in C but gives up $60 in B. A smaller loss on one reversal does not establish higher expectancy.
- The trailing rule retains $10 more than breakeven in A. It still suffers the same early exit in B because both stops were $100 during that bar.
- The three chosen paths do not estimate how often these outcomes occur. Predefine a historical sample and repeat the comparison after costs on a separate holdout period.
- Keep entry timestamps, actual fills, quantity, costs and deadlines matched. In a complete strategy, different exit times can allow or block later entries; report that effect separately from the paired exit test.
| Same entry sample | Fixed: gross / net | Breakeven: gross / net | Trailing: gross / net |
|---|
| A: rise then retreat | +$40 / +$37.80 | +$40 / +$37.80 | +$50 / +$47.80 |
| B: pullback then recovery | +$60 / +$57.80 | $0 / -$2.20 | $0 / -$2.20 |
| C: reversal through entry | -$50 / -$52.20 | $0 / -$2.20 | $0 / -$2.20 |
| Total, three trades | +$50 / +$43.40 | +$40 / +$33.40 | +$50 / +$43.40 |
A gap can defeat both meanings of breakeven
Assume the long has armed its stop and the next bar opens at $98 after a $105 close. TradingView documents filling active price-based orders crossed in an interbar gap at the new open. Both a $100 stop and a $100.22 stop would therefore fill at $98 before extra slippage in this example.
- With the same $0.02 adverse exit slippage and $2 fees, net P/L = (97.98 - 100) × 10 - 2 = -$22.20. Raising the trigger to cover estimated costs does not insure the fill.
- Investor.gov explains that a stop price is a trigger, not a guaranteed execution price. A stop-limit order controls its acceptable execution price but can remain unfilled.
- Verify the broker trigger convention, eligible trading session and order type separately. A simulated exit is not a live broker order.
Turn the specification into a checkable strategy and journal entry
Give Pine Script AI Coding Agent the entry rule and the state table, then ask it to create the three exit variants with identical position units. Review the output and compare individual fills with the arithmetic above before interpreting aggregate performance. TradingView documents that strategy.exit uses stop for an absolute price and loss for a distance in ticks; confusing those units changes the trade.
- Keep the initial stop, trigger method, armed state, revised stop and reset rule explicit. The official TradingView breakeven example updates a persistent stop value and sends the updated exit order each bar.
- In Trading Journal, preserve the initial stop and planned risk. Use plan notes for the activation rule and review notes for its trigger time, intended stop, actual fill, fees and net outcome. Label simulated trades clearly.
- Do not overwrite original risk with zero merely because the stop moved to entry. Retain it as the denominator when comparing net R across exit variants.
- Pineify supports writing scripts and recording trades. This workflow does not automatically place broker orders, guarantee execution or determine broker margin requirements.