Pine Script v5 · Strategy
Astor SMA20-60
A Pine Script v5 strategy built on SMA (close, 10), Crossover or SMA (close, close, 20) and Crossunder or SMA (close, close, 20). It has 4 order rules, 2 entries among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 3 settings; defaults include backtest_year 2018, 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 Astor SMA20-60 repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 15 of 15 trades.
- How did Astor SMA20-60 do on BTCUSDT 1D with default settings?
- +0.22%
- From 26 Jan 2024 to 21 Oct 2026, over 50 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Astor SMA20-60 run in Pine Script v6?
- Yes
- Same 50 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 Astor SMA20-60 use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Astor SMA20-60 run in Zeal Terminal?
- Yes
- It compiles in 33 ms and runs 1,000 bars in 41 ms, in the browser.
BTCUSDT · 1D · default settings
- sma(20)
- sma(60)
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +0.22%
- $2,177.44
- Buy and hold
- +102.5%
- same period
- Closed trades
- 50
- 13 won · 37 lost
- Profitable
- 26.0%
- of closed trades
- Profit factor
- 1.26
- gross profit ÷ gross loss
- Max drawdown
- 0.30%
- −$2,966.03
One run with the author's default settings, $1,000,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
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.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
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 | 2018 | int | start_time |
| backtest_month | 01 | int · min 1 · max 12 | start_time |
| backtest_day | 01 | int · min 1 · max 31 | start_time |
What it calculates
- SMAclose, 10
sma10 · line 10 - SMAclose, 20
sma20 · line 11 - SMAclose, 60
sma60 · line 12 - Crossover / SMAclose, ta.sma(close, 20)
longCondition · line 17 - Crossunder / SMAclose, ta.sma(close, 20)
shortCondition · line 20 - Crossover / SMAclose, ta.sma(close, 60)
longCondition1 · line 24 - Crossunder / SMAclose, ta.sma(close, 60)
shortCondition1 · line 27
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 open long20 long | (longCondition) and time >=start_time | On | 19 |
| Close open long20 | (shortCondition) and time >=start_time | On | 22 |
| Open open long60 long | (longCondition1) and time >=start_time | On | 26 |
| Close open long60 | (shortCondition1) and time >=start_time | On | 29 |
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 | +0.2% | +102.5% | 50 | 26% | 1.26 | 0.3% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −0.0% | +5.5% | 54 | 17% | 0.92 | 0.1% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.0% | +9.8% | 49 | 20% | 1.06 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.0% | +8.4% | 81 | 11% | 0.67 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.0% | +16.7% | 54 | 28% | 1.16 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −0.0% | +21.5% | 66 | 17% | 0.96 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +0.0% | +148.3% | 52 | 37% | 1.60 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.0% | +17.1% | 63 | 27% | 1.07 | 0.0% | 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 | 15 | 27% | −$948.19 |
| Sideways market | 22 | 27% | $1,621.08 |
| Falling market | 13 | 23% | $1,504.56 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
0.5%
The 95th percentile of the worst drawdown when the same 50 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 0.2% to 0.5%; the tick is what actually happened, 0.3%. Order luck alone moves it this much.
All 50 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 18 Mar 2024 68,393.50 | 20 Mar 2024 61,937.40 | 2 | −$645.61 |
| long | 21 Mar 2024 67,840.50 | 22 Mar 2024 65,501.30 | 1 | −$233.92 |
| long | 26 Mar 2024 69,880.00 | 3 Apr 2024 65,464.00 | 8 | −$441.60 |
| long | 5 Apr 2024 68,487.80 | 13 Apr 2024 67,116.50 | 8 | −$137.13 |
| long | 15 Apr 2024 65,661.90 | 16 Apr 2024 63,420.00 | 1 | −$224.19 |
| long | 23 Apr 2024 66,819.30 | 24 Apr 2024 66,414.00 | 1 | −$40.53 |
| long | 5 May 2024 63,892.00 | 7 May 2024 63,165.20 | 2 | −$72.69 |
| long | 14 May 2024 62,940.10 | 15 May 2024 61,577.50 | 1 | −$136.26 |
| long | 16 May 2024 66,206.50 | 12 Jun 2024 67,314.20 | 27 | $110.77 |
| long | 15 Jul 2024 60,797.90 | 1 Aug 2024 64,628.00 | 17 | $383.01 |
| long | 22 Aug 2024 61,156.00 | 28 Aug 2024 59,415.00 | 6 | −$174.10 |
| long | 14 Sep 2024 60,498.00 | 2 Oct 2024 60,804.90 | 18 | $30.69 |
| long | 12 Oct 2024 62,540.00 | 9 Jan 2025 95,060.60 | 89 | $3,252.06 |
| long | 15 Jan 2025 96,560.90 | 2 Feb 2025 100,636.00 | 18 | $407.48 |
| long | 4 Feb 2025 101,329.00 | 5 Feb 2025 97,763.10 | 1 | −$356.54 |
| long | 21 Feb 2025 98,305.00 | 22 Feb 2025 96,182.00 | 1 | −$212.30 |
| long | 3 Mar 2025 94,270.00 | 4 Mar 2025 86,221.20 | 1 | −$804.88 |
| long | 20 Mar 2025 86,845.90 | 21 Mar 2025 84,223.40 | 1 | −$262.25 |
| long | 24 Mar 2025 86,082.50 | 30 Mar 2025 82,648.50 | 6 | −$343.40 |
| long | 2 Apr 2025 85,158.40 | 3 Apr 2025 82,516.30 | 1 | −$264.21 |
| long | 12 Apr 2025 83,423.80 | 30 May 2025 105,590.00 | 48 | $2,216.59 |
| long | 10 Jun 2025 110,263.00 | 13 Jun 2025 105,672.00 | 3 | −$459.13 |
| long | 17 Jun 2025 106,795.00 | 18 Jun 2025 104,551.00 | 1 | −$224.34 |
| long | 24 Jun 2025 105,334.00 | 30 Jul 2025 117,951.00 | 36 | $1,261.68 |
| long | 8 Aug 2025 117,472.00 | 9 Aug 2025 116,675.00 | 1 | −$79.73 |
| long | 11 Aug 2025 119,294.00 | 19 Aug 2025 116,227.00 | 8 | −$306.72 |
| long | 23 Aug 2025 116,936.00 | 24 Aug 2025 115,438.00 | 1 | −$149.79 |
| long | 9 Sep 2025 112,065.00 | 23 Sep 2025 112,651.00 | 14 | $58.58 |
| long | 30 Sep 2025 114,312.00 | 1 Oct 2025 114,049.00 | 1 | −$26.30 |
| long | 2 Oct 2025 118,595.00 | 11 Oct 2025 112,774.00 | 9 | −$582.05 |
| long | 13 Oct 2025 114,959.00 | 15 Oct 2025 113,028.00 | 2 | −$193.07 |
| long | 27 Oct 2025 114,559.00 | 30 Oct 2025 110,021.00 | 3 | −$453.81 |
| long | 3 Nov 2025 110,541.00 | 4 Nov 2025 106,583.00 | 1 | −$395.76 |
| long | 3 Dec 2025 91,277.90 | 6 Dec 2025 89,330.00 | 3 | −$194.78 |
| long | 8 Dec 2025 90,395.30 | 13 Dec 2025 90,268.40 | 5 | −$12.69 |
| long | 31 Dec 2025 88,485.50 | 1 Jan 2026 87,648.20 | 1 | −$83.73 |
| long | 2 Jan 2026 88,839.10 | 21 Jan 2026 88,427.70 | 19 | −$41.14 |
| long | 3 Mar 2026 68,830.10 | 8 Mar 2026 67,262.90 | 5 | −$156.72 |
| long | 10 Mar 2026 68,432.20 | 20 Mar 2026 69,930.00 | 10 | $149.78 |
| long | 21 Mar 2026 70,510.70 | 22 Mar 2026 68,918.10 | 1 | −$159.26 |
| long | 24 Mar 2026 70,906.40 | 27 Mar 2026 68,820.30 | 3 | −$208.61 |
| long | 6 Apr 2026 69,034.20 | 16 May 2026 79,113.20 | 40 | $1,007.90 |
| long | 21 Jun 2026 64,298.00 | 22 Jun 2026 63,312.00 | 1 | −$98.60 |
| long | 23 Jun 2026 64,020.00 | 24 Jun 2026 62,734.60 | 1 | −$128.54 |
| long | 4 Jul 2026 62,583.30 | 25 Jul 2026 64,140.00 | 21 | $155.67 |
| long | 26 Jul 2026 64,375.00 | 28 Jul 2026 63,755.90 | 2 | −$61.91 |
| long | 29 Jul 2026 63,915.00 | 1 Aug 2026 62,887.90 | 3 | −$102.71 |
| long | 3 Aug 2026 63,570.00 | 13 Aug 2026 63,480.00 | 10 | −$9.00 |
| long | 18 Aug 2026 64,532.10 | 10 Sep 2026 78,306.40 | 23 | $1,377.43 |
| long | 19 Sep 2026 80,883.90 | 8 Oct 2026 83,321.80 | 19 | $243.79 |
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 |
|---|---|---|---|---|---|
| Astor SMA20-60 this page | — | v5 strategy | +0.2% | 50 | 0.3% |
| 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% |
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.
- 1 setting uses the untyped input() (line 5). 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 50 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 5: input() → input.int()
⋯strategy("Astor SMA20/60", overlay=true, margin_long=100, margin_short=100)-backtest_year = input(2018, title='backtest_year') //回測開始年分+backtest_year = input.int(2018, title='backtest_year') //回測開始年分backtest_month = input.int(01, title='backtest_month', minval=1, maxval=12) //回測開始月份⋯Does it run in Pine Script v6?
Yes
Same 50 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.
⋯// © Astorhsu-//@version=5+//@version=6strategy("Astor SMA20/60", overlay=true, margin_long=100, margin_short=100)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 33 ms | Yes 1,000 bars in 41 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/// © Astorhsu//@version=5strategy("Astor SMA20/60", overlay=true, margin_long=100, margin_short=100)backtest_year = input(2018, title='backtest_year') //回測開始年分backtest_month = input.int(01, title='backtest_month', minval=1, maxval=12) //回測開始月份backtest_day = input.int(01, title='backtest_day', minval=1, maxval=31) //回測開始日期start_time = timestamp(backtest_year, backtest_month, backtest_day, 00, 00) //回測開始的時間函數//Indicatorssma10 = ta.sma(close,10)sma20 = ta.sma(close,20)sma60 = ta.sma(close,60)plot(sma20, color=color.green, title="sma(20)")plot(sma60, color=color.red, title="sma(60)")//進場條件// trend1 = sma60 > sma20 //假設目前趨勢為60>20longCondition = ta.crossover(close, ta.sma(close, 20))if (longCondition) and time >=start_time strategy.entry("open long20", strategy.long, qty=0.1, comment="站上m20做多")shortCondition = ta.crossunder(close, ta.sma(close, 20))if (shortCondition) and time >=start_time strategy.close("open long20",comment="跌破m20平倉", qty=0.1) longCondition1 = ta.crossover(close, ta.sma(close, 60))if (longCondition1) and time >=start_time strategy.entry("open long60", strategy.long, qty=0.1, comment="站上m60做多")shortCondition1 = ta.crossunder(close, ta.sma(close, 60))if (shortCondition1) and time >=start_time strategy.close("open long60",comment="跌破m60平倉", qty=0.1) // longCondition2 = ta.crossover(close, ta.sma(close, 10))// if (longCondition2) // strategy.entry("open long10", strategy.long, qty=0.1, comment="站上m10做多")// shortCondition2 = ta.crossunder(close, ta.sma(close, 10))// if (shortCondition2)// strategy.close("open long10",comment="跌破m10平倉", qty=0.1)