Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

How to use Leverage and Margin in PineScript

A Pine Script v4 strategy built on SMA or Stoch (4) and SMA (k, 3). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a profit target and no stop loss. Each trade commits 3000% of equity and pays no commission. 4 settings; defaults include K 13, D 3 and Smooth 4.

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 How to use Leverage and Margin in PineScript repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 62 of 62 trades.
How did How to use Leverage and Margin in PineScript do on BTCUSDT 1D with default settings?
+7.49%
From 26 Jan 2024 to 21 Oct 2026, over 191 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can How to use Leverage and Margin in PineScript be converted to Pine Script v5?
No
The automatic step from v4 to v5 changes the results, so no v5 download is offered; the edits are shown below.
Does How to use Leverage and Margin in PineScript use a stop loss?
No
Its exits set a profit target but no stop.
Does How to use Leverage and Margin in PineScript run in Zeal Terminal?
Yes
It compiles in 15 ms and runs 1,000 bars in 32 ms, in the browser.

BTCUSDT · 1D · default settings

  • %K
  • %D
  • 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,000AprJulOct2025AprJulOct2026AprJulOct%K$107,486$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
+7.49%
$7,485.03
Buy and hold
+102.5%
same period
Closed trades
191
191 won · 0 lost
Profitable
100.0%
of closed trades
Profit factor
—
gross profit ÷ gross loss
Max drawdown
0.00%
$0.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 stop loss

    strategy.exit is used without a stop, loss or trailing stop.

  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Check

    Every trade uses all the equity

    default_qty_value is 3000% of equity.

  • 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 20, 22. The upgraded version below moves each call inside an if block.

  • Note

    Uses transp =, which v5 removed line 16

    transp = on line 16. v5 folds the transparency into the colour with color.new(c, transp).

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 sma → ta.sma, stoch → ta.stoch, crossover → ta.crossover, crossunder → ta.crossunder.
  • 2 strategy calls use the when = argument (line 20, 22). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Differs

Trades differ: 191 before, 191 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 3: //@version=4 → //@version=5
  • Line 10: sma → ta.sma
  • Line 10: stoch → ta.stoch
  • Line 11: sma → ta.sma
  • Line 16: transp = 75 → color.new(color.purple, 75)
  • Line 17: crossover → ta.crossover
  • Line 18: crossunder → ta.crossunder
⋯// © Peter_O-//@version=4+//@version=5strategy(title="How to use Leverage and Margin in PineScript", overlay=false, pyramiding=100,⋯smoothK = input(4, title="Smooth", minval=1)-k = sma(stoch(close, high, low, periodK), smoothK)+k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)-d = sma(k, periodD)+d = ta.sma(k, periodD)plot(k, title="%K", color=color.blue)⋯h1 = hline(20)-fill(h0, h1, color=color.purple, transp=75)+fill(h0, h1, color=color.new(color.purple, 75))-GoLong=crossover(k,d) and k<80+GoLong=ta.crossover(k,d) and k<80-GoShort=crossunder(k,d) and k>20+GoShort=ta.crossunder(k,d) and k>20TP=input(100, title="Take Profit (in ticks)")⋯

Clean v5

Verified

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

  • Line 7: input() → input.int()
  • Line 8: input() → input.int()
  • Line 9: input() → input.int()
  • Line 19: input() → input.int()
  • Line 20: when = GoLong → if block
  • Line 22: when = GoShort → if block
⋯     margin_long=1./30*50, margin_short=1./30*50)-periodK = input(13, title="K", minval=1)+periodK = input.int(13, title="K", minval=1)-periodD = input(3, title="D", minval=1)+periodD = input.int(3, title="D", minval=1)-smoothK = input(4, title="Smooth", minval=1)+smoothK = input.int(4, title="Smooth", minval=1)k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)⋯GoShort=ta.crossunder(k,d) and k>20-TP=input(100, title="Take Profit (in ticks)")+TP=input.int(100, title="Take Profit (in ticks)")-strategy.entry("Long", strategy.long, when=GoLong)+if GoLong+    strategy.entry("Long", strategy.long)strategy.exit("tp_long", from_entry="Long", profit=TP)-strategy.entry("Short", strategy.short, when=GoShort)+if GoShort+    strategy.entry("Short", strategy.short)strategy.exit("tp_short", from_entry="Short", profit=TP)

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

⋯// © Peter_O-//@version=5+//@version=6strategy(title="How to use Leverage and Margin in PineScript", overlay=false, pyramiding=100,⋯

Settings

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

SettingDefaultType and rangeFeeds
K13int · min 1k
D3int · min 1d
Smooth4int · min 1k
Take Profit (in ticks)100intexit tp_long exit tp_short

What it calculates

  • SMA / Stoch (sma, ta.sma in v5)stoch(close, high, low, periodK), Smooth (4)k · line 10
  • SMA (sma, ta.sma in v5)k, D (3)d · line 11

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.

lowlowprice datahighhighprice dataclosecloseprice dataperiodKKsetting · 13smoothKSmoothsetting · 4periodDDsetting · 3kSMA / Stoch→ kdSMA→ dGoLongGoLongconditionGoShortGoShortconditionentry:LongOpen Longstrategy.entryexit:tp_longexit tp_longstrategy.exitentry:ShortOpen Shortstrategy.entryexit:tp_shortexit tp_shortstrategy.exitplot:12%Kplotplot:13%Dplothline:14hlinehlinehline:15hlinehlinefill:16Fillfill

Order rules

OrderFires whenBy defaultLine
Open Long longGoLongcrossover(k,d) and k<80On20
Exit tp_long limitevery barOn21
Open Short shortGoShortcrossunder(k,d) and k>20On22
Exit tp_short limitevery barOn23

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.

62/62trades 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+7.5%+102.5%191100%—0.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−57.3%+5.5%14899%0.09313.6%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+41.0%+9.8%18899%1.09356.7%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−76.5%+8.4%11996%0.46404.2%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+1,730,740,000.0%+16.7%12198%3.191,274.3%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−94.6%+21.5%10164%0.54260.2%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+292,907.0%+148.3%18899%7.97358.3%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h−86.6%+17.1%17485%0.85211.2%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

Settings heatmap

Two settings that feed the entry signal, moved around their defaults. The best in-sample pair (K 7, D 2) made +6.9% before 26 Dec 2025 and +3.9% after it, against +2.7% for the defaults. 100% of the 32 combinations made money in-sample and 100% out-of-sample.

Before 26 Dec 2025 · in-sample
D ↓ · K →7891113161822
2+7%+7%+6%+6%+7%+6%+6%+5%
3+6%+5%+5%+5%+5%+5%+4%+4%
4+5%+5%+4%+4%+4%+4%+4%+4%
5+4%+4%+4%+4%+4%+4%+3%+3%
From 26 Dec 2025 · out-of-sample
D ↓ · K →7891113161822
2+4%+4%+4%+4%+3%+3%+3%+3%
3+3%+3%+3%+3%+3%+3%+2%+2%
4+3%+3%+3%+2%+2%+2%+2%+2%
5+3%+2%+2%+2%+2%+2%+2%+2%

Net P&L of trades opened in each period, as a share of starting capital. marks the defaults and the best in-sample cell. Hover a cell for its trade count. Backtests are simulations on historical data and are not investment advice.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market70100%$2,555.02
Sideways market68100%$2,689.42
Falling market53100%$2,240.59

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

How bad could the drawdown be?

0.0%

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

0%1%
The first 150 of 191 trades
SideEntryExitBarsP&L
short16 Feb 2024 51,880.0016 Feb 2024 51,879.000$57.83
long27 Feb 2024 54,476.5027 Feb 2024 54,477.500$55.10
short2 Mar 2024 62,387.902 Mar 2024 62,386.900$48.14
short6 Mar 2024 63,724.006 Mar 2024 63,723.000$47.15
short15 Mar 2024 71,388.9015 Mar 2024 71,387.900$42.11
long24 Mar 2024 63,990.0024 Mar 2024 63,991.000$47.00
short3 Apr 2024 65,464.003 Apr 2024 65,463.000$45.96
long7 Apr 2024 68,896.007 Apr 2024 68,897.000$43.69
short13 Apr 2024 67,116.5013 Apr 2024 67,115.500$44.87
long20 Apr 2024 63,818.0020 Apr 2024 63,819.000$47.21
short28 Apr 2024 63,462.0028 Apr 2024 63,461.000$47.50
long29 Apr 2024 63,118.6029 Apr 2024 63,119.600$47.78
short30 Apr 2024 63,866.0030 Apr 2024 63,865.000$47.24
long5 May 2024 63,892.005 May 2024 63,893.000$47.25
short9 May 2024 61,193.009 May 2024 61,192.000$49.35
long14 May 2024 62,940.1014 May 2024 62,941.100$48.01
short23 May 2024 69,166.6023 May 2024 69,165.600$43.71
long28 May 2024 69,436.4028 May 2024 69,437.400$43.55
short29 May 2024 68,398.4029 May 2024 68,397.400$44.23
long4 Jun 2024 68,809.904 Jun 2024 68,810.900$43.99
short9 Jun 2024 69,310.509 Jun 2024 69,309.500$43.69
long18 Jun 2024 66,504.3018 Jun 2024 66,505.300$45.55
long26 Jun 2024 61,806.0026 Jun 2024 61,807.000$49.04
short30 Jun 2024 60,986.7030 Jun 2024 60,985.700$49.72
long1 Jul 2024 62,772.001 Jul 2024 62,773.000$48.33
short5 Jul 2024 57,050.005 Jul 2024 57,049.000$53.20
long9 Jul 2024 56,714.609 Jul 2024 56,715.600$53.55
short20 Jul 2024 66,660.0020 Jul 2024 66,659.000$45.58
short24 Jul 2024 65,936.0024 Jul 2024 65,935.000$46.10
short30 Jul 2024 66,784.7030 Jul 2024 66,783.700$45.54
long7 Aug 2024 56,022.007 Aug 2024 56,023.000$54.31
short19 Aug 2024 58,427.3019 Aug 2024 58,426.300$52.10
long22 Aug 2024 61,156.0022 Aug 2024 61,157.000$49.80
short28 Aug 2024 59,415.0028 Aug 2024 59,414.000$51.29
long5 Sep 2024 57,970.905 Sep 2024 57,971.900$52.59
long8 Sep 2024 54,160.908 Sep 2024 54,161.900$56.32
short18 Sep 2024 60,314.0018 Sep 2024 60,313.000$50.60
short23 Sep 2024 63,578.8023 Sep 2024 63,577.800$48.03
short1 Oct 2024 63,327.601 Oct 2024 63,326.600$48.24
long6 Oct 2024 62,058.006 Oct 2024 62,059.000$49.25
short10 Oct 2024 60,636.0010 Oct 2024 60,635.000$50.43
long12 Oct 2024 62,540.0012 Oct 2024 62,541.000$48.92
short22 Oct 2024 67,377.5022 Oct 2024 67,376.500$45.43
long29 Oct 2024 69,962.2029 Oct 2024 69,963.200$43.77
short2 Nov 2024 69,496.002 Nov 2024 69,495.000$44.08
long7 Nov 2024 75,572.007 Nov 2024 75,573.000$40.56
short14 Nov 2024 90,375.2014 Nov 2024 90,374.200$33.93
short25 Nov 2024 97,900.1025 Nov 2024 97,899.100$31.33
long30 Nov 2024 97,460.0030 Nov 2024 97,461.000$31.48
short3 Dec 2024 95,840.603 Dec 2024 95,839.600$32.02
long5 Dec 2024 98,587.305 Dec 2024 98,588.300$31.14
short6 Dec 2024 96,945.606 Dec 2024 96,944.600$31.68
long8 Dec 2024 99,832.008 Dec 2024 99,833.000$30.77
short9 Dec 2024 101,110.009 Dec 2024 101,109.000$30.39
long14 Dec 2024 101,424.0014 Dec 2024 101,425.000$30.31
short19 Dec 2024 100,204.0019 Dec 2024 100,203.000$30.68
long25 Dec 2024 98,663.6025 Dec 2024 98,664.600$31.17
short28 Dec 2024 94,299.0028 Dec 2024 94,298.000$32.63
long2 Jan 2025 94,591.802 Jan 2025 94,592.800$32.54
short8 Jan 2025 96,954.608 Jan 2025 96,953.600$31.75
long14 Jan 2025 94,536.1014 Jan 2025 94,537.100$32.57
short21 Jan 2025 102,260.0021 Jan 2025 102,259.000$30.12
long25 Jan 2025 104,871.0025 Jan 2025 104,872.000$29.38
short26 Jan 2025 104,747.0026 Jan 2025 104,746.000$29.43
long5 Feb 2025 97,763.105 Feb 2025 97,764.100$31.54
short8 Feb 2025 96,506.808 Feb 2025 96,505.800$31.96
long11 Feb 2025 97,430.8011 Feb 2025 97,431.800$31.66
short12 Feb 2025 95,778.2012 Feb 2025 95,777.200$32.22
long13 Feb 2025 97,870.0013 Feb 2025 97,871.000$31.54
short17 Feb 2025 96,118.1017 Feb 2025 96,117.100$32.13
long21 Feb 2025 98,305.0021 Feb 2025 98,306.000$31.42
short25 Feb 2025 91,552.9025 Feb 2025 91,551.900$33.75
long1 Mar 2025 84,349.901 Mar 2025 84,350.900$36.64
short7 Mar 2025 89,931.907 Mar 2025 89,930.900$34.38
long8 Mar 2025 86,801.708 Mar 2025 86,802.700$35.63
short10 Mar 2025 80,734.5010 Mar 2025 80,733.500$38.32
long14 Mar 2025 81,115.8014 Mar 2025 81,116.800$38.16
short28 Mar 2025 87,232.0028 Mar 2025 87,231.000$35.50
long3 Apr 2025 82,516.303 Apr 2025 82,517.300$37.54
short6 Apr 2025 83,538.006 Apr 2025 83,537.000$37.09
long8 Apr 2025 79,163.208 Apr 2025 79,164.200$39.15
short9 Apr 2025 76,322.409 Apr 2025 76,321.400$40.63
long10 Apr 2025 82,615.2010 Apr 2025 82,616.200$37.55
short27 Apr 2025 94,628.0027 Apr 2025 94,627.000$32.79
short4 May 2025 95,856.404 May 2025 95,855.400$32.38
long9 May 2025 103,262.009 May 2025 103,263.000$30.07
short13 May 2025 102,791.0013 May 2025 102,790.000$30.22
short24 May 2025 107,318.0024 May 2025 107,317.000$28.95
long28 May 2025 108,938.0028 May 2025 108,939.000$28.53
short30 May 2025 105,590.0030 May 2025 105,589.000$29.44
long4 Jun 2025 105,377.004 Jun 2025 105,378.000$29.51
short5 Jun 2025 104,697.005 Jun 2025 104,696.000$29.71
long8 Jun 2025 105,552.008 Jun 2025 105,553.000$29.48
short14 Jun 2025 106,067.0014 Jun 2025 106,066.000$29.34
long24 Jun 2025 105,334.0024 Jun 2025 105,335.000$29.55
short2 Jul 2025 105,681.002 Jul 2025 105,680.000$29.47
short4 Jul 2025 109,585.004 Jul 2025 109,584.000$28.42
short7 Jul 2025 109,204.007 Jul 2025 109,203.000$28.53
long10 Jul 2025 111,234.0010 Jul 2025 111,235.000$28.02
short15 Jul 2025 119,841.0015 Jul 2025 119,840.000$26.01
long23 Jul 2025 119,954.0023 Jul 2025 119,955.000$25.99
short24 Jul 2025 118,756.0024 Jul 2025 118,755.000$26.26
long28 Jul 2025 119,416.0028 Jul 2025 119,417.000$26.12
short1 Aug 2025 115,764.001 Aug 2025 115,763.000$26.96
long5 Aug 2025 115,055.005 Aug 2025 115,056.000$27.13
short15 Aug 2025 118,295.0015 Aug 2025 118,294.000$26.39
long24 Aug 2025 115,438.0024 Aug 2025 115,439.000$27.05
long29 Aug 2025 112,567.0029 Aug 2025 112,568.000$27.75
short31 Aug 2025 108,816.0031 Aug 2025 108,815.000$28.71
long3 Sep 2025 111,240.003 Sep 2025 111,241.000$28.10
short15 Sep 2025 115,268.0015 Sep 2025 115,267.000$27.12
short20 Sep 2025 115,632.0020 Sep 2025 115,631.000$27.04
long29 Sep 2025 112,164.0029 Sep 2025 112,165.000$27.89
short7 Oct 2025 124,659.007 Oct 2025 124,658.000$25.10
long16 Oct 2025 110,763.0016 Oct 2025 110,764.000$28.25
short17 Oct 2025 108,194.0017 Oct 2025 108,193.000$28.93
long21 Oct 2025 110,532.0021 Oct 2025 110,533.000$28.33
short30 Oct 2025 110,021.0030 Oct 2025 110,020.000$28.47
long9 Nov 2025 102,313.009 Nov 2025 102,314.000$30.62
short14 Nov 2025 99,692.0014 Nov 2025 99,691.000$31.43
long19 Nov 2025 92,960.8019 Nov 2025 92,961.800$33.72
long22 Nov 2025 85,129.4022 Nov 2025 85,130.400$36.84
short2 Dec 2025 86,286.002 Dec 2025 86,285.000$36.35
long3 Dec 2025 91,277.903 Dec 2025 91,278.900$34.38
short7 Dec 2025 89,236.807 Dec 2025 89,235.800$35.18
long10 Dec 2025 92,678.8010 Dec 2025 92,679.800$33.88
short14 Dec 2025 90,240.0014 Dec 2025 90,239.000$34.81
long20 Dec 2025 88,136.9020 Dec 2025 88,137.900$35.65
short25 Dec 2025 87,669.4025 Dec 2025 87,668.400$35.85
long26 Dec 2025 87,225.3026 Dec 2025 87,226.300$36.05
short1 Jan 2026 87,648.201 Jan 2026 87,647.200$35.89
long3 Jan 2026 89,995.103 Jan 2026 89,996.100$34.96
short8 Jan 2026 91,364.208 Jan 2026 91,363.200$34.45
long14 Jan 2026 95,414.0014 Jan 2026 95,415.000$33.00
short18 Jan 2026 95,147.8018 Jan 2026 95,146.800$33.10
long25 Jan 2026 89,225.3025 Jan 2026 89,226.300$35.31
long28 Jan 2026 89,250.0028 Jan 2026 89,251.000$35.31
short1 Feb 2026 78,741.101 Feb 2026 78,740.100$40.04
long3 Feb 2026 78,738.603 Feb 2026 78,739.600$40.05
long7 Feb 2026 70,580.307 Feb 2026 70,581.300$44.70
short12 Feb 2026 67,082.5012 Feb 2026 67,081.500$47.05
long14 Feb 2026 68,854.0014 Feb 2026 68,855.000$45.86
short20 Feb 2026 67,003.7020 Feb 2026 67,002.700$47.15
long26 Feb 2026 67,988.0026 Feb 2026 67,989.000$46.49
short2 Mar 2026 65,776.502 Mar 2026 65,775.500$48.07
long3 Mar 2026 68,830.103 Mar 2026 68,831.100$45.96
short7 Mar 2026 68,114.007 Mar 2026 68,113.000$46.46
long11 Mar 2026 69,948.6011 Mar 2026 69,949.600$45.26
short19 Mar 2026 71,246.6019 Mar 2026 71,245.600$44.46
long26 Mar 2026 71,336.5026 Mar 2026 71,337.500$44.42

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
How to use Leverage and Margin in PineScript this page—v4 strategy+7.5%1910.0%
(IK) Stoch-60-15 by tapRoot_codingstoch smav4 strategyNo trades on this market
Stochastic Oscillator by Zeal Terminalstoch smav5 indicatorindicator
CCI Level Zone by Naruephatsma stochv5 strategyNo trades on this market
Stochastic Moving Average by LucasVivienstoch smav5 strategy+2.8%74.4%
OTT-Stoch-TP-SL by BigCoinHuntersma stochv5 strategyNo trades on this market

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 15 msYes 1,000 bars in 32 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/// © Peter_O//@version=4strategy(title="How to use Leverage and Margin in PineScript", overlay=false, pyramiding=100,     default_qty_type = strategy.percent_of_equity, default_qty_value=3000,     margin_long=1./30*50, margin_short=1./30*50)periodK = input(13, title="K", minval=1)periodD = input(3, title="D", minval=1)smoothK = input(4, title="Smooth", minval=1)k = sma(stoch(close, high, low, periodK), smoothK)d = sma(k, periodD)plot(k, title="%K", color=color.blue)plot(d, title="%D", color=color.orange)h0 = hline(80)h1 = hline(20)fill(h0, h1, color=color.purple, transp=75)GoLong=crossover(k,d) and k<80GoShort=crossunder(k,d) and k>20TP=input(100, title="Take Profit (in ticks)")strategy.entry("Long", strategy.long, when=GoLong)strategy.exit("tp_long", from_entry="Long", profit=TP)strategy.entry("Short", strategy.short, when=GoShort)strategy.exit("tp_short", from_entry="Short", profit=TP)