Pine Script v4 · Strategy
WEEKLY BTC TRADING SCRYPT
A Pine Script v4 strategy built on SMA (btc, 8), Crossover (btc, ma) and Crossunder (btc, ma). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. 8 settings; defaults include source close, COLOR #FF3232 and LINE WIDTH 2.
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 WEEKLY BTC TRADING SCRYPT repaint?
- Yes
- In a live replay, it did not match history on 11 of 11 trades, and it produced 11 trades that history does not have.
- How did WEEKLY BTC TRADING SCRYPT do on BTCUSDT 1D with default settings?
- +17.11%
- From 26 Jan 2024 to 21 Oct 2026, over 37 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can WEEKLY BTC TRADING SCRYPT be converted to Pine Script v5?
- Yes
- The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
- What alerts does WEEKLY BTC TRADING SCRYPT have?
- 2
- BTC buy order trigerred!; BTC sell order trigerred!.
- Does WEEKLY BTC TRADING SCRYPT use a stop loss?
- Yes
- strategy.exit sets a stop on line 23.
BTCUSDT · 1D · default settings
- WEEKLY CLOSE
- SMA8 WEEKLY
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +17.11%
- $17,107.20
- Buy and hold
- +102.5%
- same period
- Closed trades
- 37
- 11 won · 26 lost
- Profitable
- 29.7%
- of closed trades
- Profit factor
- 1.23
- gross profit ÷ gross loss
- Max drawdown
- 24.75%
- −$31,372.30
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 commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
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, 23. The upgraded version below moves each call inside an if block.
-
Note
Uses long =, which v5 renamed line 20
long = on line 20. v5 writes it as direction = strategy.long or strategy.short.
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 security → request.security, sma → ta.sma, crossover → ta.crossover, crossunder → ta.crossunder.
- 2 strategy calls use the when = argument (line 20, 23). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 37 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 5: //@version=4 → //@version=5
- Line 8: security → request.security
- Line 9: sma → ta.sma
- Line 10: crossover → ta.crossover
- Line 11: crossunder → ta.crossunder
- Line 20: long = true → direction = strategy.long
⋯//author: taberandwords-//@version=4+//@version=5strategy("WEEKLY BTC TRADING SCRYPT","WBTS",overlay=false,default_qty_type=strategy.fixed)source=input(defval=close,title="source",group="STRATEGY")-btc=security('BTCUSDT','1W', source)+btc=request.security('BTCUSDT','1W', source)-ma=sma(btc,8)+ma=ta.sma(btc,8)-buy_condition= crossover(btc,ma) +buy_condition= ta.crossover(btc,ma) -sell_condition= crossunder(btc,ma)+sell_condition= ta.crossunder(btc,ma)ma_color=input(defval=#FF3232,title="COLOR",group="MA")⋯if(year>=start_date)- strategy.entry('BUY',long=true,when=buy_condition,alert_message='Price came to buying value!')+ strategy.entry('BUY',direction = strategy.long,when=buy_condition,alert_message='Price came to buying value!') if(strategy.long)⋯Same 37 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 7: input() → input.source()
- Line 12: input() → input.color()
- Line 13: input() → input.int()
- Line 14: input() → input.color()
- Line 15: input() → input.int()
- Line 16: input() → input.int()
4 more edits
- Line 17: input() → input.int()
- Line 18: input() → input.int()
- Line 20: when = buy_condition → if block
- Line 23: when = sell_condition → if block
⋯strategy("WEEKLY BTC TRADING SCRYPT","WBTS",overlay=false,default_qty_type=strategy.fixed)-source=input(defval=close,title="source",group="STRATEGY")+source=input.source(defval=close,title="source",group="STRATEGY")btc=request.security('BTCUSDT','1W', source)⋯sell_condition= ta.crossunder(btc,ma)-ma_color=input(defval=#FF3232,title="COLOR",group="MA")+ma_color=input.color(defval=#FF3232,title="COLOR",group="MA")-ma_linewidth=input(defval=2,title="LINE WIDTH",group="MA")+ma_linewidth=input.int(defval=2,title="LINE WIDTH",group="MA")-graphic_color=input(defval=#6666FF,title="COLOR",group="GRAPHIC")+graphic_color=input.color(defval=#6666FF,title="COLOR",group="GRAPHIC")-graphic_linewidth=input(defval=2,title="LINE WIDTH",group="GRAPHIC")+graphic_linewidth=input.int(defval=2,title="LINE WIDTH",group="GRAPHIC")-start_date=input(defval=2020,title="YEAR",group="STRATEGY EXECUTION YEAR")+start_date=input.int(defval=2020,title="YEAR",group="STRATEGY EXECUTION YEAR")-loss_ratio=input(defval=1,title="LOSS RATIO", group="STRATEGY")+loss_ratio=input.int(defval=1,title="LOSS RATIO", group="STRATEGY")-reward_ratio=input(defval=3,title="REWARD RATIO", group="STRATEGY")+reward_ratio=input.int(defval=3,title="REWARD RATIO", group="STRATEGY")if(year>=start_date)- strategy.entry('BUY',direction = strategy.long,when=buy_condition,alert_message='Price came to buying value!')+ if buy_condition+ strategy.entry('BUY',direction = strategy.long,alert_message='Price came to buying value!') if(strategy.long) alert('BTC buy order trigerred!',alert.freq_once_per_bar)- strategy.exit(id="SELL",loss=loss_ratio,profit=reward_ratio,when=sell_condition,alert_message='Price came to position closing value!')+ if sell_condition+ strategy.exit(id="SELL",loss=loss_ratio,profit=reward_ratio,alert_message='Price came to position closing value!') if(sell_condition)⋯Does it run in Pine Script v6?
Yes
Same 37 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.
⋯//author: taberandwords-//@version=5+//@version=6strategy("WEEKLY BTC TRADING SCRYPT","WBTS",overlay=false,default_qty_type=strategy.fixed)⋯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 | |||
| source | close | source | btc WEEKLY CLOSE |
| LOSS RATIO | 1 | int | exit SELL |
| REWARD RATIO | 3 | int | exit SELL |
| MA | |||
| COLOR | #FF3232 | value | SMA8 WEEKLY |
| LINE WIDTH | 2 | int | SMA8 WEEKLY |
| GRAPHIC | |||
| COLOR | #6666FF | value | WEEKLY CLOSE |
| LINE WIDTH | 2 | int | WEEKLY CLOSE |
| STRATEGY EXECUTION YEAR | |||
| YEAR | 2020 | int | entry BUY exit SELL line 19 |
What it calculates
- SMA (
sma,ta.smain v5)btc, 8ma · line 9 - Crossover (
crossover,ta.crossoverin v5)btc, mabuy_condition · line 10 - Crossunder (
crossunder,ta.crossunderin v5)btc, masell_condition · 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 BUY long | buy_condition | On | 20 |
| Exit SELL stop and limit | sell_condition | On | 23 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| (no title) | alert | BTC buy order trigerred! | 22 |
| (no title) | alert | BTC sell order trigerred! | 25 |
Does it repaint?
Yes
The live replay did not match history.
- ClearHigher-timeframe data1 security call(s), none with lookahead on.
- 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 | +17.1% | +102.5% | 37 | 30% | 1.23 | 24.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −10.2% | +5.5% | 7 | 14% | 0.20 | 13.6% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.2% | +9.8% | 37 | 41% | 1.05 | 2.2% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.4% | +8.4% | 7 | 14% | 0.21 | 0.5% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.0% | +16.7% | 37 | 46% | 0.94 | 0.2% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −0.0% | +21.5% | 7 | 43% | 0.27 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.2% | +148.3% | 37 | 49% | 1.24 | 0.3% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.1% | +17.1% | 7 | 14% | 0.01 | 0.2% | 8 May 2026 – 21 Oct 2026 |
Higher-timeframe data for request.security(): BTCUSDT 1W (Binance BTCUSDT 1w), fetched from Binance's public market data for each market.
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 | 14 | 36% | $15,264.20 |
| Sideways market | 16 | 25% | −$3,982.94 |
| Falling market | 7 | 29% | $5,826.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
33.4%
The 95th percentile of the worst drawdown when the same 37 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 15.8% to 33.4%; the tick is what actually happened, 19.3%. Order luck alone moves it this much.
All 37 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 4 Mar 2024 63,114.00 | 18 Mar 2024 68,393.50 | 14 | $5,279.50 |
| long | 1 Apr 2024 71,280.00 | 8 Apr 2024 69,360.40 | 7 | −$1,919.62 |
| long | 6 May 2024 64,012.00 | 13 May 2024 61,484.00 | 7 | −$2,528.00 |
| long | 20 May 2024 66,274.00 | 3 Jun 2024 67,765.60 | 14 | $1,491.62 |
| long | 10 Jun 2024 69,648.10 | 17 Jun 2024 66,676.90 | 7 | −$2,971.29 |
| long | 15 Jul 2024 60,797.90 | 5 Aug 2024 58,161.00 | 21 | −$2,636.91 |
| long | 12 Aug 2024 58,712.60 | 19 Aug 2024 58,427.30 | 7 | −$285.24 |
| long | 26 Aug 2024 64,220.00 | 2 Sep 2024 57,301.80 | 7 | −$6,918.22 |
| long | 16 Sep 2024 59,132.00 | 7 Oct 2024 62,819.90 | 21 | $3,687.91 |
| long | 14 Oct 2024 62,870.00 | 28 Oct 2024 68,021.70 | 14 | $5,151.67 |
| long | 4 Nov 2024 68,776.00 | 2 Dec 2024 97,185.20 | 28 | $28,409.20 |
| long | 9 Dec 2024 101,110.00 | 23 Dec 2024 95,186.30 | 14 | −$5,923.32 |
| long | 6 Jan 2025 98,363.60 | 13 Jan 2025 94,545.10 | 7 | −$3,818.54 |
| long | 20 Jan 2025 101,332.00 | 3 Feb 2025 97,700.60 | 14 | −$3,630.98 |
| long | 24 Feb 2025 96,258.00 | 3 Mar 2025 94,270.00 | 7 | −$1,988.01 |
| long | 17 Mar 2025 82,574.50 | 31 Mar 2025 82,390.00 | 14 | −$184.52 |
| long | 14 Apr 2025 83,760.00 | 2 Jun 2025 105,643.00 | 49 | $21,882.90 |
| long | 9 Jun 2025 105,734.00 | 16 Jun 2025 105,594.00 | 7 | −$139.99 |
| long | 30 Jun 2025 108,357.00 | 21 Jul 2025 117,265.00 | 21 | $8,908.18 |
| long | 28 Jul 2025 119,416.00 | 4 Aug 2025 114,209.00 | 7 | −$5,206.75 |
| long | 11 Aug 2025 119,294.00 | 18 Aug 2025 117,405.00 | 7 | −$1,889.26 |
| long | 8 Sep 2025 111,137.00 | 22 Sep 2025 115,232.00 | 14 | $4,094.94 |
| long | 6 Oct 2025 123,482.00 | 13 Oct 2025 114,959.00 | 7 | −$8,523.51 |
| long | 27 Oct 2025 114,559.00 | 3 Nov 2025 110,541.00 | 7 | −$4,018.72 |
| long | 1 Dec 2025 90,360.00 | 15 Dec 2025 88,172.20 | 14 | −$2,187.85 |
| long | 22 Dec 2025 88,658.90 | 29 Dec 2025 87,952.70 | 7 | −$706.16 |
| long | 5 Jan 2026 91,529.70 | 12 Jan 2026 91,013.70 | 7 | −$516.08 |
| long | 19 Jan 2026 93,673.10 | 26 Jan 2026 86,670.40 | 7 | −$7,002.78 |
| long | 9 Mar 2026 65,971.20 | 23 Mar 2026 67,859.00 | 14 | $1,887.80 |
| long | 6 Apr 2026 69,034.20 | 4 May 2026 78,568.60 | 28 | $9,534.40 |
| long | 11 May 2026 82,210.10 | 18 May 2026 77,457.70 | 7 | −$4,752.40 |
| long | 15 Jun 2026 65,746.40 | 22 Jun 2026 63,312.00 | 7 | −$2,434.45 |
| long | 6 Jul 2026 63,650.00 | 3 Aug 2026 63,570.00 | 28 | −$80.00 |
| long | 10 Aug 2026 64,901.60 | 17 Aug 2026 62,900.00 | 7 | −$2,001.59 |
| long | 24 Aug 2026 77,734.00 | 31 Aug 2026 77,682.00 | 7 | −$52.00 |
| long | 7 Sep 2026 80,341.80 | 14 Sep 2026 76,842.00 | 7 | −$3,499.82 |
| long | 21 Sep 2026 81,178.00 | 12 Oct 2026 83,773.10 | 21 | $2,595.11 |
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 |
|---|---|---|---|---|---|
| WEEKLY BTC TRADING SCRYPT this page | — | v4 strategy | +17.1% | 37 | 24.7% |
| 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 9 ms | With a workaround 1,000 bars in 33 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as long = true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (line 20) so the engine trades the way the script says. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“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/// © taberandwords//developer: taberandwords//author: taberandwords//@version=4strategy("WEEKLY BTC TRADING SCRYPT","WBTS",overlay=false,default_qty_type=strategy.fixed)source=input(defval=close,title="source",group="STRATEGY")btc=security('BTCUSDT','1W', source)ma=sma(btc,8)buy_condition= crossover(btc,ma) sell_condition= crossunder(btc,ma)ma_color=input(defval=#FF3232,title="COLOR",group="MA")ma_linewidth=input(defval=2,title="LINE WIDTH",group="MA")graphic_color=input(defval=#6666FF,title="COLOR",group="GRAPHIC")graphic_linewidth=input(defval=2,title="LINE WIDTH",group="GRAPHIC")start_date=input(defval=2020,title="YEAR",group="STRATEGY EXECUTION YEAR")loss_ratio=input(defval=1,title="LOSS RATIO", group="STRATEGY")reward_ratio=input(defval=3,title="REWARD RATIO", group="STRATEGY")if(year>=start_date) strategy.entry('BUY',long=true,when=buy_condition,alert_message='Price came to buying value!') if(strategy.long) alert('BTC buy order trigerred!',alert.freq_once_per_bar) strategy.exit(id="SELL",loss=loss_ratio,profit=reward_ratio,when=sell_condition,alert_message='Price came to position closing value!') if(sell_condition) alert('BTC sell order trigerred!',alert.freq_once_per_bar)plot(series=source,title="WEEKLY CLOSE",color=graphic_color,linewidth=graphic_linewidth)plot(ma,title="SMA8 WEEKLY",color=ma_color,linewidth=ma_linewidth)plot(strategy.equity,display=0)