Pine Script v4 · Strategy
Quarterly Returns in Strategies vs Buy & Hold
A Pine Script v4 strategy built on VWMA (hl2, 400), Rising (wma, 5) and Falling (wma, 5). It has 2 order rules, 1 entry among them, and trades long only with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays 0.1% commission. 4 settings; defaults include MA Length 400 and Table Position bottom_right.
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 Quarterly Returns in Strategies vs Buy & Hold repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 1 of 1 trades.
- How did Quarterly Returns in Strategies vs Buy & Hold do on BTCUSDT 1D with default settings?
- +80.23%
- From 26 Jan 2024 to 21 Oct 2026, over 4 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Quarterly Returns in Strategies vs Buy & Hold be converted to Pine Script v5?
- No
- The automatic step from v4 to v5 gives a script that does not run in v5 (Pine Script v5 Error at @L69:C12: No value assigned to the `transp` parameter in color.new()), so no v5 download is offered; the edits are shown below.
- Does Quarterly Returns in Strategies vs Buy & Hold use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Quarterly Returns in Strategies vs Buy & Hold run in Zeal Terminal?
- Yes
- It compiles in 41 ms and runs 1,000 bars in 56 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +80.23%
- $802.34
- Buy and hold
- +102.5%
- same period
- Closed trades
- 4
- 1 won · 3 lost
- Profitable
- 25.0%
- of closed trades
- Profit factor
- 5.16
- gross profit ÷ gross loss
- Max drawdown
- 10.70%
- −$213.42
One run with the author's default settings, $1,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
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
1 setting has no label
In the settings dialog maLength (line 5) shows an empty name. The labels on this page come from the variable names.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses transp =, which v5 removed line 69
transp = on line 69, 71, 73, 76, 78, 80. 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 vwma → ta.vwma, rising → ta.rising, falling → ta.falling, ceil → math.ceil, tostring → str.tostring, round → math.round.
v4 → v5
DiffersThe v5 version does not run in Zeal Terminal's engine: Pine Script v5 Error at @L69:C12: No value assigned to the `transp` parameter in color.new()
- Line 3: //@version=4 → //@version=5
- Line 6: vwma → ta.vwma
- Line 7: rising → ta.rising
- Line 8: falling → ta.falling
- Line 16: input(type = input.bool) → input.bool()
- Line 17: input(type = input.bool) → input.bool()
23 more edits
- Line 18: input(type = input.string) → input.string()
- Line 20: ceil → math.ceil
- Line 20: ceil → math.ceil
- Line 69: transp = 20 removed: the call sets no colour to fold it into, so its default colour loses the transparency
- Line 71: transp = 50 removed: the call sets no colour to fold it into, so its default colour loses the transparency
- Line 73: transp = 80 removed: the call sets no colour to fold it into, so its default colour loses the transparency
- Line 76: transp = 20 removed: the call sets no colour to fold it into, so its default colour loses the transparency
- Line 78: transp = 50 removed: the call sets no colour to fold it into, so its default colour loses the transparency
- Line 80: transp = 80 removed: the call sets no colour to fold it into, so its default colour loses the transparency
- Line 90: tostring → str.tostring
- Line 93: tostring → str.tostring
- Line 93: round → math.round
- Line 93: tostring → str.tostring
- Line 93: round → math.round
- Line 93: tostring → str.tostring
- Line 93: round → math.round
- Line 97: ceil → math.ceil
- Line 100: tostring → str.tostring
- Line 100: round → math.round
- Line 100: tostring → str.tostring
- Line 100: round → math.round
- Line 100: tostring → str.tostring
- Line 100: round → math.round
⋯// © Dannnnnnny-//@version=4+//@version=5strategy(title="Quarterly Returns in Strategies vs Buy & Hold", initial_capital= 1000, overlay=true,default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, commission_value = 0.1)maLength= input(400)-wma= vwma(hl2,maLength)+wma= ta.vwma(hl2,maLength)-uptrend= rising(wma, 5)+uptrend= ta.rising(wma, 5)-downtrend= falling(wma,5)+downtrend= ta.falling(wma,5)plot(wma)⋯// QUARTERLY TABLE //-enableQuarterlyTable = input(title="Enable Quarterly Return table", type=input.bool, defval=false)+enableQuarterlyTable = input.bool(title="Enable Quarterly Return table", defval=false)-enableCompareWithMarket = input(title="Compare with Market Benchmark", type=input.bool, defval=false)+enableCompareWithMarket = input.bool(title="Compare with Market Benchmark", defval=false)-table_position = input(title="Table Position", type=input.string, defval='bottom_right', options=['bottom_right','bottom_left','top_right', 'top_left'])+table_position = input.string(title="Table Position", defval='bottom_right', options=['bottom_right','bottom_left','top_right', 'top_left'])precision = 2-new_quarter = ceil(month(time)/3) != ceil(month(time[1])/3)+new_quarter = math.ceil(month(time)/3) != math.ceil(month(time[1])/3)new_year = year(time) != year(time[1])⋯ if bh < 0 or pnl > 2 * bh- color.new(color.green, transp = 20)+ color.new(color.green) else if pnl > bh- color.new(color.green, transp = 50)+ color.new(color.green) else- color.new(color.green, transp = 80)+ color.new(color.green) else if bh > 0 or pnl < 2 * bh- color.new(color.red, transp = 20)+ color.new(color.red) else if pnl < bh- color.new(color.red, transp = 50)+ color.new(color.red) else- color.new(color.red, transp = 80)+ color.new(color.red)if (end_time and enableQuarterlyTable)⋯ for yi = 0 to array.size(year_pnl) - 1- table.cell(quarterly_table, 0, yi + 1, tostring(year(array.get(year_time, yi))), bgcolor = #cccccc)+ table.cell(quarterly_table, 0, yi + 1, str.tostring(year(array.get(year_time, yi))), bgcolor = #cccccc) y_color = getCellColor(array.get(year_pnl, yi), array.get(year_bh, yi))- table.cell(quarterly_table, 5, yi + 1, enableCompareWithMarket ? tostring(round(array.get(year_pnl, yi) * 100, precision)) + " (" + tostring(round(array.get(year_bh, yi) * 100, precision)) + ")" : tostring(round(array.get(year_pnl, yi) * 100, precision)), bgcolor = y_color, text_color=#bfbfbf)+ table.cell(quarterly_table, 5, yi + 1, enableCompareWithMarket ? str.tostring(math.round(array.get(year_pnl, yi) * 100, precision)) + " (" + str.tostring(math.round(array.get(year_bh, yi) * 100, precision)) + ")" : str.tostring(math.round(array.get(year_pnl, yi) * 100, precision)), bgcolor = y_color, text_color=#bfbfbf) ⋯ m_row = year(array.get(quarter_time, mi)) - year(array.get(year_time, 0)) + 1- m_col = ceil(month(array.get(quarter_time, mi)) / 3)+ m_col = math.ceil(month(array.get(quarter_time, mi)) / 3) m_color = getCellColor(array.get(quarter_pnl, mi), array.get(quarter_bh, mi)) - table.cell(quarterly_table, m_col, m_row, enableCompareWithMarket ? tostring(round(array.get(quarter_pnl, mi) * 100, precision)) + " (" + tostring(round(array.get(quarter_bh, mi) * 100,precision)) +")" : tostring(round(array.get(quarter_pnl, mi) * 100, precision)), bgcolor = m_color, text_color=#bfbfbf)+ table.cell(quarterly_table, m_col, m_row, enableCompareWithMarket ? str.tostring(math.round(array.get(quarter_pnl, mi) * 100, precision)) + " (" + str.tostring(math.round(array.get(quarter_bh, mi) * 100,precision)) +")" : str.tostring(math.round(array.get(quarter_pnl, mi) * 100, precision)), bgcolor = m_color, text_color=#bfbfbf)Clean v5
Not verifiedThe v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L69:C12: No value assigned to the `transp` parameter in color.new()), so this step could not be checked.
- Line 5: input() → input.int()
⋯strategy(title="Quarterly Returns in Strategies vs Buy & Hold", initial_capital= 1000, overlay=true,default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, commission_value = 0.1)-maLength= input(400)+maLength= input.int(400)wma= ta.vwma(hl2,maLength)⋯Does it run in Pine Script v6?
Not tested
The v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L69:C12: No value assigned to the `transp` parameter in color.new()), so this step could not be checked. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © Dannnnnnny-//@version=5+//@version=6strategy(title="Quarterly Returns in Strategies vs Buy & Hold", initial_capital= 1000, overlay=true,default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, commission_value = 0.1)⋯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 |
|---|---|---|---|
| MA Length (no label in the script) | 400 | int | wma |
| Enable Quarterly Return table | false | bool | line 81 |
| Compare with Market Benchmark | false | bool | line 93 line 100 |
| Table Position | bottom_right | string · options ['bottom_right','bottom_left','top_right', 'top_left'] | quarterly_table |
What it calculates
- VWMA (
vwma,ta.vwmain v5)hl2, MA Length (400)wma · line 6 - Rising (
rising,ta.risingin v5)wma, 5uptrend · line 7 - Falling (
falling,ta.fallingin v5)wma, 5downtrend · line 8
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 | uptrend | On | 11 |
| Close Buy | uptrend | On | 13 |
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 | +80.2% | +102.5% | 4 | 25% | 5.16 | 10.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −21.7% | +5.5% | 3 | 33% | 0.06 | 28.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −31.9% | +9.8% | 9 | 22% | 0.26 | 34.8% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −4.3% | +8.4% | 3 | 33% | 0.82 | 35.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −21.6% | +16.7% | 6 | 17% | 0.50 | 36.8% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −20.1% | +21.5% | 1 | 0% | 0.00 | 35.9% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +91.3% | +148.3% | 10 | 50% | 3.74 | 17.5% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −13.2% | +17.1% | 3 | 0% | 0.00 | 17.4% | 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 | 0 | — | $0.00 |
| Sideways market | 2 | 50% | $942.16 |
| Falling market | 2 | 0% | −$139.82 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
9.7%
The 95th percentile of the worst drawdown when the same 4 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 5.1% to 9.7%; the tick is what actually happened, 9.7%. Order luck alone moves it this much.
All 4 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 1 Feb 2024 42,580.00 | 22 Nov 2025 85,129.40 | 660 | $995.29 |
| long | 27 Nov 2025 90,484.00 | 2 Dec 2025 86,286.00 | 5 | −$96.37 |
| long | 7 Dec 2025 89,236.80 | 27 Dec 2025 87,369.60 | 20 | −$43.45 |
| long | 16 May 2026 79,113.20 | 19 May 2026 77,001.90 | 3 | −$53.13 |
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 |
|---|---|---|---|---|---|
| Quarterly Returns in Strategies vs Buy & Hold this page | — | v4 strategy | +80.2% | 4 | 10.7% |
| Trading Day and Time Session by Dannnnnnny | vwma rising falling | v5 strategy | No trades on this market | ||
| Swing Trading SPX Correlation by exlux99 | vwma rising | v5 strategy | No trades on this market | ||
| PMA Strategy Idea by QuantCT | rising falling | v4 strategy | +51.7% | 129 | 30.8% |
| Trendelicious Strategy by levieux | rising falling | v5 strategy | −12.8% | 9 | 41.4% |
| Linear On MACD by stocktechbot | rising falling vwma | v5 strategy | +1.5% | 16 | 5.6% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 41 ms | Yes 1,000 bars in 56 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/// © Dannnnnnny//@version=4strategy(title="Quarterly Returns in Strategies vs Buy & Hold", initial_capital= 1000, overlay=true,default_qty_type = strategy.percent_of_equity, default_qty_value = 100, commission_type = strategy.commission.percent, commission_value = 0.1)maLength= input(400)wma= vwma(hl2,maLength)uptrend= rising(wma, 5)downtrend= falling(wma,5)plot(wma)if uptrend strategy.entry("Buy", strategy.long)else strategy.close("Buy")/////////////////////// QUARTERLY TABLE //enableQuarterlyTable = input(title="Enable Quarterly Return table", type=input.bool, defval=false)enableCompareWithMarket = input(title="Compare with Market Benchmark", type=input.bool, defval=false)table_position = input(title="Table Position", type=input.string, defval='bottom_right', options=['bottom_right','bottom_left','top_right', 'top_left'])precision = 2new_quarter = ceil(month(time)/3) != ceil(month(time[1])/3)new_year = year(time) != year(time[1])eq = strategy.equitybar_pnl = eq / eq[1] - 1bar_bh = (close-close[1])/close[1]cur_quarter_pnl = 0.0cur_year_pnl = 0.0cur_quarter_bh = 0.0cur_year_bh = 0.0// Current Quarterly P&Lcur_quarter_pnl := new_quarter ? 0.0 : (1 + cur_quarter_pnl[1]) * (1 + bar_pnl) - 1 cur_quarter_bh := new_quarter ? 0.0 : (1 + cur_quarter_bh[1]) * (1 + bar_bh) - 1// Current Yearly P&Lcur_year_pnl := new_year ? 0.0 : (1 + cur_year_pnl[1]) * (1 + bar_pnl) - 1cur_year_bh := new_year ? 0.0 : (1 + cur_year_bh[1]) * (1 + bar_bh) - 1// Arrays to store Yearly and Quarterly P&Lsvar quarter_pnl = array.new_float(0)var quarter_time = array.new_int(0)var quarter_bh = array.new_float(0)var year_pnl = array.new_float(0)var year_time = array.new_int(0)var year_bh = array.new_float(0)end_time = falseend_time:= time_close + (time_close - time_close[1]) > timenow or barstate.islastconfirmedhistoryif (not na(cur_quarter_pnl[1]) and (new_quarter or end_time)) if (end_time[1]) array.pop(quarter_pnl) array.pop(quarter_time) array.push(quarter_pnl , cur_quarter_pnl[1]) array.push(quarter_time, time[1]) array.push(quarter_bh , cur_quarter_bh[1])if (not na(cur_year_pnl[1]) and (new_year or end_time)) if (end_time[1]) array.pop(year_pnl) array.pop(year_time) array.push(year_pnl , cur_year_pnl[1]) array.push(year_time, time[1]) array.push(year_bh , cur_year_bh[1])// Quarterly P&L Table var quarterly_table = table(na)getCellColor(pnl, bh) => if pnl > 0 if bh < 0 or pnl > 2 * bh color.new(color.green, transp = 20) else if pnl > bh color.new(color.green, transp = 50) else color.new(color.green, transp = 80) else if bh > 0 or pnl < 2 * bh color.new(color.red, transp = 20) else if pnl < bh color.new(color.red, transp = 50) else color.new(color.red, transp = 80)if (end_time and enableQuarterlyTable) quarterly_table := table.new(table_position, columns = 14, rows = array.size(year_pnl) + 1, border_width = 1) table.cell(quarterly_table, 0, 0, "", bgcolor = #cccccc) table.cell(quarterly_table, 1, 0, "Q1", bgcolor = #cccccc) table.cell(quarterly_table, 2, 0, "Q2", bgcolor = #cccccc) table.cell(quarterly_table, 3, 0, "Q3", bgcolor = #cccccc) table.cell(quarterly_table, 4, 0, "Q4", bgcolor = #cccccc) table.cell(quarterly_table, 5, 0, "Year", bgcolor = #999999) for yi = 0 to array.size(year_pnl) - 1 table.cell(quarterly_table, 0, yi + 1, tostring(year(array.get(year_time, yi))), bgcolor = #cccccc) y_color = getCellColor(array.get(year_pnl, yi), array.get(year_bh, yi)) table.cell(quarterly_table, 5, yi + 1, enableCompareWithMarket ? tostring(round(array.get(year_pnl, yi) * 100, precision)) + " (" + tostring(round(array.get(year_bh, yi) * 100, precision)) + ")" : tostring(round(array.get(year_pnl, yi) * 100, precision)), bgcolor = y_color, text_color=#bfbfbf) for mi = 0 to array.size(quarter_time) - 1 m_row = year(array.get(quarter_time, mi)) - year(array.get(year_time, 0)) + 1 m_col = ceil(month(array.get(quarter_time, mi)) / 3) m_color = getCellColor(array.get(quarter_pnl, mi), array.get(quarter_bh, mi)) table.cell(quarterly_table, m_col, m_row, enableCompareWithMarket ? tostring(round(array.get(quarter_pnl, mi) * 100, precision)) + " (" + tostring(round(array.get(quarter_bh, mi) * 100,precision)) +")" : tostring(round(array.get(quarter_pnl, mi) * 100, precision)), bgcolor = m_color, text_color=#bfbfbf)