Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

2x take profit, move stop loss to entry

A Pine Script v5 strategy built on Stoch (close, high) and BB (close, 20). 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 commits 25% of equity and pays 0.01% commission. 4 settings; defaults include Take Profit 1 200, Take Profit 2 500 and Stop Loss 200.

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 2x take profit, move stop loss to entry repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 20 of 20 trades.
How did 2x take profit, move stop loss to entry do on BTCUSDT 1D with default settings?
−0.45%
From 26 Jan 2024 to 21 Oct 2026, over 66 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does 2x take profit, move stop loss to entry 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: 66 before, 66 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 2x take profit, move stop loss to entry use a stop loss?
Yes
strategy.exit sets a stop on line 84, 85, 87, 88.
Does 2x take profit, move stop loss to entry run in Zeal Terminal?
Yes
It compiles in 31 ms and runs 1,000 bars in 105 ms, in the browser.

BTCUSDT · 1D · default settings

  • Plot
  • Plot
  • Plot
  • Plot
  • HLine
  • HLine
  • 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 (4)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctPlot$995$2,025Equity from $1,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.45%
−$4.55
Buy and hold
+102.5%
same period
Closed trades
66
8 won · 58 lost
Profitable
12.1%
of closed trades
Profit factor
0.77
gross profit ÷ gross loss
Max drawdown
1.71%
−$17.15

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

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

  • Note

    Uses an argument v6 removed

    when = on line 83, 86. The upgraded version below moves each call inside an if block.

Settings

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

SettingDefaultType and rangeFeeds
Take Profit 1200floatlongTP1 shortTP1
Take Profit 2500floatlongTP2 shortTP2
Stop Loss200floatlongSL shortSL
Use Stochastic overbought/oversold thresholdtrueboollongCondition shortCondition plot

What it calculates

  • Stochclose, high, low, 14stoch · line 27
  • BBclose, 20, 2bbMiddle · line 34
  • BBclose, 20, 2bbUpper · line 34
  • BBclose, 20, 2bbLower · line 34

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 datatp1Take Profit 1setting · 200tp2Take Profit 2setting · 500slStop Losssetting · 200stochStoch→ stochbbMiddleBB→ bbMiddlebbUpperBB→ bbUpperbbLowerBB→ bbLowerlongConditionlongConditionvalueshortConditionshortConditionvaluelongTP1, shortTP1longTP1 · shortTP12 valueslongTP2, shortTP2longTP2 · shortTP22 valuesinLong, inShort, longClose, shortCloseinLong · inShort +24 conditionslongSLlongSLconditionshortSLshortSLconditioncolorRed, colorGreenColourcolorRed · colorGreenentry:LongOpen Longstrategy.entryexit:TP1/SLexit TP1/SLstrategy.exitexit:TP2/SLexit TP2/SLstrategy.exitentry:ShortOpen Shortstrategy.entryplot:91plotplotplot:92plotplotplot:94plotplotplot:95plotplothline:97hlinehlinehline:98hlinehline

Order rules

OrderFires whenBy defaultLine
Open Long longlongConditionOn83
Exit TP1/SL stop and limitevery barOn84
Exit TP2/SL stop and limitevery barOn85
Open Short shortshortConditionOn86
Exit TP1/SL stop and limitevery barOn87
Exit TP2/SL stop and limitevery barOn88

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.

20/20trades 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.5%+102.5%6612%0.771.7%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+0.7%+5.5%6033%1.470.6%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+6.7%+9.8%6240%1.247.8%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+4.5%+8.4%2060%1.489.5%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+23.9%+16.7%1963%1.4822.6%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+4.8%+21.5%1573%1.3511.4%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−21.8%+148.3%2642%0.5222.7%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+3.9%+17.1%1457%1.487.5%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 market3020%−$2.52
Sideways market229%$3.36
Falling market140%−$5.38

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

How bad could the drawdown be?

1.4%

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

0%2%
All 66 trades
SideEntryExitBarsP&L
short17 Feb 2024 52,124.1018 Feb 2024 51,642.601$1.13
short17 Feb 2024 52,124.1018 Feb 2024 51,624.101$1.17
short2 Mar 2024 62,387.903 Mar 2024 61,987.301$0.78
short2 Mar 2024 62,387.903 Mar 2024 61,887.901$0.98
short7 Mar 2024 66,074.007 Mar 2024 66,274.000−$0.40
short7 Mar 2024 66,074.007 Mar 2024 66,274.000−$0.40
long21 Apr 2024 64,940.6021 Apr 2024 64,740.600−$0.41
long21 Apr 2024 64,940.6021 Apr 2024 64,740.600−$0.41
short23 May 2024 69,166.6023 May 2024 69,366.600−$0.39
short23 May 2024 69,166.6023 May 2024 69,366.600−$0.39
long26 Jun 2024 61,806.0026 Jun 2024 61,606.000−$0.43
long26 Jun 2024 61,806.0026 Jun 2024 61,606.000−$0.43
long8 Jul 2024 55,857.808 Jul 2024 55,657.800−$0.47
long8 Jul 2024 55,857.808 Jul 2024 55,657.800−$0.47
long7 Aug 2024 56,022.007 Aug 2024 55,822.000−$0.47
long7 Aug 2024 56,022.007 Aug 2024 55,822.000−$0.47
long6 Sep 2024 56,180.006 Sep 2024 55,980.000−$0.47
long6 Sep 2024 56,180.006 Sep 2024 55,980.000−$0.47
short2 Nov 2024 69,496.002 Nov 2024 69,696.000−$0.38
short2 Nov 2024 69,496.002 Nov 2024 69,696.000−$0.38
short14 Nov 2024 90,375.2014 Nov 2024 90,575.200−$0.30
short14 Nov 2024 90,375.2014 Nov 2024 90,575.200−$0.30
short20 Dec 2024 97,461.9020 Dec 2024 97,661.900−$0.28
short20 Dec 2024 97,461.9020 Dec 2024 97,661.900−$0.28
short9 Jan 2025 95,060.609 Jan 2025 95,260.600−$0.29
short9 Jan 2025 95,060.609 Jan 2025 95,260.600−$0.29
short21 Jan 2025 102,260.0021 Jan 2025 102,460.000−$0.27
short21 Jan 2025 102,260.0021 Jan 2025 102,460.000−$0.27
long2 Mar 2025 86,064.502 Mar 2025 85,864.500−$0.31
long2 Mar 2025 86,064.502 Mar 2025 85,864.500−$0.31
short27 Apr 2025 94,628.0027 Apr 2025 94,828.000−$0.29
short27 Apr 2025 94,628.0027 Apr 2025 94,828.000−$0.29
short14 May 2025 104,104.0014 May 2025 104,304.000−$0.26
short14 May 2025 104,104.0014 May 2025 104,304.000−$0.26
long8 Jun 2025 105,552.008 Jun 2025 105,352.000−$0.26
long8 Jun 2025 105,552.008 Jun 2025 105,352.000−$0.26
short16 Jul 2025 117,758.0016 Jul 2025 117,958.000−$0.24
short16 Jul 2025 117,758.0016 Jul 2025 117,958.000−$0.24
short16 Aug 2025 117,342.0016 Aug 2025 117,542.000−$0.24
short16 Aug 2025 117,342.0016 Aug 2025 117,542.000−$0.24
short7 Oct 2025 124,659.007 Oct 2025 124,859.000−$0.22
short7 Oct 2025 124,659.007 Oct 2025 124,859.000−$0.22
long9 Nov 2025 102,313.009 Nov 2025 102,113.000−$0.27
long9 Nov 2025 102,313.009 Nov 2025 102,113.000−$0.27
long20 Nov 2025 91,555.0020 Nov 2025 91,355.000−$0.30
long20 Nov 2025 91,555.0020 Nov 2025 91,355.000−$0.30
short8 Jan 2026 91,364.208 Jan 2026 91,564.200−$0.30
short8 Jan 2026 91,364.208 Jan 2026 91,564.200−$0.30
long5 Feb 2026 73,165.805 Feb 2026 72,965.800−$0.36
long5 Feb 2026 73,165.805 Feb 2026 72,965.800−$0.36
long8 Feb 2026 69,289.408 Feb 2026 69,089.400−$0.38
long8 Feb 2026 69,289.408 Feb 2026 69,089.400−$0.38
short8 May 2026 80,006.008 May 2026 80,206.000−$0.33
short8 May 2026 80,006.008 May 2026 80,206.000−$0.33
long25 May 2026 77,065.0026 May 2026 77,322.001$0.39
long25 May 2026 77,065.0026 May 2026 77,565.001$0.78
long7 Jun 2026 60,884.608 Jun 2026 63,332.001$4.94
long7 Jun 2026 60,884.608 Jun 2026 63,332.001$4.94
long3 Jul 2026 61,560.003 Jul 2026 61,360.000−$0.43
long3 Jul 2026 61,560.003 Jul 2026 61,360.000−$0.43
long5 Aug 2026 64,106.605 Aug 2026 63,906.600−$0.41
long5 Aug 2026 64,106.605 Aug 2026 63,906.600−$0.41
short25 Aug 2026 78,992.8025 Aug 2026 79,192.800−$0.34
short25 Aug 2026 78,992.8025 Aug 2026 79,192.800−$0.34
short25 Sep 2026 84,410.2025 Sep 2026 84,610.200−$0.32
short25 Sep 2026 84,410.2025 Sep 2026 84,610.200−$0.32

Similar scripts

No other indicator or strategy here shares enough of its calculations.

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.

  • 2 strategy calls use the when = argument (line 83, 86). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

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

  • Line 83: when = longCondition → if block
  • Line 86: when = shortCondition → if block
⋯// Manage positions-strategy.entry("Long", strategy.long, when=longCondition)+if longCondition+    strategy.entry("Long", strategy.long)strategy.exit("TP1/SL", from_entry="Long", qty_percent=50, limit=longTP1, stop=longSL)strategy.exit("TP2/SL", from_entry="Long", limit=longTP2, stop=longSL)-strategy.entry("Short", strategy.short, when=shortCondition)+if shortCondition+    strategy.entry("Short", strategy.short)strategy.exit("TP1/SL", from_entry="Short", qty_percent=50, limit=shortTP1, stop=shortSL)⋯

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

⋯// © fpsd4ve-//@version=5+//@version=6// Add Bollinger Bands indicator (close, 20, 2) manually to visualise trading conditions⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 31 msYes 1,000 bars in 105 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/// © fpsd4ve//@version=5// Add Bollinger Bands indicator (close, 20, 2) manually to visualise trading conditionsstrategy("2xTP, SL to entry",      overlay=false,     pyramiding=0,     calc_on_every_tick=false,     default_qty_type=strategy.percent_of_equity,     default_qty_value=25,     initial_capital=1000,     commission_type=strategy.commission.percent,     commission_value=0.01     )// PARAMETERS// Assumes quote currency is FIAT as with BTC/USDT pairtp1=input.float(200, title="Take Profit 1")tp2=input.float(500, title="Take Profit 2")sl=input.float(200, title="Stop Loss")stOBOS = input.bool(true, title="Use Stochastic overbought/oversold threshold")// ColorscolorRed = #FF2052colorGreen = #66FF00// FUNCTIONS// Stochasticf_stochastic() =>    stoch = ta.stoch(close, high, low, 14)    stoch_K = ta.sma(stoch, 3)    stoch_D = ta.sma(stoch_K, 3)    stRD = ta.crossunder(stoch_K, stoch_D)    stGD = ta.crossover(stoch_K, stoch_D)    [stoch_K, stoch_D, stRD, stGD]// VARIABLES[bbMiddle, bbUpper, bbLower] = ta.bb(close, 20, 2)[stoch_K, stoch_D, stRD, stGD] = f_stochastic()// ORDERS// Active Orders// Check if strategy has open positionsinLong = strategy.position_size > 0inShort = strategy.position_size < 0// Check if strategy reduced position size in last barlongClose = strategy.position_size < strategy.position_size[1]shortClose = strategy.position_size > strategy.position_size[1]// Entry Conditions// Enter long when during last candle these conditions are true:// Candle high is greater than upper Bollinger Band// Stochastic K line crosses under D line and is oversoldlongCondition = stOBOS ?     low[1] < bbLower[1] and stGD[1] and stoch_K[1] < 25 :     low[1] < bbLower[1] and stGD[1]// Enter short when during last candle these conditions are true:// Candle low is lower than lower Bollinger Band// Stochastic K line crosses over D line and is overboughtshortCondition = stOBOS ?     high[1] > bbUpper[1] and stRD[1] and stoch_K[1] > 75 :     high[1] > bbUpper[1] and stRD[1]// Exit Conditions// Calculate Take Profit longTP1 = strategy.position_avg_price + tp1longTP2 = strategy.position_avg_price + tp2shortTP1 = strategy.position_avg_price - tp1shortTP2 = strategy.position_avg_price - tp2// Calculate Stop Loss// Initialise variablesvar float longSL = 0.0var float shortSL = 0.0// When not in position, set stop loss using close price which is the price used during backtesting// When in a position, check to see if the position was reduced on the last bar// If it was, set stop loss to position entry price. Otherwise, maintain last stop loss valuelongSL := if inLong and ta.barssince(longClose) < ta.barssince(longCondition)    strategy.position_avg_priceelse if inLong    longSL[1]else    close - slshortSL := if inShort and ta.barssince(shortClose) < ta.barssince(shortCondition)    strategy.position_avg_priceelse if inShort    shortSL[1]else    close + sl// Manage positionsstrategy.entry("Long", strategy.long, when=longCondition)strategy.exit("TP1/SL", from_entry="Long", qty_percent=50, limit=longTP1, stop=longSL)strategy.exit("TP2/SL", from_entry="Long", limit=longTP2, stop=longSL)strategy.entry("Short", strategy.short, when=shortCondition)strategy.exit("TP1/SL", from_entry="Short", qty_percent=50, limit=shortTP1, stop=shortSL)strategy.exit("TP2/SL", from_entry="Short", limit=shortTP2, stop=shortSL)// DRAW// Stochastic Chartplot(stoch_K, color=color.blue)plot(stoch_D, color=color.orange)// Circlesplot(stOBOS ? stRD and stoch_K >= 75 ? stoch_D : na : stRD ? stoch_D : na, color=colorRed, style=plot.style_circles, linewidth=3)plot(stOBOS ? stGD and stoch_K <= 25 ? stoch_D : na : stGD ? stoch_K : na, color=colorGreen, style=plot.style_circles, linewidth=3)// Levelshline(75, linestyle=hline.style_dotted)hline(25, linestyle=hline.style_dotted)