Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Multiple -- profit exits example

A Pine Script v4 strategy built on Crossover or SMA (close, 14, close, 28) and Crossunder or SMA (close, 14, close, 28). It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is 100 contracts and pays no commission. It has no settings.

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 Multiple -- profit exits example repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 48 of 48 trades.
How did Multiple -- profit exits example do on BTCUSDT 1D with default settings?
−457.31%
From 26 Jan 2024 to 21 Oct 2026, over 172 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Multiple -- profit exits example be converted to Pine Script v5?
Yes
The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
Does Multiple -- profit exits example use a stop loss?
Yes
strategy.exit sets a stop on line 14, 15, 16, 17.
Does Multiple -- profit exits example run in Zeal Terminal?
Yes
It compiles in 14 ms and runs 1,000 bars in 37 ms, in the browser.

BTCUSDT · 1D · default settings

  • open profit % upper bound
  • open profit % lower bound
  • 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 (0)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctopen profit % upper bound$-357,240$202,527Equity from $100,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
−457.31%
−$457,309.00
Buy and hold
+102.5%
same period
Closed trades
172
83 won · 89 lost
Profitable
48.3%
of closed trades
Profit factor
0.92
gross profit ÷ gross loss
Max drawdown
197.08%
−$2,227,670.00

One run with the author's default settings, $100,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.

Upgrade and export

Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.

  • Upgrading to v5 renames crossover → ta.crossover, sma → ta.sma, crossunder → ta.crossunder, round → math.round.

v4 → v5

VerifiedDownload the v5 script

Same 172 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 3: //@version=4 → //@version=5
  • Line 5: crossover → ta.crossover
  • Line 5: sma → ta.sma
  • Line 5: sma → ta.sma
  • Line 8: crossunder → ta.crossunder
  • Line 8: sma → ta.sma
  • Line 8: sma → ta.sma
  • Line 12: round → math.round
⋯// © adolgov-//@version=4+//@version=5strategy("Multiple %% profit exits example", overlay=false, default_qty_value = 100)-longCondition = crossover(sma(close, 14), sma(close, 28))+longCondition = ta.crossover(ta.sma(close, 14), ta.sma(close, 28))if (longCondition)    strategy.entry("My Long Entry Id", strategy.long)-shortCondition = crossunder(sma(close, 14), sma(close, 28))+shortCondition = ta.crossunder(ta.sma(close, 14), ta.sma(close, 28))if (shortCondition)⋯percentAsPoints(pcnt) =>-    strategy.position_size != 0 ? round(pcnt / 100 * strategy.position_avg_price / syminfo.mintick) : float(na)+    strategy.position_size != 0 ? math.round(pcnt / 100 * strategy.position_avg_price / syminfo.mintick) : float(na)lossPnt = percentAsPoints(2)⋯

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: 172 before, 79 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.

⋯// © adolgov-//@version=5+//@version=6strategy("Multiple %% profit exits example", overlay=false, default_qty_value = 100)⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

The script declares no settings.

What it calculates

  • Crossover / SMA (crossover, ta.crossover in v5)sma(close, 14), sma(close, 28)longCondition · line 5
  • Crossunder / SMA (crossunder, ta.crossunder in v5)sma(close, 14), sma(close, 28)shortCondition · line 8

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 datahighhighprice datalowlowprice datalongConditionCrossover / SMA→ longConditionshortConditionCrossunder / SMA→ shortConditionposSignposSignvalueentry:My Long Entry IdOpen My Long Entry Idstrategy.entryentry:My Short Entry IdOpen My Short Entry Idstrategy.entryexit:x1exit x1strategy.exitexit:x2exit x2strategy.exitexit:x3exit x3strategy.exitexit:x4exit x4strategy.exitplot:21open profit % upper bou…plotplot:22open profit % lower bou…plotfill:23Fillfill

Order rules

OrderFires whenBy defaultLine
Open My Long Entry Id long(longCondition)On7
Open My Short Entry Id short(shortCondition)On10
Exit x1 stop and limitevery barOn14
Exit x2 stop and limitevery barOn15
Exit x3 stop and limitevery barOn16
Exit x4 stop and limitevery barOn17

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.

48/48trades 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−457.3%+102.5%17248%0.92197.1%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−1,428.4%+5.5%15836%0.591,629.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+9.3%+9.8%15039%1.0555.9%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−31.8%+8.4%16944%0.7250.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+1.3%+16.7%13253%1.164.3%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+1.1%+21.5%15553%1.341.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−4.9%+148.3%14841%0.8413.3%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−6.7%+17.1%16142%0.7812.6%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 market6052%−$297,745.00
Sideways market7250%−$314,862.00
Falling market4040%$155,298.00

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

99.3%

The 95th percentile of the worst drawdown when the same 172 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 87.1% to 99.3%; the tick is what actually happened, 99.5%. Order luck alone moves it this much.

0%114%
The first 150 of 172 trades
SideEntryExitBarsP&L
short29 Mar 2024 70,780.6030 Mar 2024 69,850.501$23,251.80
short29 Mar 2024 70,780.601 Apr 2024 69,365.003$35,390.30
short29 Mar 2024 70,780.601 Apr 2024 68,657.203$53,085.50
short29 Mar 2024 70,780.602 Apr 2024 67,949.404$70,780.50
long6 Apr 2024 67,820.607 Apr 2024 68,896.001$26,884.20
long6 Apr 2024 67,820.607 Apr 2024 69,177.001$33,910.20
long6 Apr 2024 67,820.607 Apr 2024 69,855.301$50,865.50
long6 Apr 2024 67,820.608 Apr 2024 70,533.502$67,820.80
short16 Apr 2024 63,420.0017 Apr 2024 62,785.801$15,855.00
short16 Apr 2024 63,420.0017 Apr 2024 62,151.601$31,710.00
short16 Apr 2024 63,420.0017 Apr 2024 61,517.401$47,565.00
short16 Apr 2024 63,420.0017 Apr 2024 60,883.201$63,420.00
long19 May 2024 66,915.2020 May 2024 67,584.401$16,728.80
long19 May 2024 66,915.2020 May 2024 68,253.501$33,457.50
long19 May 2024 66,915.2020 May 2024 68,922.701$50,186.50
long19 May 2024 66,915.2020 May 2024 69,591.801$66,915.30
short17 Jun 2024 66,676.9018 Jun 2024 66,010.101$16,669.30
short17 Jun 2024 66,676.9018 Jun 2024 65,343.301$33,338.50
short17 Jun 2024 66,676.9018 Jun 2024 64,676.601$50,007.70
short17 Jun 2024 66,676.9021 Jun 2024 64,009.804$66,676.80
long21 Jul 2024 67,140.0022 Jul 2024 68,165.401$25,634.50
long21 Jul 2024 67,140.0023 Jul 2024 65,797.202−$33,570.00
long21 Jul 2024 67,140.0023 Jul 2024 65,797.202−$33,570.00
long21 Jul 2024 67,140.0023 Jul 2024 65,797.202−$33,570.00
short8 Aug 2024 55,133.809 Aug 2024 61,686.001−$163,806.00
short8 Aug 2024 55,133.809 Aug 2024 61,686.001−$163,806.00
short8 Aug 2024 55,133.809 Aug 2024 61,686.001−$163,806.00
short8 Aug 2024 55,133.809 Aug 2024 61,686.001−$163,806.00
long27 Aug 2024 62,834.0028 Aug 2024 59,415.001−$85,475.00
long27 Aug 2024 62,834.0028 Aug 2024 59,415.001−$85,475.00
long27 Aug 2024 62,834.0028 Aug 2024 59,415.001−$85,475.00
long27 Aug 2024 62,834.0028 Aug 2024 59,415.001−$85,475.00
short7 Sep 2024 53,963.008 Sep 2024 55,042.201−$26,981.50
short7 Sep 2024 53,963.008 Sep 2024 55,042.201−$26,981.50
short7 Sep 2024 53,963.008 Sep 2024 55,042.201−$26,981.50
short7 Sep 2024 53,963.008 Sep 2024 55,042.201−$26,981.50
long22 Sep 2024 63,349.0023 Sep 2024 63,982.501$15,837.20
long22 Sep 2024 63,349.0023 Sep 2024 64,615.901$31,674.50
long22 Sep 2024 63,349.0026 Sep 2024 65,249.404$47,511.80
long22 Sep 2024 63,349.0027 Sep 2024 65,882.905$63,349.00
short12 Oct 2024 62,540.0014 Oct 2024 63,790.802−$31,270.00
short12 Oct 2024 62,540.0014 Oct 2024 63,790.802−$31,270.00
short12 Oct 2024 62,540.0014 Oct 2024 63,790.802−$31,270.00
short12 Oct 2024 62,540.0014 Oct 2024 63,790.802−$31,270.00
long18 Oct 2024 67,421.8019 Oct 2024 68,428.001$25,155.30
long18 Oct 2024 67,421.8020 Oct 2024 68,770.202$33,711.00
long18 Oct 2024 67,421.8021 Oct 2024 69,444.403$50,566.20
long18 Oct 2024 67,421.8023 Oct 2024 66,073.305−$33,711.00
short30 Dec 2024 93,738.2031 Dec 2024 92,792.101$23,653.50
short30 Dec 2024 93,738.2031 Dec 2024 95,612.901−$46,869.00
short30 Dec 2024 93,738.2031 Dec 2024 95,612.901−$46,869.00
short30 Dec 2024 93,738.2031 Dec 2024 95,612.901−$46,869.00
long15 Jan 2025 96,560.9016 Jan 2025 100,497.001$98,412.50
long15 Jan 2025 96,560.9016 Jan 2025 100,497.001$98,412.50
long15 Jan 2025 96,560.9016 Jan 2025 100,497.001$98,412.50
long15 Jan 2025 96,560.9016 Jan 2025 100,497.001$98,412.50
short8 Feb 2025 96,506.809 Feb 2025 95,541.701$24,126.80
short8 Feb 2025 96,506.8011 Feb 2025 98,436.903−$48,253.50
short8 Feb 2025 96,506.8011 Feb 2025 98,436.903−$48,253.50
short8 Feb 2025 96,506.8011 Feb 2025 98,436.903−$48,253.50
long31 Mar 2025 82,390.001 Apr 2025 83,213.901$20,597.50
long31 Mar 2025 82,390.001 Apr 2025 84,037.801$41,195.00
long31 Mar 2025 82,390.001 Apr 2025 84,861.701$61,792.50
long31 Mar 2025 82,390.002 Apr 2025 85,685.602$82,390.00
short8 Apr 2025 79,163.209 Apr 2025 76,322.401$71,020.50
short8 Apr 2025 79,163.209 Apr 2025 76,322.401$71,020.50
short8 Apr 2025 79,163.209 Apr 2025 76,322.401$71,020.50
short8 Apr 2025 79,163.209 Apr 2025 75,996.701$79,163.20
long22 Apr 2025 87,516.2023 Apr 2025 93,443.001$148,169.00
long22 Apr 2025 87,516.2023 Apr 2025 93,443.001$148,169.00
long22 Apr 2025 87,516.2023 Apr 2025 93,443.001$148,169.00
long22 Apr 2025 87,516.2023 Apr 2025 93,443.001$148,169.00
short9 Jun 2025 105,734.0010 Jun 2025 110,263.001−$113,225.00
short9 Jun 2025 105,734.0010 Jun 2025 110,263.001−$113,225.00
short9 Jun 2025 105,734.0010 Jun 2025 110,263.001−$113,225.00
short9 Jun 2025 105,734.0010 Jun 2025 110,263.001−$113,225.00
long20 Jun 2025 104,659.0021 Jun 2025 102,565.001−$52,329.20
long20 Jun 2025 104,659.0021 Jun 2025 102,565.001−$52,329.20
long20 Jun 2025 104,659.0021 Jun 2025 102,565.001−$52,329.20
long20 Jun 2025 104,659.0021 Jun 2025 102,565.001−$52,329.20
short24 Jun 2025 105,334.0025 Jun 2025 107,441.001−$52,667.00
short24 Jun 2025 105,334.0025 Jun 2025 107,441.001−$52,667.00
short24 Jun 2025 105,334.0025 Jun 2025 107,441.001−$52,667.00
short24 Jun 2025 105,334.0025 Jun 2025 107,441.001−$52,667.00
long5 Jul 2025 107,984.006 Jul 2025 109,064.001$26,996.00
long5 Jul 2025 107,984.009 Jul 2025 110,144.004$53,992.30
long5 Jul 2025 107,984.009 Jul 2025 111,224.004$80,988.20
long5 Jul 2025 107,984.0010 Jul 2025 112,304.005$107,984.00
short6 Aug 2025 114,130.007 Aug 2025 116,412.001−$57,065.00
short6 Aug 2025 114,130.007 Aug 2025 116,412.001−$57,065.00
short6 Aug 2025 114,130.007 Aug 2025 116,412.001−$57,065.00
short6 Aug 2025 114,130.007 Aug 2025 116,412.001−$57,065.00
long17 Aug 2025 117,381.0018 Aug 2025 115,033.001−$58,690.30
long17 Aug 2025 117,381.0018 Aug 2025 115,033.001−$58,690.30
long17 Aug 2025 117,381.0018 Aug 2025 115,033.001−$58,690.30
long17 Aug 2025 117,381.0018 Aug 2025 115,033.001−$58,690.30
short27 Aug 2025 111,763.0029 Aug 2025 110,646.002$27,940.80
short27 Aug 2025 111,763.0029 Aug 2025 109,528.002$55,881.50
short27 Aug 2025 111,763.0029 Aug 2025 108,410.002$83,822.50
short27 Aug 2025 111,763.001 Sep 2025 107,293.005$111,763.00
long15 Sep 2025 115,268.0016 Sep 2025 116,421.001$28,817.00
long15 Sep 2025 115,268.0018 Sep 2025 117,573.003$57,634.00
long15 Sep 2025 115,268.0022 Sep 2025 112,963.007−$57,634.00
long15 Sep 2025 115,268.0022 Sep 2025 112,963.007−$57,634.00
short1 Oct 2025 114,049.002 Oct 2025 118,595.001−$113,651.00
short1 Oct 2025 114,049.002 Oct 2025 118,595.001−$113,651.00
short1 Oct 2025 114,049.002 Oct 2025 118,595.001−$113,651.00
short1 Oct 2025 114,049.002 Oct 2025 118,595.001−$113,651.00
long6 Oct 2025 123,482.007 Oct 2025 124,717.001$30,870.50
long6 Oct 2025 123,482.007 Oct 2025 121,013.001−$61,741.30
long6 Oct 2025 123,482.007 Oct 2025 121,013.001−$61,741.30
long6 Oct 2025 123,482.007 Oct 2025 121,013.001−$61,741.30
short20 Oct 2025 108,643.0021 Oct 2025 107,556.001$27,160.80
short20 Oct 2025 108,643.0021 Oct 2025 110,816.001−$54,321.50
short20 Oct 2025 108,643.0021 Oct 2025 110,816.001−$54,321.50
short20 Oct 2025 108,643.0021 Oct 2025 110,816.001−$54,321.50
long11 Dec 2025 92,015.4012 Dec 2025 90,175.101−$46,007.70
long11 Dec 2025 92,015.4012 Dec 2025 90,175.101−$46,007.70
long11 Dec 2025 92,015.4012 Dec 2025 90,175.101−$46,007.70
long11 Dec 2025 92,015.4012 Dec 2025 90,175.101−$46,007.70
short20 Dec 2025 88,136.9022 Dec 2025 89,899.702−$44,068.50
short20 Dec 2025 88,136.9022 Dec 2025 89,899.702−$44,068.50
short20 Dec 2025 88,136.9022 Dec 2025 89,899.702−$44,068.50
short20 Dec 2025 88,136.9022 Dec 2025 89,899.702−$44,068.50
long7 Jan 2026 93,748.008 Jan 2026 91,364.201−$59,595.20
long7 Jan 2026 93,748.008 Jan 2026 91,364.201−$59,595.20
long7 Jan 2026 93,748.008 Jan 2026 91,364.201−$59,595.20
long7 Jan 2026 93,748.008 Jan 2026 91,364.201−$59,595.20
short29 Jan 2026 89,300.0030 Jan 2026 84,650.201$116,246.00
short29 Jan 2026 89,300.0030 Jan 2026 84,650.201$116,246.00
short29 Jan 2026 89,300.0030 Jan 2026 84,650.201$116,246.00
short29 Jan 2026 89,300.0030 Jan 2026 84,650.201$116,246.00
long10 Mar 2026 68,432.2011 Mar 2026 69,948.601$37,912.00
long10 Mar 2026 68,432.2011 Mar 2026 69,948.601$37,912.00
long10 Mar 2026 68,432.2011 Mar 2026 70,485.101$51,324.00
long10 Mar 2026 68,432.2011 Mar 2026 71,169.401$68,432.20
short31 Mar 2026 66,797.401 Apr 2026 68,284.501−$37,177.80
short31 Mar 2026 66,797.401 Apr 2026 68,284.501−$37,177.80
short31 Mar 2026 66,797.401 Apr 2026 68,284.501−$37,177.80
short31 Mar 2026 66,797.401 Apr 2026 68,284.501−$37,177.80
long14 Apr 2026 74,418.0015 Apr 2026 75,162.201$18,604.50
long14 Apr 2026 74,418.0017 Apr 2026 75,906.403$37,209.00
long14 Apr 2026 74,418.0017 Apr 2026 76,650.503$55,813.50
long14 Apr 2026 74,418.0017 Apr 2026 77,394.703$74,418.00
short24 May 2026 76,752.0026 May 2026 75,984.502$19,188.00
short24 May 2026 76,752.0027 May 2026 75,217.003$38,376.00
short24 May 2026 76,752.0027 May 2026 74,449.403$57,564.00
short24 May 2026 76,752.0028 May 2026 73,681.904$76,752.00
long14 Jul 2026 62,334.5015 Jul 2026 65,044.001$67,736.80
long14 Jul 2026 62,334.5015 Jul 2026 65,044.001$67,736.80

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
Multiple -- profit exits example this page—v4 strategy−457.3%172197.1%
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%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 14 msYes 1,000 bars in 37 msNot measured
PineTSNo v5 and v6 only—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. PineTS runs Pine Script v5 and v6 only.

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/// © adolgov//@version=4strategy("Multiple %% profit exits example", overlay=false, default_qty_value = 100)longCondition = crossover(sma(close, 14), sma(close, 28))if (longCondition)    strategy.entry("My Long Entry Id", strategy.long)shortCondition = crossunder(sma(close, 14), sma(close, 28))if (shortCondition)    strategy.entry("My Short Entry Id", strategy.short)percentAsPoints(pcnt) =>    strategy.position_size != 0 ? round(pcnt / 100 * strategy.position_avg_price / syminfo.mintick) : float(na)lossPnt = percentAsPoints(2)strategy.exit("x1", qty_percent = 25, profit = percentAsPoints(1), loss = lossPnt)strategy.exit("x2", qty_percent = 25, profit = percentAsPoints(2), loss = lossPnt)strategy.exit("x3", qty_percent = 25, profit = percentAsPoints(3), loss = lossPnt)strategy.exit("x4", profit = percentAsPoints(4), loss = lossPnt)profitPercent(price) =>    posSign = strategy.position_size > 0 ? 1 : strategy.position_size < 0 ? -1 : 0    (price - strategy.position_avg_price) / strategy.position_avg_price * posSign * 100p1 = plot(profitPercent(high), style=plot.style_linebr, title = "open profit % upper bound")p2 = plot(profitPercent(low), style=plot.style_linebr, title = "open profit % lower bound")fill(p1, p2, color = color.red)