Pine Script v5 · Strategy
Boftei's Strategy
A Pine Script v5 strategy built on Crossover (y, 0), Crossunder (y, 0.0065) and EMA (close, 21). It has 16 order rules, 4 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays no commission. 15 settings; defaults include strategy direction all, Backtest Start Year 2005 and Backtest Start Month 7.
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 Boftei's Strategy repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 2 of 2 trades.
- How did Boftei's Strategy do on BTCUSDT 1D with default settings?
- −32.18%
- From 26 Jan 2024 to 21 Oct 2026, over 30 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Boftei's Strategy run in Pine Script v6?
- Yes
- Same 30 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. The v6 script can be downloaded below.
- Does Boftei's Strategy use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Boftei's Strategy run in Zeal Terminal?
- Yes
- It compiles in 52 ms and runs 1,000 bars in 87 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Plot
- buy
- zero
- sell
- long retry
- overbought
- oversold
- short retry
- too low to short - an asset may die
- Plot
- Plot
- Plot
- Plot
- Plot
- Net profit
- −32.18%
- −$12.87
- Buy and hold
- +102.5%
- same period
- Closed trades
- 30
- 5 won · 25 lost
- Profitable
- 16.7%
- of closed trades
- Profit factor
- 0.37
- gross profit ÷ gross loss
- Max drawdown
- 38.32%
- −$15.65
One run with the author's default settings, $40 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
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
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.
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 |
|---|---|---|---|
| strategy direction | all | string · options ["long", "short", "all"] | strat_dir_value |
| Backtest Start Year | 2005 | int | testPeriodStart |
| Backtest Start Month | 7 | int | testPeriodStart |
| Backtest Start Day | 16 | int | testPeriodStart |
| Backtest Stop Year | 2030 | int | testPeriodStop |
| Backtest Stop Month | 12 | int | testPeriodStop |
| Backtest Stop Day | 30 | int | testPeriodStop |
| sell level | 0.0065 | float | cu sell |
| buy level | 0 | float | co buy |
| long retry - too low | -0.493 | float | retry_long long retry |
| long close up | 2.2 | float | deadline_long_up overbought |
| long close down | -1.5 | float | deadline_long_down oversold |
| short retry - too high | 0.8 | float | retry_short short retry |
| dead - close the short | -5 | float | deadline_short too low to short - an asset may die |
| Histogram Period | 60 | int | y |
What it calculates
- Crossovery, buy level (0)
co · line 44 - Crossundery, sell level (0.0065)
cu · line 45 - Crossundery, long retry - too low (-0.493)
retry_long · line 46 - Crossovery, long close up (2.2)
deadline_long_up · line 47 - Crossundery, long close down (-1.5)
deadline_long_down · line 48 - Crossovery, short retry - too high (0.8)
retry_short · line 49 - Crossundery, dead - close the short (-5)
deadline_short · line 50 - EMAclose, 21
ema_21 · line 60 - EMAclose, 55
ema_55 · line 61 - EMAclose, 89
ema_89 · line 62 - EMAclose, 144
ema_144 · line 63 - EMAclose, 233
ema_233 · line 64
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.
The script has 64 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Close OH BRO | (co and testPeriod() and (g_v == 3 or y_v == 2)) | On | 82 |
| Close OH DUDE | (co and testPeriod() and (g_v == 3 or y_v == 2)) | On | 83 |
| Open OH DAMN long | (co and testPeriod() and (g_v == 3 or y_v == 2)) | On | 84 |
| Close OH DAMN | (retry_long and testPeriod() and (g_v == 3 or y_v == 2)) | On | 86 |
| Open OH BRUH long | (retry_long and testPeriod() and (g_v == 3 or y_v == 2)) | On | 87 |
| Close OH DAMN | (cu and testPeriod() and (r_v == -2 or y_v == 2)) | On | 90 |
| Close OH BRUH | (cu and testPeriod() and (r_v == -2 or y_v == 2)) | On | 91 |
| Open OH BRO short | (cu and testPeriod() and (r_v == -2 or y_v == 2)) | On | 92 |
| Close OH BRO | (retry_short and testPeriod() and (r_v == -2 or y_v == 2)) | On | 94 |
| Open OH DUDE short | (retry_short and testPeriod() and (r_v == -2 or y_v == 2)) | On | 95 |
| Close OH DAMN | (deadline_long_up and testPeriod() or r_v == -2 and testPeriod()) | On | 99 |
| Close OH BRUH | (deadline_long_up and testPeriod() or r_v == -2 and testPeriod()) | On | 100 |
| Close OH DAMN | (deadline_long_down and testPeriod()) | On | 102 |
| Close OH BRUH | (deadline_long_down and testPeriod()) | On | 103 |
| Close OH BRO | (deadline_short and testPeriod() or g_v == 3 and testPeriod()) | On | 105 |
| Close OH DUDE | (deadline_short and testPeriod() or g_v == 3 and testPeriod()) | On | 106 |
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 | −32.2% | +102.5% | 30 | 17% | 0.37 | 38.3% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +6.2% | +5.5% | 18 | 22% | 1.72 | 6.9% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +18.0% | +9.8% | 21 | 19% | 1.50 | 19.4% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +2.8% | +8.4% | 8 | 25% | 1.44 | 4.9% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −76.0% | +16.7% | 44 | 18% | 0.30 | 77.1% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −7.1% | +21.5% | 11 | 18% | 0.29 | 24.1% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +3.7% | +148.3% | 34 | 9% | 1.06 | 25.3% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −7.0% | +17.1% | 15 | 13% | 0.38 | 10.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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 7 | 14% | −$7.30 |
| Sideways market | 18 | 17% | −$5.75 |
| Falling market | 5 | 20% | $0.18 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
42.7%
The 95th percentile of the worst drawdown when the same 30 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 32.2% to 42.7%; the tick is what actually happened, 36.0%. Order luck alone moves it this much.
All 30 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 5 May 2024 63,892.00 | 17 May 2024 65,235.20 | 12 | $0.84 |
| short | 17 May 2024 65,235.20 | 17 May 2024 67,451.20 | 0 | −$1.39 |
| long | 19 May 2024 66,915.20 | 20 May 2024 66,274.00 | 1 | −$0.38 |
| short | 20 May 2024 66,274.00 | 20 May 2024 71,515.60 | 0 | −$3.09 |
| long | 21 May 2024 71,446.60 | 25 May 2024 68,550.00 | 4 | −$1.46 |
| short | 25 May 2024 68,550.00 | 25 May 2024 69,610.00 | 0 | −$0.53 |
| long | 2 Jun 2024 67,766.80 | 4 Jun 2024 68,809.90 | 2 | $0.52 |
| short | 4 Jun 2024 68,809.90 | 4 Jun 2024 71,063.40 | 0 | −$1.13 |
| short | 8 Jun 2024 69,355.60 | 8 Jun 2024 69,582.20 | 0 | −$0.11 |
| long | 9 Jun 2024 69,310.50 | 20 Jun 2024 64,974.40 | 11 | −$2.08 |
| short | 20 Jun 2024 64,974.40 | 20 Jun 2024 66,482.90 | 0 | −$0.72 |
| long | 30 Jun 2024 60,986.70 | 3 Jul 2024 62,135.50 | 3 | $0.57 |
| short | 3 Jul 2024 62,135.50 | 3 Jul 2024 62,285.90 | 0 | −$0.08 |
| long | 29 Jul 2024 68,249.90 | 30 Jul 2024 66,784.70 | 1 | −$0.66 |
| short | 30 Jul 2024 66,784.70 | 30 Jul 2024 67,000.00 | 0 | −$0.10 |
| long | 24 Aug 2024 64,037.20 | 28 Aug 2024 59,415.00 | 4 | −$2.18 |
| short | 28 Aug 2024 59,415.00 | 28 Aug 2024 60,235.00 | 0 | −$0.39 |
| long | 3 Sep 2024 59,132.10 | 5 Sep 2024 57,970.90 | 2 | −$0.54 |
| short | 5 Sep 2024 57,970.90 | 5 Sep 2024 58,327.10 | 0 | −$0.17 |
| long | 6 Sep 2024 56,180.00 | 15 Sep 2024 59,993.00 | 9 | $1.83 |
| long | 30 Sep 2024 65,602.00 | 1 Oct 2024 63,327.60 | 1 | −$1.00 |
| short | 10 Oct 2024 60,636.00 | 10 Oct 2024 61,321.70 | 0 | −$0.31 |
| long | 4 Feb 2025 101,329.00 | 23 Feb 2025 96,551.00 | 19 | −$1.29 |
| short | 23 Feb 2025 96,551.00 | 23 Feb 2025 96,650.00 | 0 | −$0.03 |
| long | 26 Apr 2025 94,638.70 | 1 Sep 2025 108,246.00 | 128 | $3.76 |
| long | 3 Sep 2025 111,240.00 | 8 Sep 2025 111,137.00 | 5 | −$0.03 |
| short | 26 Oct 2025 111,646.00 | 26 Oct 2025 115,467.00 | 0 | −$1.02 |
| short | 31 Oct 2025 108,323.00 | 31 Oct 2025 111,190.00 | 0 | −$0.76 |
| short | 26 Jan 2026 86,670.40 | 26 Jan 2026 88,860.00 | 0 | −$0.71 |
| short | 11 Aug 2026 63,970.00 | 11 Aug 2026 64,515.40 | 0 | −$0.23 |
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 |
|---|---|---|---|---|---|
| Boftei's Strategy this page | — | v5 strategy | −32.2% | 30 | 38.3% |
| EMA Slope AyE by fajardoarelys | ema | v4 strategy | No trades on this market | ||
| ROoT by realisticDove62527 | ema | v5 strategy | −4.7% | 225 | 9.4% |
| sachin5986 by mohitesachin78 | ema | v4 strategy | +32.1% | 35 | 17.6% |
| sonu1997 by Sonu1997 | ema | v4 strategy | +960.7% | 2 | 1,103.8% |
| Moving Average Crossover by Muh4mm4d | ema | v4 strategy | +19,990.1% | 30 | 1,274.2% |
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.
- 7 settings use the untyped input() (line 10, 11, 12, 15, 16, 17, 30). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Same 30 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 10: input() → input.int()
- Line 11: input() → input.int()
- Line 12: input() → input.int()
- Line 15: input() → input.int()
- Line 16: input() → input.int()
- Line 17: input() → input.int()
- Line 30: input() → input.int()
⋯//DATA-testStartYear = input(2005, "Backtest Start Year")+testStartYear = input.int(2005, "Backtest Start Year")-testStartMonth = input(7, "Backtest Start Month")+testStartMonth = input.int(7, "Backtest Start Month")-testStartDay = input(16, "Backtest Start Day")+testStartDay = input.int(16, "Backtest Start Day")testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)//Stop date if you want to use a specific range of dates-testStopYear = input(2030, "Backtest Stop Year")+testStopYear = input.int(2030, "Backtest Stop Year")-testStopMonth = input(12, "Backtest Stop Month")+testStopMonth = input.int(12, "Backtest Stop Month")-testStopDay = input(30, "Backtest Stop Day")+testStopDay = input.int(30, "Backtest Stop Day")testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)⋯///< botvenko script-nn = input(60, "Histogram Period")+nn = input.int(60, "Histogram Period")float x = 0⋯Does it run in Pine Script v6?
Yes
Same 30 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. Both versions were run on Zeal Terminal's engine, and the results are identical. It differs from the v5 version by 1 edit.
⋯// © boftei-//@version=5+//@version=6strategy("Boftei's Strategy", overlay=false, pyramiding=1, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, margin_long = 100, margin_short = 100, slippage=0, commission_type=strategy.commission.percent, commission_value = 0, initial_capital = 40, precision = 6)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 52 ms | Yes 1,000 bars in 87 ms | Not measured |
| PineTS | Not tested | Not tested | 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.
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/// © boftei//@version=5strategy("Boftei's Strategy", overlay=false, pyramiding=1, default_qty_type= strategy.percent_of_equity, default_qty_value = 100, calc_on_order_fills=false, margin_long = 100, margin_short = 100, slippage=0, commission_type=strategy.commission.percent, commission_value = 0, initial_capital = 40, precision = 6)strat_dir_input = input.string("all", "strategy direction", options=["long", "short", "all"])strat_dir_value = strat_dir_input == "long" ? strategy.direction.long : strat_dir_input == "short" ? strategy.direction.short : strategy.direction.allstrategy.risk.allow_entry_in(strat_dir_value)////////////////////////////////////////////////////////////////////////DATAtestStartYear = input(2005, "Backtest Start Year")testStartMonth = input(7, "Backtest Start Month")testStartDay = input(16, "Backtest Start Day")testPeriodStart = timestamp(testStartYear,testStartMonth,testStartDay,0,0)//Stop date if you want to use a specific range of datestestStopYear = input(2030, "Backtest Stop Year")testStopMonth = input(12, "Backtest Stop Month")testStopDay = input(30, "Backtest Stop Day")testPeriodStop = timestamp(testStopYear,testStopMonth,testStopDay,0,0)testPeriod() => time >= testPeriodStart and time <= testPeriodStop ? true : false//////////////////////////////////////////////////////////////////////sell = input.float(0.0065, "sell level")buy = input.float(0, "buy level")long1 = input.float(-0.493, "long retry - too low")long2 = input.float(2.2, "long close up")long3 = input.float(-1.5, "long close down")short1 = input.float(0.8, "short retry - too high")short2 = input.float(-5, "dead - close the short")///< botvenko scriptnn = input(60, "Histogram Period")float x = 0float z = 0float k = 0y = math.log(close[0]) - math.log(close[nn])if y>0 x := yelse k := y//--------------------------------------------- plot(y > 0 ? x: 0, color = color.green, linewidth = 4)plot(y <= 0 ? k: 0, color = color.maroon, linewidth = 4)plot(y, color = color.yellow, linewidth = 1)co = ta.crossover(y, buy)cu = ta.crossunder(y, sell)retry_long = ta.crossunder(y, long1)deadline_long_up = ta.crossover(y, long2)deadline_long_down = ta.crossunder(y, long3)retry_short = ta.crossover(y, short1)deadline_short = ta.crossunder(y, short2)hline(buy, title='buy', color=color.green, linestyle=hline.style_dotted, linewidth=2)hline(0, title='zero', color=color.white, linestyle=hline.style_dotted, linewidth=1)hline(sell, title='sell', color=color.red, linestyle=hline.style_dotted, linewidth=2)hline(long1, title='long retry', color=color.blue, linestyle=hline.style_dotted, linewidth=2)hline(long2, title='overbought', color=color.teal, linestyle=hline.style_dotted, linewidth=2)hline(long3, title='oversold', color=color.maroon, linestyle=hline.style_dotted, linewidth=2)hline(short1, title='short retry', color=color.purple, linestyle=hline.style_dotted, linewidth=2)hline(short2, title='too low to short - an asset may die', color=color.navy, linestyle=hline.style_dotted, linewidth=2)////////////////////////////////////////////////////////////EMAprotectionBLOCKema_21 = ta.ema(close, 21)ema_55 = ta.ema(close, 55)ema_89 = ta.ema(close, 89)ema_144 = ta.ema(close, 144)ema_233 = ta.ema(close, 233)//ema_377 = ta.ema(close, 377)long_st = ema_21>ema_55 and ema_55>ema_89 and ema_89>ema_144 and ema_144>ema_233// and ema_233>ema_377short_st = ema_21<ema_55 and ema_55<ema_89 and ema_89<ema_144 and ema_144<ema_233// and ema_233<ema_377 g_v = long_st == true?3:0r_v = short_st == true?-2:0y_v = long_st != true and short_st != true?2:0plot(math.log(ema_21), color = color.new(#ffaf5e, 50))plot(math.log(ema_55), color = color.new(#b9ff5e, 50))plot(math.log(ema_89), color = color.new(#5eff81, 50))plot(math.log(ema_144), color = color.new(#5effe4, 50))plot(math.log(ema_233), color = color.new(#5e9fff, 50))//plot(math.log(ema_377), color = color.new(#af5eff, 50))plot(long_st == true?3:0, color = color.new(color.green, 65), linewidth = 5)plot(short_st == true?-2:0, color = color.new(color.red, 65), linewidth = 5)plot(long_st != true and short_st != true?2:0, color = color.new(color.yellow, 65), linewidth = 5)////////////////////////////////////////////////////////////EMAprotectionBLOCKif (co and testPeriod() and (g_v == 3 or y_v == 2)) strategy.close("OH BRO", comment = "EXIT-SHORT") strategy.close("OH DUDE", comment = "EXIT-SHORT") strategy.entry("OH DAMN", strategy.long, comment="ENTER-LONG 'co'")if (retry_long and testPeriod() and (g_v == 3 or y_v == 2)) strategy.close("OH DAMN", comment = "EXIT-LONG") strategy.entry("OH BRUH", strategy.long, comment="ENTER-LONG 'retry_long'") if (cu and testPeriod() and (r_v == -2 or y_v == 2)) strategy.close("OH DAMN", comment = "EXIT-LONG") strategy.close("OH BRUH", comment = "EXIT-LONG") strategy.entry("OH BRO", strategy.short, comment="ENTER-SHORT 'cu'")if (retry_short and testPeriod() and (r_v == -2 or y_v == 2)) strategy.close("OH BRO", comment = "EXIT-SHORT") strategy.entry("OH DUDE", strategy.short, comment="ENTER-SHORT 'retry_short'") if (deadline_long_up and testPeriod() or r_v == -2 and testPeriod()) strategy.close("OH DAMN", comment = "EXIT-LONG 'deadline_long_up'") strategy.close("OH BRUH", comment = "EXIT-LONG 'deadline_long_up'")if (deadline_long_down and testPeriod()) strategy.close("OH DAMN", comment = "EXIT-LONG 'deadline_long_down'") strategy.close("OH BRUH", comment = "EXIT-LONG 'deadline_long_down'")if (deadline_short and testPeriod() or g_v == 3 and testPeriod()) strategy.close("OH BRO", comment = "EXIT-SHORT 'deadline_short'") strategy.close("OH DUDE", comment = "EXIT-SHORT 'deadline_short'") // (you can use strategy.close_all(comment = "close all entries") here)