Pine Script v5 · Strategy
Portfolio Performance - 2 Assets
A Pine Script v5 strategy built on Stdev (bar_count+1). 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 is one contract and pays no commission. 28 settings; defaults include Prefix NASDAQ, Ticker BND and First Weight (%) 100.00.
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 Portfolio Performance - 2 Assets repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- How did Portfolio Performance - 2 Assets do on BTCUSDT 1D with default settings?
- Not measured
- It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
- Does Portfolio Performance - 2 Assets run in Pine Script v6?
- Not tested
- Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download.
- Does Portfolio Performance - 2 Assets use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Portfolio Performance - 2 Assets run in Zeal Terminal?
- Yes
- It compiles in 46 ms and runs 1,000 bars in 76 ms, in the browser.
BTCUSDT · 1D · default settings
- Stdev
- Stdev
- Winning trade
- Losing trade
- Equity
- Buy and hold
Needs NASDAQ:BND D data, not available: not a Binance spot market Values that depend on it are empty on this chart.
- Net profit
- 0.00%
- $0.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 0
- 0 won · 0 lost
- Profitable
- 0.0%
- of closed trades
- Profit factor
- —
- gross profit ÷ gross loss
- Max drawdown
- 0.00%
- $0.00
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.
-
Note
Uses an argument v6 removed
when = on line 10, 11. The upgraded version below moves each call inside an if block.
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 |
|---|---|---|---|
| Time Interval | |||
| Entry TimeEnter the starting date | timestamp("2021-12-16") | time | entrycondition |
| Exit TimeEnter the ending date | timestamp("2021-12-17") | time | entrycondition exitcondition |
| Second Asset | |||
| Prefix | NASDAQ | string | second_ticker |
| Ticker | BND | string | second_ticker |
| First Portfolio | |||
| First Weight (%)Input the weight of this asset relative to your portfolio | 100.00 | float · min 0 · max 100 · step 0.1 | onehundred_zero_weighted_return onehundred_zero_risk_adjusted_weighted_return |
| Second Weight (%)Input the weight of this asset relative to your portfolio | 0.00 | float · min 0 · max 100 · step 0.1 | onehundred_zero_weighted_return onehundred_zero_risk_adjusted_weighted_return |
| Plot Weighted Return | true | bool | 100/0 Weighted Return |
| Plot Risk Adjusted Weighted Return | false | bool | 100/0 Risk Adjusted Weighted Return |
| Second Portfolio | |||
| First Weight (%)Input the weight of this asset relative to your portfolio | 80.00 | float · min 0 · max 100 · step 0.1 | eighty_twenty_weighted_return eighty_twenty_risk_adjusted_weighted_return |
| Second Weight (%)Input the weight of this asset relative to your portfolio | 20.00 | float · min 0 · max 100 · step 0.1 | eighty_twenty_weighted_return eighty_twenty_risk_adjusted_weighted_return |
| Plot Weighted Return | true | bool | 80/20 Weighted Return |
| Plot Risk Adjusted Weighted Return | false | bool | 80/20 Risk Adjusted Weighted Return |
| Third Portfolio | |||
| First Weight (%)Input the weight of this asset relative to your portfolio | 60.00 | float · min 0 · max 100 · step 0.1 | sixty_fourty_weighted_return sixty_fourty_risk_adjusted_weighted_return |
| Second Weight (%)Input the weight of this asset relative to your portfolio | 40.00 | float · min 0 · max 100 · step 0.1 | sixty_fourty_weighted_return sixty_fourty_risk_adjusted_weighted_return |
| Plot Weighted Return | true | bool | 60/40 Weighted Return |
| Plot Risk Adjusted Weighted Return | false | bool | 60/40 Risk Adjusted Weighted Return |
| Fourth Portfolio | |||
| First Weight (%)Input the weight of this asset relative to your portfolio | 40.00 | float · min 0 · max 100 · step 0.1 | fourty_sixty_weighted_return fourty_sixty_risk_adjusted_weighted_return |
| Second Weight (%)Input the weight of this asset relative to your portfolio | 60.00 | float · min 0 · max 100 · step 0.1 | fourty_sixty_weighted_return fourty_sixty_risk_adjusted_weighted_return |
| Plot Weighted Return | true | bool | 40/60 Weighted Return |
| Plot Risk Adjusted Weighted Return | false | bool | 40/60 Risk Adjusted Weighted Return |
| Fifth Portfolio | |||
| First Weight (%)Input the weight of this asset relative to your portfolio | 20.00 | float · min 0 · max 100 · step 0.1 | twenty_eighty_weighted_return twenty_eighty_risk_adjusted_weighted_return |
| Second Weight (%)Input the weight of this asset relative to your portfolio | 80.00 | float · min 0 · max 100 · step 0.1 | twenty_eighty_weighted_return twenty_eighty_risk_adjusted_weighted_return |
| Plot Weighted Return | true | bool | 20/80 Weighted Return |
| Plot Risk Adjusted Weighted Return | false | bool | 20/80 Risk Adjusted Weighted Return |
| Sixth Portfolio | |||
| First Weight (%)Input the weight of this asset relative to your portfolio | 0.00 | float · min 0 · max 100 · step 0.1 | zero_onehundred_weighted_return zero_onehundred_adjusted_weighted_return |
| Second Weight (%)Input the weight of this asset relative to your portfolio | 100.00 | float · min 0 · max 100 · step 0.1 | zero_onehundred_weighted_return zero_onehundred_adjusted_weighted_return |
| Plot Weighted Return | true | bool | 0/100 Weighted Return |
| Plot Risk Adjusted Weighted Return | false | bool | 0/100 Risk Adjusted Weighted Return |
What it calculates
- Stdevpercent_return_first_asset, bar_count+1
risk_adjusted_return_first_asset · line 34 - Stdevpercent_return_second_asset, bar_count+1
risk_adjusted_return_second_asset · line 36
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 | entryconditiontime >= entrytime and time < exittime | On | 10 |
| Close | exitconditiontime >= exittime | On | 11 |
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.
- ClearHigher-timeframe data1 request.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 timingprocess_orders_on_close = true: orders fill at the signal bar's close.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
Not run on other markets: the script requests NASDAQ:BND D, and that data is not available here (not a Binance spot market). Its results would rest on empty values.
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 |
|---|---|---|---|---|---|
| Portfolio Performance - 2 Assets this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| Simple way to BEAT the market [STRATEGY] by TraderHalai | stdev | v4 strategy | +193.5% | 15 | 39.2% |
| Crypto RSI with RVI Strategy by exlux99 | stdev | v4 strategy | +4.0% | 2 | 32.1% |
| Historical Volatility by Zeal Terminal | stdev | v5 indicator | indicator | ||
| Double Bollinger Binary Options by Trade_by_DB | stdev | v5 strategy | No trades on this market | ||
| Improved Bollinger Swing Strategy Stock Nasdaq by exlux99 | stdev | v4 strategy | −20.4% | 7 | 22.3% |
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.
- 2 strategy calls use the when = argument (line 10, 11). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- No v6-only features. v6 is not needed to run this script.
Clean v5
Not verifiedNeither version placed a trade on any of the 8 markets, so there was nothing to compare.
- Line 10: when = entrycondition → if block
- Line 11: when = exitcondition → if block
⋯exitcondition = time >= exittime-strategy.entry("Buy", strategy.long, qty=10000/close, when=entrycondition)+if entrycondition+ strategy.entry("Buy", strategy.long, qty=10000/close)-strategy.close_all(when = exitcondition)+if exitcondition+ strategy.close_all()//****************************************************************** Define the second asset ******************************************************************//⋯Does it run in Pine Script v6?
Not tested
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © Skywalking2874-//@version=5+//@version=6strategy("Portfolio Performance - 2 Assets", overlay=false, margin_long=100, margin_short=100, process_orders_on_close=true, max_bars_back=5000)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 46 ms | With a workaround 1,000 bars in 76 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
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.
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/// © Skywalking2874//@version=5strategy("Portfolio Performance - 2 Assets", overlay=false, margin_long=100, margin_short=100, process_orders_on_close=true, max_bars_back=5000)//****************************************************************** Define the time interval ******************************************************************//entrytime = input.time(defval=timestamp("2021-12-16"), title="Entry Time", tooltip="Enter the starting date", confirm=true, group="Time Interval")exittime = input.time(defval=timestamp("2021-12-17"), title="Exit Time", tooltip="Enter the ending date", confirm=true, group="Time Interval")entrycondition = time >= entrytime and time < exittimeexitcondition = time >= exittimestrategy.entry("Buy", strategy.long, qty=10000/close, when=entrycondition)strategy.close_all(when = exitcondition)//****************************************************************** Define the second asset ******************************************************************//second_asset_prefix = input.string(defval = "NASDAQ", title = "Prefix", group="Second Asset", inline="Asset2")second_asset_ticker = input.string(defval = "BND", title="Ticker", group="Second Asset", inline="Asset2")second_ticker = ticker.new(prefix = second_asset_prefix, ticker = second_asset_ticker, session = session.regular, adjustment = adjustment.dividends)second_symbol = request.security(second_ticker, "D", close)//****************************************************************** Define the portfolio weights ******************************************************************//portfolio1_weight1 = input.float(defval=100.00, title="First Weight (%)", minval=0, maxval=100, step=0.1, tooltip="Input the weight of this asset relative to your portfolio", inline="Asset1", group="First Portfolio")portfolio1_weight2 = input.float(defval=0.00, title="Second Weight (%)", minval=0, maxval=100, step=0.1, tooltip="Input the weight of this asset relative to your portfolio", inline="Asset1", group="First Portfolio")portfolio2_weight1 = input.float(defval=80.00, title="First Weight (%)", minval=0, maxval=100, step=0.1, tooltip="Input the weight of this asset relative to your portfolio", inline="Asset2", group="Second Portfolio")portfolio2_weight2 = input.float(defval=20.00, title="Second Weight (%)", minval=0, maxval=100, step=0.1, tooltip="Input the weight of this asset relative to your portfolio", inline="Asset2", group="Second Portfolio")portfolio3_weight1 = input.float(defval=60.00, title="First Weight (%)", minval=0, maxval=100, step=0.1, tooltip="Input the weight of this asset relative to your portfolio", inline="Asset3", group="Third Portfolio")portfolio3_weight2 = input.float(defval=40.00, title="Second Weight (%)", minval=0, maxval=100, step=0.1, tooltip="Input the weight of this asset relative to your portfolio", inline="Asset3", group="Third Portfolio")portfolio4_weight1 = input.float(defval=40.00, title="First Weight (%)", minval=0, maxval=100, step=0.1, tooltip="Input the weight of this asset relative to your portfolio", inline="Asset4", group="Fourth Portfolio")portfolio4_weight2 = input.float(defval=60.00, title="Second Weight (%)", minval=0, maxval=100, step=0.1, tooltip="Input the weight of this asset relative to your portfolio", inline="Asset4", group="Fourth Portfolio")portfolio5_weight1 = input.float(defval=20.00, title="First Weight (%)", minval=0, maxval=100, step=0.1, tooltip="Input the weight of this asset relative to your portfolio", inline="Asset5", group="Fifth Portfolio")portfolio5_weight2 = input.float(defval=80.00, title="Second Weight (%)", minval=0, maxval=100, step=0.1, tooltip="Input the weight of this asset relative to your portfolio", inline="Asset5", group="Fifth Portfolio")portfolio6_weight1 = input.float(defval=0.00, title="First Weight (%)", minval=0, maxval=100, step=0.1, tooltip="Input the weight of this asset relative to your portfolio", inline="Asset6", group="Sixth Portfolio")portfolio6_weight2 = input.float(defval=100.00, title="Second Weight (%)", minval=0, maxval=100, step=0.1, tooltip="Input the weight of this asset relative to your portfolio", inline="Asset6", group="Sixth Portfolio")//****************************************************************** Calculate %Return and %Risk Adjusted Return ******************************************************************//trade_open_time = time >= strategy.opentrades.entry_time(strategy.opentrades-1) ? strategy.opentrades.entry_time(strategy.opentrades-1) : 2524608000000bar_count = ta.barssince(time <= trade_open_time)percent_return_first_asset = ((close - close[bar_count])/close[bar_count])*100risk_adjusted_return_first_asset = percent_return_first_asset/ta.stdev(percent_return_first_asset, bar_count+1)percent_return_second_asset = ((second_symbol - second_symbol[bar_count])/second_symbol[bar_count])*100risk_adjusted_return_second_asset = percent_return_second_asset/ta.stdev(percent_return_second_asset, bar_count+1)onehundred_zero_weighted_return = (portfolio1_weight1/100.00)*percent_return_first_asset + (portfolio1_weight2/100.00)*percent_return_second_assetonehundred_zero_risk_adjusted_weighted_return = (portfolio1_weight1/100.00)*risk_adjusted_return_first_asset + (portfolio1_weight2/100.00)*risk_adjusted_return_second_asseteighty_twenty_weighted_return = (portfolio2_weight1/100.00)*percent_return_first_asset + (portfolio2_weight2/100.00)*percent_return_second_asseteighty_twenty_risk_adjusted_weighted_return = (portfolio2_weight1/100.00)*risk_adjusted_return_first_asset + (portfolio2_weight2/100.00)*risk_adjusted_return_second_assetsixty_fourty_weighted_return = (portfolio3_weight1/100.00)*percent_return_first_asset + (portfolio3_weight2/100.00)*percent_return_second_assetsixty_fourty_risk_adjusted_weighted_return = (portfolio3_weight1/100.00)*risk_adjusted_return_first_asset + (portfolio3_weight2/100.00)*risk_adjusted_return_second_assetfourty_sixty_weighted_return = (portfolio4_weight1/100.00)*percent_return_first_asset + (portfolio4_weight2/100.00)*percent_return_second_assetfourty_sixty_risk_adjusted_weighted_return = (portfolio4_weight1/100.00)*risk_adjusted_return_first_asset + (portfolio4_weight2/100.00)*risk_adjusted_return_second_assettwenty_eighty_weighted_return = (portfolio5_weight1/100.00)*percent_return_first_asset + (portfolio5_weight2/100.00)*percent_return_second_assettwenty_eighty_risk_adjusted_weighted_return = (portfolio5_weight1/100.00)*risk_adjusted_return_first_asset + (portfolio5_weight2/100.00)*risk_adjusted_return_second_assetzero_onehundred_weighted_return = (portfolio6_weight1/100.00)*percent_return_first_asset + (portfolio6_weight2/100.00)*percent_return_second_assetzero_onehundred_adjusted_weighted_return = (portfolio6_weight1/100.00)*risk_adjusted_return_first_asset + (portfolio6_weight2/100.00)*risk_adjusted_return_second_asset//****************************************************************** Plot ******************************************************************//portfolio1_return = input.bool(defval=true, title="Plot Weighted Return", inline="Asset11", group="First Portfolio")portfolio2_return = input.bool(defval=true, title="Plot Weighted Return", inline="Asset22", group="Second Portfolio")portfolio3_return = input.bool(defval=true, title="Plot Weighted Return", inline="Asset33", group="Third Portfolio")portfolio4_return = input.bool(defval=true, title="Plot Weighted Return", inline="Asset44", group="Fourth Portfolio")portfolio5_return = input.bool(defval=true, title="Plot Weighted Return", inline="Asset55", group="Fifth Portfolio")portfolio6_return = input.bool(defval=true, title="Plot Weighted Return", inline="Asset66", group="Sixth Portfolio")portfolio1_risk_adjusted_return = input.bool(defval=false, title="Plot Risk Adjusted Weighted Return", inline="Asset11", group="First Portfolio")portfolio2_risk_adjusted_return = input.bool(defval=false, title="Plot Risk Adjusted Weighted Return", inline="Asset22", group="Second Portfolio")portfolio3_risk_adjusted_return = input.bool(defval=false, title="Plot Risk Adjusted Weighted Return", inline="Asset33", group="Third Portfolio")portfolio4_risk_adjusted_return = input.bool(defval=false, title="Plot Risk Adjusted Weighted Return", inline="Asset44", group="Fourth Portfolio")portfolio5_risk_adjusted_return = input.bool(defval=false, title="Plot Risk Adjusted Weighted Return", inline="Asset55", group="Fifth Portfolio")portfolio6_risk_adjusted_return = input.bool(defval=false, title="Plot Risk Adjusted Weighted Return", inline="Asset66", group="Sixth Portfolio")trade_close_time = time >= strategy.closedtrades.entry_time(strategy.closedtrades-1) ? strategy.closedtrades.entry_time(strategy.closedtrades-1) : 2524608000000transparant = color.rgb(0, 0, 0, 100)//Fixed Weight Palette fixed_color1 = time >= trade_open_time ? color.new(#10B22D, 0) : transparantfixed_color2 = time >= trade_open_time ? color.new(#00FF1E, 0) : transparantfixed_color3 = time >= trade_open_time ? color.new(#FFFB00, 0) : transparantfixed_color4 = time >= trade_open_time ?color.new(#FF6600, 0) : transparantfixed_color5 = time >= trade_open_time ? color.new(#FF0000, 0) : transparantfixed_color6 = time >= trade_open_time ? color.new(#9C0000, 0) : transparant//Fixed Weight Risk Adjusted Palettefixed_risk_color1 = time >= trade_open_time ? color.new(#72A97C, 0) : transparantfixed_risk_color2 = time >= trade_open_time ? color.new(#8AF897, 0) : transparantfixed_risk_color3 = time >= trade_open_time ? color.new(#FFFD78, 0) : transparantfixed_risk_color4 = time >= trade_open_time ?color.new(#FFAD77, 0) : transparantfixed_risk_color5 = time >= trade_open_time ? color.new(#FF7D7D, 0) : transparantfixed_risk_color6 = time >= trade_open_time ? color.new(#904747, 0) : transparantplot(onehundred_zero_weighted_return, title="100/0 Weighted Return", color= portfolio1_return == true ? fixed_color1 : transparant)plot(eighty_twenty_weighted_return, title="80/20 Weighted Return", color= portfolio2_return == true ? fixed_color2 : transparant)plot(sixty_fourty_weighted_return, title="60/40 Weighted Return", color= portfolio3_return == true ? fixed_color3: transparant)plot(fourty_sixty_weighted_return, title="40/60 Weighted Return", color= portfolio4_return == true ? fixed_color4: transparant)plot(twenty_eighty_weighted_return, title="20/80 Weighted Return", color= portfolio5_return == true ? fixed_color5: transparant)plot(zero_onehundred_weighted_return, title="0/100 Weighted Return", color= portfolio6_return == true ? fixed_color6: transparant)plot(onehundred_zero_risk_adjusted_weighted_return, title="100/0 Risk Adjusted Weighted Return", color= portfolio1_risk_adjusted_return == true ? fixed_risk_color1 : transparant)plot(eighty_twenty_risk_adjusted_weighted_return, title="80/20 Risk Adjusted Weighted Return", color= portfolio2_risk_adjusted_return == true ? fixed_risk_color2 : transparant)plot(sixty_fourty_risk_adjusted_weighted_return, title="60/40 Risk Adjusted Weighted Return", color= portfolio3_risk_adjusted_return == true ? fixed_risk_color3: transparant)plot(fourty_sixty_risk_adjusted_weighted_return, title="40/60 Risk Adjusted Weighted Return", color= portfolio4_risk_adjusted_return == true ? fixed_risk_color4: transparant)plot(twenty_eighty_risk_adjusted_weighted_return, title="20/80 Risk Adjusted Weighted Return", color= portfolio5_risk_adjusted_return == true ? fixed_risk_color5: transparant)plot(zero_onehundred_adjusted_weighted_return, title="0/100 Risk Adjusted Weighted Return", color= portfolio6_risk_adjusted_return == true ? fixed_risk_color6: transparant)