Pine Script v4 · Strategy
Strategy Template[Benson]
A Pine Script v4 strategy built on Crossunder or SMA (close,7, close,14) and Crossover or SMA (close,7, close,14). 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 100% of equity and pays no commission. 13 settings; defaults include backtest_year 2019, backtest_month 01 and backtest_day 01.
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 Strategy Template[Benson] repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 25 of 25 trades.
- How did Strategy Template[Benson] do on BTCUSDT 1D with default settings?
- +31.83%
- From 26 Jan 2024 to 21 Oct 2026, over 84 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Strategy Template[Benson] 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 Strategy Template[Benson] use a stop loss?
- Yes
- strategy.exit sets a stop on line 24, 27.
- Does Strategy Template[Benson] run in Zeal Terminal?
- Yes
- It compiles in 12 ms and runs 1,000 bars in 46 ms, in the browser.
BTCUSDT · 1D · default settings
- Net Profit
- Winning trade
- Losing trade
- Exit at a stop or limit price
- Equity
- Buy and hold
- Net profit
- +31.83%
- $31,825.90
- Buy and hold
- +102.5%
- same period
- Closed trades
- 84
- 34 won · 50 lost
- Profitable
- 40.5%
- of closed trades
- Profit factor
- 1.15
- gross profit ÷ gross loss
- Max drawdown
- 42.86%
- −$42,864.20
One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A short position was still open at the last bar. 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.
-
Check
Every trade uses all the equity
default_qty_value is 100% 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 22, 23, 25, 26. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 29
transp = on line 29. 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 crossunder → ta.crossunder, sma → ta.sma, crossover → ta.crossover.
- 4 strategy calls use the when = argument (line 22, 23, 25, 26). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
DiffersTrades differ: 84 before, 84 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 1: //@version=4 → //@version=5
- Line 5: input(type = input.integer) → input.int()
- Line 6: input(type = input.integer) → input.int()
- Line 7: input(type = input.integer) → input.int()
- Line 9: input(type = input.bool) → input.bool()
- Line 10: input(type = input.bool) → input.bool()
15 more edits
- Line 11: input(type = input.float) → input.float()
- Line 12: input(type = input.float) → input.float()
- Line 13: input(type = input.float) → input.float()
- Line 14: input(type = input.float) → input.float()
- Line 15: input(type = input.float) → input.float()
- Line 16: input(type = input.float) → input.float()
- Line 17: input(type = input.float) → input.float()
- Line 18: input(type = input.float) → input.float()
- Line 20: crossunder → ta.crossunder
- Line 20: sma → ta.sma
- Line 20: sma → ta.sma
- Line 21: crossover → ta.crossover
- Line 21: sma → ta.sma
- Line 21: sma → ta.sma
- Line 29: transp = 50 → color.new(net_profit >= 0 ? #26A69A : color.red, 50)
-//@version=4+//@version=5// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯strategy("Strategy Template[Benson]", pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=100)-backtest_year = input(2019, type=input.integer, title='backtest_year')+backtest_year = input.int(2019, title='backtest_year')-backtest_month = input(01, type=input.integer, title='backtest_month', minval=1, maxval=12)+backtest_month = input.int(01, title='backtest_month', minval=1, maxval=12)-backtest_day = input(01, type=input.integer, title='backtest_day', minval=1, maxval=31)+backtest_day = input.int(01, title='backtest_day', minval=1, maxval=31)start_time = timestamp(backtest_year, backtest_month, backtest_day, 00, 00)-stop_loss_and_tp = input(title="Enable Stop Loss and Take Profit", type=input.bool, defval=true)+stop_loss_and_tp = input.bool(title="Enable Stop Loss and Take Profit", defval=true)-trail_stop = input(title="Enable Trail Stop", type=input.bool, defval=true)+trail_stop = input.bool(title="Enable Trail Stop", defval=true)-buy_stop_loss = input(0.2, type=input.float, title='buy_stop_loss')+buy_stop_loss = input.float(0.2, title='buy_stop_loss')-sell_stop_loss = input(0.1, type=input.float, title='sell_stop_loss')+sell_stop_loss = input.float(0.1, title='sell_stop_loss')-buy_tp = input(0.4, type=input.float, title='buy_tp')+buy_tp = input.float(0.4, title='buy_tp')-sell_tp =input(0.2, type=input.float, title='sell_tp')+sell_tp =input.float(0.2, title='sell_tp')-trail_stop_long = input(1.1, type=input.float, title='trail_stop_long')+trail_stop_long = input.float(1.1, title='trail_stop_long')-trail_stop_short = input(0.9, type=input.float, title='trail_stop_short')+trail_stop_short = input.float(0.9, title='trail_stop_short')-trail_stop_long_offset = input(0.05, type=input.float, title='trail_stop_long_offset')+trail_stop_long_offset = input.float(0.05, title='trail_stop_long_offset')-trail_stop_short_offset = input(0.05, type=input.float, title='trail_stop_short_offset')+trail_stop_short_offset = input.float(0.05, title='trail_stop_short_offset')// you can set your own logic here-shortCondition = crossunder(sma(close,7),sma(close,14))+shortCondition = ta.crossunder(ta.sma(close,7),ta.sma(close,14))-longCondition = crossover(sma(close,7),sma(close,14))+longCondition = ta.crossover(ta.sma(close,7),ta.sma(close,14))strategy.entry("Buy", strategy.long, when=longCondition and time >= start_time )⋯net_profit = strategy.netprofit + strategy.openprofit-plot(net_profit, title="Net Profit", linewidth=2, style=plot.style_area, transp=50, color=net_profit >= 0 ? #26A69A : color.red)+plot(net_profit, title="Net Profit", linewidth=2, style=plot.style_area, color=color.new(net_profit >= 0 ? #26A69A : color.red, 50))Clean v5
VerifiedSame 84 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 22: when = longCondition and time >= start_time → if block
- Line 23: when = shortCondition → if block
- Line 25: when = shortCondition and time>=start_time → if block
- Line 26: when = longCondition → if block
⋯longCondition = ta.crossover(ta.sma(close,7),ta.sma(close,14))-strategy.entry("Buy", strategy.long, when=longCondition and time >= start_time )+if longCondition and time >= start_time+ strategy.entry("Buy", strategy.long )-strategy.close("Buy", when=shortCondition)+if shortCondition+ strategy.close("Buy")strategy.exit("Close Buy","Buy", limit= stop_loss_and_tp?strategy.position_avg_price * (1+buy_tp):na, stop = stop_loss_and_tp?strategy.position_avg_price * (1-buy_stop_loss):na,trail_price=trail_stop?strategy.position_avg_price *trail_stop_long:na,trail_offset=trail_stop?-strategy.position_avg_price *trail_stop_long_offset:na)-strategy.entry("Sell", strategy.short, when=shortCondition and time>=start_time)+if shortCondition and time>=start_time+ strategy.entry("Sell", strategy.short)-strategy.close("Sell", when=longCondition)+if longCondition+ strategy.close("Sell")strategy.exit("Close Sell","Sell", limit= stop_loss_and_tp?strategy.position_avg_price * (1-sell_tp):na, stop = stop_loss_and_tp?strategy.position_avg_price * (1+sell_stop_loss):na,trail_price=trail_stop?strategy.position_avg_price *trail_stop_short:na,trail_offset=trail_stop?strategy.position_avg_price *trail_stop_short_offset:na)⋯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: 84 before, 65 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.
-//@version=5+//@version=6// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯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 |
|---|---|---|---|
| backtest_year | 2019 | int (written input.integer) | start_time |
| backtest_month | 01 | int (written input.integer) · min 1 · max 12 | start_time |
| backtest_day | 01 | int (written input.integer) · min 1 · max 31 | start_time |
| Enable Stop Loss and Take Profit | true | bool | exit Close Buy exit Close Sell |
| Enable Trail Stop | true | bool | exit Close Buy exit Close Sell |
| buy_stop_loss | 0.2 | float | exit Close Buy |
| sell_stop_loss | 0.1 | float | exit Close Sell |
| buy_tp | 0.4 | float | exit Close Buy |
| sell_tp | 0.2 | float | exit Close Sell |
| trail_stop_long | 1.1 | float | exit Close Buy |
| trail_stop_short | 0.9 | float | exit Close Sell |
| trail_stop_long_offset | 0.05 | float | exit Close Buy |
| trail_stop_short_offset | 0.05 | float | exit Close Sell |
What it calculates
- Crossunder / SMA (
crossunder,ta.crossunderin v5)sma(close,7), sma(close,14)shortCondition · line 20 - Crossover / SMA (
crossover,ta.crossoverin v5)sma(close,7), sma(close,14)longCondition · line 21
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 Buy long | longCondition and time >= start_time | On | 22 |
| Close Buy | shortCondition | On | 23 |
| Exit Close Buy stop and limit | every bar | On | 24 |
| Open Sell short | shortCondition and time>=start_time | On | 25 |
| Close Sell | longCondition | On | 26 |
| Exit Close Sell stop and limit | every bar | On | 27 |
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 | +31.8% | +102.5% | 84 | 40% | 1.15 | 42.9% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −3.8% | +5.5% | 79 | 37% | 0.95 | 22.3% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −40.1% | +9.8% | 83 | 41% | 0.84 | 69.7% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −17.2% | +8.4% | 85 | 32% | 0.84 | 41.8% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +110.2% | +16.7% | 81 | 52% | 1.29 | 41.4% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +16.6% | +21.5% | 73 | 37% | 1.13 | 33.5% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +21.7% | +148.3% | 76 | 46% | 1.11 | 54.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +16.3% | +17.1% | 71 | 32% | 1.25 | 9.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 33 | 27% | −$47,486.70 |
| Sideways market | 33 | 55% | $55,521.80 |
| Falling market | 18 | 39% | $23,790.80 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
54.4%
The 95th percentile of the worst drawdown when the same 84 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 27.7% to 54.4%; the tick is what actually happened, 42.2%. Order luck alone moves it this much.
All 84 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 20 Mar 2024 61,937.40 | 21 Mar 2024 68,131.20 | 1 | −$10,000.00 |
| long | 29 Mar 2024 70,780.60 | 6 Apr 2024 67,820.60 stop | 8 | −$3,763.70 |
| short | 6 Apr 2024 67,820.60 | 11 Apr 2024 70,631.10 | 5 | −$3,573.58 |
| long | 11 Apr 2024 70,631.10 | 16 Apr 2024 63,420.00 stop | 5 | −$8,439.46 |
| short | 16 Apr 2024 63,420.00 | 16 Apr 2024 63,455.30 | 0 | −$41.34 |
| long | 26 Apr 2024 64,498.30 | 1 May 2024 60,672.00 stop | 5 | −$4,400.79 |
| short | 1 May 2024 60,672.00 | 1 May 2024 56,585.10 | 0 | $4,700.54 |
| long | 10 May 2024 63,074.00 | 15 May 2024 61,577.50 stop | 5 | −$1,767.17 |
| short | 15 May 2024 61,577.50 | 16 May 2024 66,206.50 | 1 | −$5,466.23 |
| long | 16 May 2024 66,206.50 | 17 May 2024 65,235.20 stop | 1 | −$986.58 |
| short | 17 May 2024 65,235.20 | 18 May 2024 67,024.00 | 1 | −$1,816.94 |
| long | 18 May 2024 67,024.00 | 1 Jun 2024 67,540.00 limit | 14 | $496.15 |
| short | 1 Jun 2024 67,540.00 | 6 Jun 2024 71,108.00 | 5 | −$3,430.68 |
| long | 6 Jun 2024 71,108.00 | 14 Jun 2024 66,773.00 stop | 8 | −$3,749.87 |
| short | 14 Jun 2024 66,773.00 | 24 Jun 2024 58,435.40 | 10 | $7,212.25 |
| long | 16 Jul 2024 64,724.10 | 3 Aug 2024 61,498.30 stop | 18 | −$3,238.10 |
| short | 3 Aug 2024 61,498.30 | 5 Aug 2024 49,198.70 | 2 | $12,346.90 |
| long | 15 Aug 2024 58,683.40 | 21 Aug 2024 59,013.80 limit | 6 | $417.11 |
| short | 21 Aug 2024 59,013.80 | 23 Aug 2024 60,375.80 | 2 | −$1,719.41 |
| long | 23 Aug 2024 60,375.80 | 23 Aug 2024 64,944.70 | 0 | $5,507.46 |
| short | 1 Sep 2024 58,974.00 | 6 Sep 2024 52,579.50 | 5 | $8,488.55 |
| long | 15 Sep 2024 59,993.00 | 27 Sep 2024 66,022.30 | 12 | $8,720.90 |
| short | 4 Oct 2024 60,752.70 | 14 Oct 2024 62,870.00 | 10 | −$3,328.14 |
| long | 14 Oct 2024 62,870.00 | 20 Oct 2024 69,188.50 | 6 | $9,262.87 |
| short | 28 Oct 2024 68,021.70 | 30 Oct 2024 72,736.40 | 2 | −$7,030.36 |
| long | 30 Oct 2024 72,736.40 | 11 Nov 2024 80,370.00 | 12 | $9,907.20 |
| short | 2 Dec 2024 97,185.20 | 4 Dec 2024 95,849.70 | 2 | $1,433.35 |
| long | 4 Dec 2024 95,849.70 | 17 Dec 2024 106,059.00 | 13 | $11,262.50 |
| short | 23 Dec 2024 95,186.30 | 6 Jan 2025 98,363.60 | 14 | −$3,905.59 |
| long | 6 Jan 2025 98,363.60 | 13 Jan 2025 94,545.10 stop | 7 | −$4,390.53 |
| short | 13 Jan 2025 94,545.10 | 17 Jan 2025 104,000.00 | 4 | −$10,870.70 |
| long | 18 Jan 2025 104,077.00 | 31 Jan 2025 104,723.00 limit | 13 | $606.76 |
| short | 31 Jan 2025 104,723.00 | 3 Feb 2025 91,283.40 | 3 | $12,633.70 |
| long | 19 Feb 2025 95,671.70 | 20 Feb 2025 96,644.40 limit | 1 | $1,129.24 |
| short | 20 Feb 2025 96,644.40 | 21 Feb 2025 98,305.00 | 1 | −$1,928.04 |
| long | 21 Feb 2025 98,305.00 | 22 Feb 2025 96,182.00 stop | 1 | −$2,381.60 |
| short | 22 Feb 2025 96,182.00 | 25 Feb 2025 86,099.10 | 3 | $11,311.00 |
| long | 9 Mar 2025 86,222.50 | 10 Mar 2025 80,734.50 stop | 1 | −$7,587.45 |
| short | 10 Mar 2025 80,734.50 | 10 Mar 2025 77,503.00 | 0 | $4,467.68 |
| long | 21 Mar 2025 84,223.40 | 1 Apr 2025 82,550.00 stop | 11 | −$2,306.47 |
| short | 1 Apr 2025 82,550.00 | 16 Apr 2025 83,644.00 | 15 | −$1,507.88 |
| long | 16 Apr 2025 83,644.00 | 23 Apr 2025 93,443.00 | 7 | $13,153.00 |
| short | 1 Jun 2025 104,592.00 | 11 Jun 2025 110,274.00 | 10 | −$6,814.46 |
| long | 11 Jun 2025 110,274.00 | 19 Jun 2025 104,887.00 stop | 8 | −$5,794.94 |
| short | 19 Jun 2025 104,887.00 | 28 Jun 2025 107,048.00 | 9 | −$2,324.16 |
| long | 28 Jun 2025 107,048.00 | 11 Jul 2025 117,806.00 | 13 | $11,104.50 |
| short | 25 Jul 2025 118,341.00 | 28 Jul 2025 119,416.00 | 3 | −$1,104.15 |
| long | 28 Jul 2025 119,416.00 | 30 Jul 2025 117,951.00 stop | 2 | −$1,478.03 |
| short | 30 Jul 2025 117,951.00 | 11 Aug 2025 119,294.00 | 12 | −$1,355.64 |
| long | 11 Aug 2025 119,294.00 | 20 Aug 2025 112,873.00 stop | 9 | −$6,333.35 |
| short | 20 Aug 2025 112,873.00 | 8 Sep 2025 111,137.00 | 19 | $1,711.82 |
| long | 8 Sep 2025 111,137.00 | 24 Sep 2025 111,999.00 limit | 16 | $876.18 |
| short | 24 Sep 2025 111,999.00 | 3 Oct 2025 120,529.00 | 9 | −$8,676.44 |
| long | 3 Oct 2025 120,529.00 | 3 Oct 2025 123,255.00 | 0 | $2,379.57 |
| short | 13 Oct 2025 114,959.00 | 27 Oct 2025 114,559.00 | 14 | $373.89 |
| long | 27 Oct 2025 114,559.00 | 4 Nov 2025 106,583.00 stop | 8 | −$7,519.04 |
| short | 4 Nov 2025 106,583.00 | 4 Nov 2025 99,001.60 | 0 | $7,146.73 |
| long | 1 Dec 2025 90,360.00 | 16 Dec 2025 86,432.10 stop | 15 | −$4,678.17 |
| short | 16 Dec 2025 86,432.10 | 26 Dec 2025 87,225.30 | 10 | −$944.69 |
| long | 26 Dec 2025 87,225.30 | 30 Dec 2025 87,237.10 limit | 4 | $13.87 |
| short | 30 Dec 2025 87,237.10 | 31 Dec 2025 88,485.50 | 1 | −$1,459.77 |
| long | 31 Dec 2025 88,485.50 | 1 Jan 2026 87,648.20 stop | 1 | −$951.45 |
| short | 1 Jan 2026 87,648.20 | 3 Jan 2026 89,995.10 | 2 | −$2,666.92 |
| long | 3 Jan 2026 89,995.10 | 23 Jan 2026 89,559.70 stop | 20 | −$469.02 |
| short | 23 Jan 2026 89,559.70 | 31 Jan 2026 75,764.70 | 8 | $14,858.30 |
| long | 4 Mar 2026 68,338.00 | 17 Mar 2026 75,206.00 | 13 | $11,187.80 |
| short | 24 Mar 2026 70,906.40 | 8 Apr 2026 71,924.20 | 15 | −$1,758.45 |
| long | 8 Apr 2026 71,924.20 | 22 Apr 2026 79,152.60 | 14 | $12,135.40 |
| short | 4 May 2026 78,568.60 | 6 May 2026 80,905.50 | 2 | −$3,952.56 |
| long | 6 May 2026 80,905.50 | 18 May 2026 77,457.70 stop | 12 | −$5,494.60 |
| short | 18 May 2026 77,457.70 | 2 Jun 2026 66,231.70 | 15 | $17,889.90 |
| long | 16 Jun 2026 66,328.70 | 24 Jun 2026 62,734.60 stop | 8 | −$7,658.20 |
| short | 24 Jun 2026 62,734.60 | 24 Jun 2026 59,135.90 | 0 | $7,667.87 |
| long | 6 Jul 2026 63,650.00 | 29 Jul 2026 63,915.00 limit | 23 | $588.42 |
| short | 29 Jul 2026 63,915.00 | 9 Aug 2026 64,962.60 | 11 | −$2,326.25 |
| long | 9 Aug 2026 64,962.60 | 15 Aug 2026 63,043.60 stop | 6 | −$4,123.89 |
| short | 15 Aug 2026 63,043.60 | 19 Aug 2026 69,347.90 | 4 | −$13,547.70 |
| long | 20 Aug 2026 69,334.80 | 22 Aug 2026 78,338.00 | 2 | $15,832.70 |
| short | 4 Sep 2026 81,270.40 | 5 Sep 2026 79,660.80 | 1 | $2,728.43 |
| long | 5 Sep 2026 79,660.80 | 12 Sep 2026 77,225.70 stop | 7 | −$4,294.48 |
| short | 12 Sep 2026 77,225.70 | 21 Sep 2026 81,178.00 | 9 | −$6,970.29 |
| long | 21 Sep 2026 81,178.00 | 22 Sep 2026 86,620.00 | 1 | $8,662.98 |
| short | 4 Oct 2026 84,753.60 | 6 Oct 2026 85,766.90 | 2 | −$1,648.57 |
| long | 6 Oct 2026 85,766.90 | 11 Oct 2026 82,988.40 stop | 5 | −$4,413.64 |
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 |
|---|---|---|---|---|---|
| Strategy Template[Benson] this page | — | v4 strategy | +31.8% | 84 | 42.9% |
| Follow the Crypto Shorts by xtradernet | sma | v4 strategy | No trades on this market | ||
| buy down and sell high trend 200 sma and ma cross by willi130503 | sma | v4 strategy | No trades on this market | ||
| Mayer Multiple Strategy by xtradernet | sma | v4 strategy | No trades on this market | ||
| Moving Average Cross Strategy early Closing by Geduldtrader | sma | v4 strategy | +73.8% | 20 | 151.5% |
| MFI Simple Strategy by OztheWoz | sma | v5 strategy | −0.2% | 28 | 3.2% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 12 ms | Yes 1,000 bars in 46 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.
//@version=4// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © bensonsuntwstrategy("Strategy Template[Benson]", pyramiding=1, default_qty_type=strategy.percent_of_equity, default_qty_value=100)backtest_year = input(2019, type=input.integer, title='backtest_year')backtest_month = input(01, type=input.integer, title='backtest_month', minval=1, maxval=12)backtest_day = input(01, type=input.integer, title='backtest_day', minval=1, maxval=31)start_time = timestamp(backtest_year, backtest_month, backtest_day, 00, 00)stop_loss_and_tp = input(title="Enable Stop Loss and Take Profit", type=input.bool, defval=true)trail_stop = input(title="Enable Trail Stop", type=input.bool, defval=true)buy_stop_loss = input(0.2, type=input.float, title='buy_stop_loss')sell_stop_loss = input(0.1, type=input.float, title='sell_stop_loss')buy_tp = input(0.4, type=input.float, title='buy_tp')sell_tp =input(0.2, type=input.float, title='sell_tp')trail_stop_long = input(1.1, type=input.float, title='trail_stop_long')trail_stop_short = input(0.9, type=input.float, title='trail_stop_short')trail_stop_long_offset = input(0.05, type=input.float, title='trail_stop_long_offset')trail_stop_short_offset = input(0.05, type=input.float, title='trail_stop_short_offset')// you can set your own logic hereshortCondition = crossunder(sma(close,7),sma(close,14))longCondition = crossover(sma(close,7),sma(close,14))strategy.entry("Buy", strategy.long, when=longCondition and time >= start_time )strategy.close("Buy", when=shortCondition)strategy.exit("Close Buy","Buy", limit= stop_loss_and_tp?strategy.position_avg_price * (1+buy_tp):na, stop = stop_loss_and_tp?strategy.position_avg_price * (1-buy_stop_loss):na,trail_price=trail_stop?strategy.position_avg_price *trail_stop_long:na,trail_offset=trail_stop?-strategy.position_avg_price *trail_stop_long_offset:na)strategy.entry("Sell", strategy.short, when=shortCondition and time>=start_time)strategy.close("Sell", when=longCondition)strategy.exit("Close Sell","Sell", limit= stop_loss_and_tp?strategy.position_avg_price * (1-sell_tp):na, stop = stop_loss_and_tp?strategy.position_avg_price * (1+sell_stop_loss):na,trail_price=trail_stop?strategy.position_avg_price *trail_stop_short:na,trail_offset=trail_stop?strategy.position_avg_price *trail_stop_short_offset:na)net_profit = strategy.netprofit + strategy.openprofitplot(net_profit, title="Net Profit", linewidth=2, style=plot.style_area, transp=50, color=net_profit >= 0 ? #26A69A : color.red)