Pine Script v5 · Strategy
Break even stop loss (- of instrument price)
A Pine Script v5 strategy built on Crossover or SMA (close, 14, close, 28) and Crossunder or SMA (close, 14, close, 28). It has 3 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss. Each trade is one contract and pays no commission. 1 setting; defaults include Trail Long Loss (%) 3.0.
Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.
- Does Break even stop loss (- of instrument price) repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 6 of 6 trades.
- How did Break even stop loss (- of instrument price) do on BTCUSDT 1D with default settings?
- +0.20%
- From 26 Jan 2024 to 21 Oct 2026, over 21 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Break even stop loss (- of instrument price) run in Pine Script v6?
- No
- The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 21 before, 12 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does Break even stop loss (- of instrument price) use a stop loss?
- Yes
- strategy.exit sets a stop on line 35.
- Does Break even stop loss (- of instrument price) run in Zeal Terminal?
- Yes
- It compiles in 16 ms and runs 1,000 bars in 20 ms, in the browser.
BTCUSDT · 1D · default settings
- Long Trail Stop
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +0.20%
- $2,006.79
- Buy and hold
- +102.5%
- same period
- Closed trades
- 21
- 3 won · 10 lost
- Profitable
- 14.3%
- of closed trades
- Profit factor
- 1.07
- gross profit ÷ gross loss
- Max drawdown
- 1.71%
- −$17,365.00
One run with the author's default settings, $1,000,000 starting capital, commission as the script sets it. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Trail Long Loss (%) | 3.0 | float · step 0.1 | longStopPrice stopValue |
What it calculates
- Crossover / SMAta.sma(close, 14), ta.sma(close, 28)
longCondition · line 8 - Crossunder / SMAta.sma(close, 14), ta.sma(close, 28)
shortCondition · line 30
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | (longCondition) | On | 29 |
| Close Long | (shortCondition) | On | 32 |
| Exit Stop Loss stop | (strategy.position_size > 0) | On | 35 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
No
No repainting patterns in the source, and the live replay matched history.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +0.2% | +102.5% | 21 | 14% | 1.07 | 1.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −0.7% | +5.5% | 22 | 23% | 0.71 | 1.5% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.2% | +9.8% | 19 | 26% | 2.27 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.0% | +8.4% | 23 | 17% | 0.91 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.0% | +16.7% | 16 | 25% | 2.28 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.0% | +21.5% | 20 | 20% | 1.46 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.0% | +148.3% | 18 | 17% | 2.62 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.0% | +17.1% | 21 | 29% | 0.70 | 0.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 6 | 17% | $419.48 |
| Sideways market | 11 | 18% | $7,160.22 |
| Falling market | 4 | 0% | −$5,572.91 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
2.6%
The 95th percentile of the worst drawdown when the same 21 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 1.1% to 2.6%; the tick is what actually happened, 1.6%. Order luck alone moves it this much.
All 21 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 6 Apr 2024 67,820.60 | 10 Apr 2024 67,820.60 | 4 | $0.00 |
| long | 19 May 2024 66,915.20 | 23 May 2024 66,915.20 | 4 | $0.00 |
| long | 21 Jul 2024 67,140.00 | 24 Jul 2024 65,125.80 | 3 | −$2,014.20 |
| long | 27 Aug 2024 62,834.00 | 28 Aug 2024 59,415.00 | 1 | −$3,419.00 |
| long | 22 Sep 2024 63,349.00 | 30 Sep 2024 63,349.00 | 8 | $0.00 |
| long | 18 Oct 2024 67,421.80 | 23 Oct 2024 65,399.10 | 5 | −$2,022.66 |
| long | 15 Jan 2025 96,560.90 | 2 Feb 2025 96,560.90 | 18 | $0.00 |
| long | 31 Mar 2025 82,390.00 | 2 Apr 2025 82,390.00 | 2 | $0.00 |
| long | 22 Apr 2025 87,516.20 | 9 Jun 2025 105,734.00 | 48 | $18,217.80 |
| long | 20 Jun 2025 104,659.00 | 21 Jun 2025 101,519.00 | 1 | −$3,139.76 |
| long | 5 Jul 2025 107,984.00 | 6 Aug 2025 114,130.00 | 32 | $6,145.50 |
| long | 17 Aug 2025 117,381.00 | 19 Aug 2025 113,859.00 | 2 | −$3,521.42 |
| long | 15 Sep 2025 115,268.00 | 22 Sep 2025 111,810.00 | 7 | −$3,458.05 |
| long | 6 Oct 2025 123,482.00 | 9 Oct 2025 119,778.00 | 3 | −$3,704.47 |
| long | 11 Dec 2025 92,015.40 | 14 Dec 2025 89,254.90 | 3 | −$2,760.47 |
| long | 7 Jan 2026 93,748.00 | 8 Jan 2026 90,935.50 | 1 | −$2,812.44 |
| long | 10 Mar 2026 68,432.20 | 22 Mar 2026 68,432.20 | 12 | $0.00 |
| long | 14 Apr 2026 74,418.00 | 19 Apr 2026 74,418.00 | 5 | $0.00 |
| long | 14 Jul 2026 62,334.50 | 1 Aug 2026 62,334.50 | 18 | $0.00 |
| long | 20 Aug 2026 69,334.80 | 18 Sep 2026 76,417.00 | 29 | $7,082.23 |
| long | 23 Sep 2026 86,208.60 | 24 Sep 2026 83,622.30 | 1 | −$2,586.26 |
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Break even stop loss (- of instrument price) this page | — | v5 strategy | +0.2% | 21 | 1.7% |
| Follow the Crypto Shorts by xtradernet | sma | v4 strategy | No trades on this market | ||
| buy down and sell high trend 200 sma and ma cross by willi130503 | sma | v4 strategy | No trades on this market | ||
| Mayer Multiple Strategy by xtradernet | sma | v4 strategy | No trades on this market | ||
| Moving Average Cross Strategy early Closing by Geduldtrader | sma | v4 strategy | +73.8% | 20 | 151.5% |
| MFI Simple Strategy by OztheWoz | sma | v5 strategy | −0.2% | 28 | 3.2% |
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- No v6-only features. v6 is not needed to run this script.
Clean v5
VerifiedNothing to change.
Does it run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 21 before, 12 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// based on https://kodify.net/tradingview/orders/percentage-trail/-//@version=5+//@version=6strategy("Break even stop loss (% of instrument price)", overlay=true)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 16 ms | Yes 1,000 bars in 20 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © osmaras// based on https://kodify.net/tradingview/orders/percentage-trail///@version=5strategy("Break even stop loss (% of instrument price)", overlay=true)// Configure trail stop level with input options (optional)longTrailPerc = input.float(defval=3.0,step=0.1,title="Trail Long Loss (%)")* 0.01 longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))// Determine trail stop loss priceslongStopPrice = 0.0lastEntryPrice = strategy.opentrades.entry_price(strategy.opentrades - 1)longStopPrice := if (strategy.position_size > 0 and close > (lastEntryPrice * (1 + longTrailPerc))) stopValue = lastEntryPrice math.max(stopValue, longStopPrice[1])else longStopPrice := if (strategy.position_size > 0) stopValue = lastEntryPrice * (1 - longTrailPerc) math.max(stopValue, longStopPrice[1]) else 0// Plot stop loss values for confirmationplot(series=(strategy.position_size > 0) ? longStopPrice : na, color=color.fuchsia, style=plot.style_cross, linewidth=2, title="Long Trail Stop")// set strategy only longstrategy.risk.allow_entry_in(strategy.direction.long)// Submit entry ordersif (longCondition) strategy.entry("Long", strategy.long)shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))if (shortCondition) strategy.close("Long")// Submit exit orders for trail stop loss priceif (strategy.position_size > 0) strategy.exit(id="Stop Loss", stop=longStopPrice)