Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (1)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,002,010$2,025,273Equity from $1,000,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
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.

SettingDefaultType and rangeFeeds
Trail Long Loss (%)3.0float · step 0.1longStopPrice 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.

closecloseprice datalongTrailPercTrail Long Loss (%)setting · 3.0longConditionCrossover / SMA→ longConditionshortConditionCrossunder / SMA→ shortConditionlastEntryPricelastEntryPricevaluestopValuestopValuevaluelongStopPricelongStopPriceconditionentry:LongOpen Longstrategy.entryclose:LongClose Longstrategy.closeexit:Stop Lossexit Stop Lossstrategy.exitplot:22Long Trail Stopplot

Order rules

OrderFires whenBy defaultLine
Open Long long(longCondition)On29
Close Long(shortCondition)On32
Exit Stop Loss stop(strategy.position_size > 0)On35

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.

6/6trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+0.2%+102.5%2114%1.071.7%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−0.7%+5.5%2223%0.711.5%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.2%+9.8%1926%2.270.1%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.0%+8.4%2317%0.910.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.0%+16.7%1625%2.280.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%2020%1.460.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.0%+148.3%1817%2.620.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−0.0%+17.1%2129%0.700.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 barsTradesWonP&L
Rising market617%$419.48
Sideways market1118%$7,160.22
Falling market40%−$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.

0%3%
All 21 trades
SideEntryExitBarsP&L
long6 Apr 2024 67,820.6010 Apr 2024 67,820.604$0.00
long19 May 2024 66,915.2023 May 2024 66,915.204$0.00
long21 Jul 2024 67,140.0024 Jul 2024 65,125.803−$2,014.20
long27 Aug 2024 62,834.0028 Aug 2024 59,415.001−$3,419.00
long22 Sep 2024 63,349.0030 Sep 2024 63,349.008$0.00
long18 Oct 2024 67,421.8023 Oct 2024 65,399.105−$2,022.66
long15 Jan 2025 96,560.902 Feb 2025 96,560.9018$0.00
long31 Mar 2025 82,390.002 Apr 2025 82,390.002$0.00
long22 Apr 2025 87,516.209 Jun 2025 105,734.0048$18,217.80
long20 Jun 2025 104,659.0021 Jun 2025 101,519.001−$3,139.76
long5 Jul 2025 107,984.006 Aug 2025 114,130.0032$6,145.50
long17 Aug 2025 117,381.0019 Aug 2025 113,859.002−$3,521.42
long15 Sep 2025 115,268.0022 Sep 2025 111,810.007−$3,458.05
long6 Oct 2025 123,482.009 Oct 2025 119,778.003−$3,704.47
long11 Dec 2025 92,015.4014 Dec 2025 89,254.903−$2,760.47
long7 Jan 2026 93,748.008 Jan 2026 90,935.501−$2,812.44
long10 Mar 2026 68,432.2022 Mar 2026 68,432.2012$0.00
long14 Apr 2026 74,418.0019 Apr 2026 74,418.005$0.00
long14 Jul 2026 62,334.501 Aug 2026 62,334.5018$0.00
long20 Aug 2026 69,334.8018 Sep 2026 76,417.0029$7,082.23
long23 Sep 2026 86,208.6024 Sep 2026 83,622.301−$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.

ScriptSharesTypeNetTradesMax drawdown
Break even stop loss (- of instrument price) this page—v5 strategy+0.2%211.7%
Follow the Crypto Shorts by xtradernetsmav4 strategyNo trades on this market
buy down and sell high trend 200 sma and ma cross by willi130503smav4 strategyNo trades on this market
Mayer Multiple Strategy by xtradernetsmav4 strategyNo trades on this market
Moving Average Cross Strategy early Closing by Geduldtradersmav4 strategy+73.8%20151.5%
MFI Simple Strategy by OztheWozsmav5 strategy−0.2%283.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

Verified

Nothing 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

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 16 msYes 1,000 bars in 20 msNot measured
PineTSNot testedNot testedNot 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)