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
- 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
DiffersTrades 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
VerifiedSame 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| K | 13 | int · min 1 | k |
| D | 3 | int · min 1 | d |
| Smooth | 4 | int · min 1 | k |
| Take Profit (in ticks) | 100 | int | exit tp_long exit tp_short |
What it calculates
- SMA / Stoch (
sma,ta.smain v5)stoch(close, high, low, periodK), Smooth (4)k · line 10 - SMA (
sma,ta.smain 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | GoLongcrossover(k,d) and k<80 | On | 20 |
| Exit tp_long limit | every bar | On | 21 |
| Open Short short | GoShortcrossunder(k,d) and k>20 | On | 22 |
| Exit tp_short limit | every bar | On | 23 |
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 | +7.5% | +102.5% | 191 | 100% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −57.3% | +5.5% | 148 | 99% | 0.09 | 313.6% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +41.0% | +9.8% | 188 | 99% | 1.09 | 356.7% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −76.5% | +8.4% | 119 | 96% | 0.46 | 404.2% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +1,730,740,000.0% | +16.7% | 121 | 98% | 3.19 | 1,274.3% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −94.6% | +21.5% | 101 | 64% | 0.54 | 260.2% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +292,907.0% | +148.3% | 188 | 99% | 7.97 | 358.3% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −86.6% | +17.1% | 174 | 85% | 0.85 | 211.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.
| D ↓ · K → | 7 | 8 | 9 | 11 | 13 | 16 | 18 | 22 |
|---|---|---|---|---|---|---|---|---|
| 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% |
| D ↓ · K → | 7 | 8 | 9 | 11 | 13 | 16 | 18 | 22 |
|---|---|---|---|---|---|---|---|---|
| 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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 70 | 100% | $2,555.02 |
| Sideways market | 68 | 100% | $2,689.42 |
| Falling market | 53 | 100% | $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.
The first 150 of 191 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 16 Feb 2024 51,880.00 | 16 Feb 2024 51,879.00 | 0 | $57.83 |
| long | 27 Feb 2024 54,476.50 | 27 Feb 2024 54,477.50 | 0 | $55.10 |
| short | 2 Mar 2024 62,387.90 | 2 Mar 2024 62,386.90 | 0 | $48.14 |
| short | 6 Mar 2024 63,724.00 | 6 Mar 2024 63,723.00 | 0 | $47.15 |
| short | 15 Mar 2024 71,388.90 | 15 Mar 2024 71,387.90 | 0 | $42.11 |
| long | 24 Mar 2024 63,990.00 | 24 Mar 2024 63,991.00 | 0 | $47.00 |
| short | 3 Apr 2024 65,464.00 | 3 Apr 2024 65,463.00 | 0 | $45.96 |
| long | 7 Apr 2024 68,896.00 | 7 Apr 2024 68,897.00 | 0 | $43.69 |
| short | 13 Apr 2024 67,116.50 | 13 Apr 2024 67,115.50 | 0 | $44.87 |
| long | 20 Apr 2024 63,818.00 | 20 Apr 2024 63,819.00 | 0 | $47.21 |
| short | 28 Apr 2024 63,462.00 | 28 Apr 2024 63,461.00 | 0 | $47.50 |
| long | 29 Apr 2024 63,118.60 | 29 Apr 2024 63,119.60 | 0 | $47.78 |
| short | 30 Apr 2024 63,866.00 | 30 Apr 2024 63,865.00 | 0 | $47.24 |
| long | 5 May 2024 63,892.00 | 5 May 2024 63,893.00 | 0 | $47.25 |
| short | 9 May 2024 61,193.00 | 9 May 2024 61,192.00 | 0 | $49.35 |
| long | 14 May 2024 62,940.10 | 14 May 2024 62,941.10 | 0 | $48.01 |
| short | 23 May 2024 69,166.60 | 23 May 2024 69,165.60 | 0 | $43.71 |
| long | 28 May 2024 69,436.40 | 28 May 2024 69,437.40 | 0 | $43.55 |
| short | 29 May 2024 68,398.40 | 29 May 2024 68,397.40 | 0 | $44.23 |
| long | 4 Jun 2024 68,809.90 | 4 Jun 2024 68,810.90 | 0 | $43.99 |
| short | 9 Jun 2024 69,310.50 | 9 Jun 2024 69,309.50 | 0 | $43.69 |
| long | 18 Jun 2024 66,504.30 | 18 Jun 2024 66,505.30 | 0 | $45.55 |
| long | 26 Jun 2024 61,806.00 | 26 Jun 2024 61,807.00 | 0 | $49.04 |
| short | 30 Jun 2024 60,986.70 | 30 Jun 2024 60,985.70 | 0 | $49.72 |
| long | 1 Jul 2024 62,772.00 | 1 Jul 2024 62,773.00 | 0 | $48.33 |
| short | 5 Jul 2024 57,050.00 | 5 Jul 2024 57,049.00 | 0 | $53.20 |
| long | 9 Jul 2024 56,714.60 | 9 Jul 2024 56,715.60 | 0 | $53.55 |
| short | 20 Jul 2024 66,660.00 | 20 Jul 2024 66,659.00 | 0 | $45.58 |
| short | 24 Jul 2024 65,936.00 | 24 Jul 2024 65,935.00 | 0 | $46.10 |
| short | 30 Jul 2024 66,784.70 | 30 Jul 2024 66,783.70 | 0 | $45.54 |
| long | 7 Aug 2024 56,022.00 | 7 Aug 2024 56,023.00 | 0 | $54.31 |
| short | 19 Aug 2024 58,427.30 | 19 Aug 2024 58,426.30 | 0 | $52.10 |
| long | 22 Aug 2024 61,156.00 | 22 Aug 2024 61,157.00 | 0 | $49.80 |
| short | 28 Aug 2024 59,415.00 | 28 Aug 2024 59,414.00 | 0 | $51.29 |
| long | 5 Sep 2024 57,970.90 | 5 Sep 2024 57,971.90 | 0 | $52.59 |
| long | 8 Sep 2024 54,160.90 | 8 Sep 2024 54,161.90 | 0 | $56.32 |
| short | 18 Sep 2024 60,314.00 | 18 Sep 2024 60,313.00 | 0 | $50.60 |
| short | 23 Sep 2024 63,578.80 | 23 Sep 2024 63,577.80 | 0 | $48.03 |
| short | 1 Oct 2024 63,327.60 | 1 Oct 2024 63,326.60 | 0 | $48.24 |
| long | 6 Oct 2024 62,058.00 | 6 Oct 2024 62,059.00 | 0 | $49.25 |
| short | 10 Oct 2024 60,636.00 | 10 Oct 2024 60,635.00 | 0 | $50.43 |
| long | 12 Oct 2024 62,540.00 | 12 Oct 2024 62,541.00 | 0 | $48.92 |
| short | 22 Oct 2024 67,377.50 | 22 Oct 2024 67,376.50 | 0 | $45.43 |
| long | 29 Oct 2024 69,962.20 | 29 Oct 2024 69,963.20 | 0 | $43.77 |
| short | 2 Nov 2024 69,496.00 | 2 Nov 2024 69,495.00 | 0 | $44.08 |
| long | 7 Nov 2024 75,572.00 | 7 Nov 2024 75,573.00 | 0 | $40.56 |
| short | 14 Nov 2024 90,375.20 | 14 Nov 2024 90,374.20 | 0 | $33.93 |
| short | 25 Nov 2024 97,900.10 | 25 Nov 2024 97,899.10 | 0 | $31.33 |
| long | 30 Nov 2024 97,460.00 | 30 Nov 2024 97,461.00 | 0 | $31.48 |
| short | 3 Dec 2024 95,840.60 | 3 Dec 2024 95,839.60 | 0 | $32.02 |
| long | 5 Dec 2024 98,587.30 | 5 Dec 2024 98,588.30 | 0 | $31.14 |
| short | 6 Dec 2024 96,945.60 | 6 Dec 2024 96,944.60 | 0 | $31.68 |
| long | 8 Dec 2024 99,832.00 | 8 Dec 2024 99,833.00 | 0 | $30.77 |
| short | 9 Dec 2024 101,110.00 | 9 Dec 2024 101,109.00 | 0 | $30.39 |
| long | 14 Dec 2024 101,424.00 | 14 Dec 2024 101,425.00 | 0 | $30.31 |
| short | 19 Dec 2024 100,204.00 | 19 Dec 2024 100,203.00 | 0 | $30.68 |
| long | 25 Dec 2024 98,663.60 | 25 Dec 2024 98,664.60 | 0 | $31.17 |
| short | 28 Dec 2024 94,299.00 | 28 Dec 2024 94,298.00 | 0 | $32.63 |
| long | 2 Jan 2025 94,591.80 | 2 Jan 2025 94,592.80 | 0 | $32.54 |
| short | 8 Jan 2025 96,954.60 | 8 Jan 2025 96,953.60 | 0 | $31.75 |
| long | 14 Jan 2025 94,536.10 | 14 Jan 2025 94,537.10 | 0 | $32.57 |
| short | 21 Jan 2025 102,260.00 | 21 Jan 2025 102,259.00 | 0 | $30.12 |
| long | 25 Jan 2025 104,871.00 | 25 Jan 2025 104,872.00 | 0 | $29.38 |
| short | 26 Jan 2025 104,747.00 | 26 Jan 2025 104,746.00 | 0 | $29.43 |
| long | 5 Feb 2025 97,763.10 | 5 Feb 2025 97,764.10 | 0 | $31.54 |
| short | 8 Feb 2025 96,506.80 | 8 Feb 2025 96,505.80 | 0 | $31.96 |
| long | 11 Feb 2025 97,430.80 | 11 Feb 2025 97,431.80 | 0 | $31.66 |
| short | 12 Feb 2025 95,778.20 | 12 Feb 2025 95,777.20 | 0 | $32.22 |
| long | 13 Feb 2025 97,870.00 | 13 Feb 2025 97,871.00 | 0 | $31.54 |
| short | 17 Feb 2025 96,118.10 | 17 Feb 2025 96,117.10 | 0 | $32.13 |
| long | 21 Feb 2025 98,305.00 | 21 Feb 2025 98,306.00 | 0 | $31.42 |
| short | 25 Feb 2025 91,552.90 | 25 Feb 2025 91,551.90 | 0 | $33.75 |
| long | 1 Mar 2025 84,349.90 | 1 Mar 2025 84,350.90 | 0 | $36.64 |
| short | 7 Mar 2025 89,931.90 | 7 Mar 2025 89,930.90 | 0 | $34.38 |
| long | 8 Mar 2025 86,801.70 | 8 Mar 2025 86,802.70 | 0 | $35.63 |
| short | 10 Mar 2025 80,734.50 | 10 Mar 2025 80,733.50 | 0 | $38.32 |
| long | 14 Mar 2025 81,115.80 | 14 Mar 2025 81,116.80 | 0 | $38.16 |
| short | 28 Mar 2025 87,232.00 | 28 Mar 2025 87,231.00 | 0 | $35.50 |
| long | 3 Apr 2025 82,516.30 | 3 Apr 2025 82,517.30 | 0 | $37.54 |
| short | 6 Apr 2025 83,538.00 | 6 Apr 2025 83,537.00 | 0 | $37.09 |
| long | 8 Apr 2025 79,163.20 | 8 Apr 2025 79,164.20 | 0 | $39.15 |
| short | 9 Apr 2025 76,322.40 | 9 Apr 2025 76,321.40 | 0 | $40.63 |
| long | 10 Apr 2025 82,615.20 | 10 Apr 2025 82,616.20 | 0 | $37.55 |
| short | 27 Apr 2025 94,628.00 | 27 Apr 2025 94,627.00 | 0 | $32.79 |
| short | 4 May 2025 95,856.40 | 4 May 2025 95,855.40 | 0 | $32.38 |
| long | 9 May 2025 103,262.00 | 9 May 2025 103,263.00 | 0 | $30.07 |
| short | 13 May 2025 102,791.00 | 13 May 2025 102,790.00 | 0 | $30.22 |
| short | 24 May 2025 107,318.00 | 24 May 2025 107,317.00 | 0 | $28.95 |
| long | 28 May 2025 108,938.00 | 28 May 2025 108,939.00 | 0 | $28.53 |
| short | 30 May 2025 105,590.00 | 30 May 2025 105,589.00 | 0 | $29.44 |
| long | 4 Jun 2025 105,377.00 | 4 Jun 2025 105,378.00 | 0 | $29.51 |
| short | 5 Jun 2025 104,697.00 | 5 Jun 2025 104,696.00 | 0 | $29.71 |
| long | 8 Jun 2025 105,552.00 | 8 Jun 2025 105,553.00 | 0 | $29.48 |
| short | 14 Jun 2025 106,067.00 | 14 Jun 2025 106,066.00 | 0 | $29.34 |
| long | 24 Jun 2025 105,334.00 | 24 Jun 2025 105,335.00 | 0 | $29.55 |
| short | 2 Jul 2025 105,681.00 | 2 Jul 2025 105,680.00 | 0 | $29.47 |
| short | 4 Jul 2025 109,585.00 | 4 Jul 2025 109,584.00 | 0 | $28.42 |
| short | 7 Jul 2025 109,204.00 | 7 Jul 2025 109,203.00 | 0 | $28.53 |
| long | 10 Jul 2025 111,234.00 | 10 Jul 2025 111,235.00 | 0 | $28.02 |
| short | 15 Jul 2025 119,841.00 | 15 Jul 2025 119,840.00 | 0 | $26.01 |
| long | 23 Jul 2025 119,954.00 | 23 Jul 2025 119,955.00 | 0 | $25.99 |
| short | 24 Jul 2025 118,756.00 | 24 Jul 2025 118,755.00 | 0 | $26.26 |
| long | 28 Jul 2025 119,416.00 | 28 Jul 2025 119,417.00 | 0 | $26.12 |
| short | 1 Aug 2025 115,764.00 | 1 Aug 2025 115,763.00 | 0 | $26.96 |
| long | 5 Aug 2025 115,055.00 | 5 Aug 2025 115,056.00 | 0 | $27.13 |
| short | 15 Aug 2025 118,295.00 | 15 Aug 2025 118,294.00 | 0 | $26.39 |
| long | 24 Aug 2025 115,438.00 | 24 Aug 2025 115,439.00 | 0 | $27.05 |
| long | 29 Aug 2025 112,567.00 | 29 Aug 2025 112,568.00 | 0 | $27.75 |
| short | 31 Aug 2025 108,816.00 | 31 Aug 2025 108,815.00 | 0 | $28.71 |
| long | 3 Sep 2025 111,240.00 | 3 Sep 2025 111,241.00 | 0 | $28.10 |
| short | 15 Sep 2025 115,268.00 | 15 Sep 2025 115,267.00 | 0 | $27.12 |
| short | 20 Sep 2025 115,632.00 | 20 Sep 2025 115,631.00 | 0 | $27.04 |
| long | 29 Sep 2025 112,164.00 | 29 Sep 2025 112,165.00 | 0 | $27.89 |
| short | 7 Oct 2025 124,659.00 | 7 Oct 2025 124,658.00 | 0 | $25.10 |
| long | 16 Oct 2025 110,763.00 | 16 Oct 2025 110,764.00 | 0 | $28.25 |
| short | 17 Oct 2025 108,194.00 | 17 Oct 2025 108,193.00 | 0 | $28.93 |
| long | 21 Oct 2025 110,532.00 | 21 Oct 2025 110,533.00 | 0 | $28.33 |
| short | 30 Oct 2025 110,021.00 | 30 Oct 2025 110,020.00 | 0 | $28.47 |
| long | 9 Nov 2025 102,313.00 | 9 Nov 2025 102,314.00 | 0 | $30.62 |
| short | 14 Nov 2025 99,692.00 | 14 Nov 2025 99,691.00 | 0 | $31.43 |
| long | 19 Nov 2025 92,960.80 | 19 Nov 2025 92,961.80 | 0 | $33.72 |
| long | 22 Nov 2025 85,129.40 | 22 Nov 2025 85,130.40 | 0 | $36.84 |
| short | 2 Dec 2025 86,286.00 | 2 Dec 2025 86,285.00 | 0 | $36.35 |
| long | 3 Dec 2025 91,277.90 | 3 Dec 2025 91,278.90 | 0 | $34.38 |
| short | 7 Dec 2025 89,236.80 | 7 Dec 2025 89,235.80 | 0 | $35.18 |
| long | 10 Dec 2025 92,678.80 | 10 Dec 2025 92,679.80 | 0 | $33.88 |
| short | 14 Dec 2025 90,240.00 | 14 Dec 2025 90,239.00 | 0 | $34.81 |
| long | 20 Dec 2025 88,136.90 | 20 Dec 2025 88,137.90 | 0 | $35.65 |
| short | 25 Dec 2025 87,669.40 | 25 Dec 2025 87,668.40 | 0 | $35.85 |
| long | 26 Dec 2025 87,225.30 | 26 Dec 2025 87,226.30 | 0 | $36.05 |
| short | 1 Jan 2026 87,648.20 | 1 Jan 2026 87,647.20 | 0 | $35.89 |
| long | 3 Jan 2026 89,995.10 | 3 Jan 2026 89,996.10 | 0 | $34.96 |
| short | 8 Jan 2026 91,364.20 | 8 Jan 2026 91,363.20 | 0 | $34.45 |
| long | 14 Jan 2026 95,414.00 | 14 Jan 2026 95,415.00 | 0 | $33.00 |
| short | 18 Jan 2026 95,147.80 | 18 Jan 2026 95,146.80 | 0 | $33.10 |
| long | 25 Jan 2026 89,225.30 | 25 Jan 2026 89,226.30 | 0 | $35.31 |
| long | 28 Jan 2026 89,250.00 | 28 Jan 2026 89,251.00 | 0 | $35.31 |
| short | 1 Feb 2026 78,741.10 | 1 Feb 2026 78,740.10 | 0 | $40.04 |
| long | 3 Feb 2026 78,738.60 | 3 Feb 2026 78,739.60 | 0 | $40.05 |
| long | 7 Feb 2026 70,580.30 | 7 Feb 2026 70,581.30 | 0 | $44.70 |
| short | 12 Feb 2026 67,082.50 | 12 Feb 2026 67,081.50 | 0 | $47.05 |
| long | 14 Feb 2026 68,854.00 | 14 Feb 2026 68,855.00 | 0 | $45.86 |
| short | 20 Feb 2026 67,003.70 | 20 Feb 2026 67,002.70 | 0 | $47.15 |
| long | 26 Feb 2026 67,988.00 | 26 Feb 2026 67,989.00 | 0 | $46.49 |
| short | 2 Mar 2026 65,776.50 | 2 Mar 2026 65,775.50 | 0 | $48.07 |
| long | 3 Mar 2026 68,830.10 | 3 Mar 2026 68,831.10 | 0 | $45.96 |
| short | 7 Mar 2026 68,114.00 | 7 Mar 2026 68,113.00 | 0 | $46.46 |
| long | 11 Mar 2026 69,948.60 | 11 Mar 2026 69,949.60 | 0 | $45.26 |
| short | 19 Mar 2026 71,246.60 | 19 Mar 2026 71,245.60 | 0 | $44.46 |
| long | 26 Mar 2026 71,336.50 | 26 Mar 2026 71,337.50 | 0 | $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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| How to use Leverage and Margin in PineScript this page | — | v4 strategy | +7.5% | 191 | 0.0% |
| (IK) Stoch-60-15 by tapRoot_coding | stoch sma | v4 strategy | No trades on this market | ||
| Stochastic Oscillator by Zeal Terminal | stoch sma | v5 indicator | indicator | ||
| CCI Level Zone by Naruephat | sma stoch | v5 strategy | No trades on this market | ||
| Stochastic Moving Average by LucasVivien | stoch sma | v5 strategy | +2.8% | 7 | 4.4% |
| OTT-Stoch-TP-SL by BigCoinHunter | sma stoch | v5 strategy | No trades on this market | ||
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 15 ms | Yes 1,000 bars in 32 ms | Not measured |
| PineTS | No 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)