Pine Script v5 · Strategy
Simple-Compounded Returns & Drawdowns Table
A Pine Script v5 strategy built on EMA (close, 12). It has 2 order rules, 2 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. 11 settings; defaults include Mode Compound Equity, Return Precision 2 and Fast Length 12.
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 Simple-Compounded Returns & Drawdowns Table repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 22 of 22 trades.
- How did Simple-Compounded Returns & Drawdowns Table do on BTCUSDT 1D with default settings?
- +9.38%
- From 26 Jan 2024 to 21 Oct 2026, over 76 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Simple-Compounded Returns & Drawdowns Table run in Pine Script v6?
- No
- The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 76 before, 95 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does Simple-Compounded Returns & Drawdowns Table use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Simple-Compounded Returns & Drawdowns Table run in Zeal Terminal?
- Yes
- It compiles in 59 ms and runs 1,000 bars in 261 ms, in the browser.
BTCUSDT · 1D · default settings
- EMA
- EMA
- Winning trade
- Losing trade
- Equity
- Buy and hold
| Jan | Feb | Mar | Apr | May | Jun | Jul | Aug | Sep | Oct | Nov | Dec | Compound Equity | |
| 2024 | 0 | 0 | -2.56 | 12.7 | 14.09 | 15.41 | 37.14 | 47.75 | 63.24 | 39.76 | 42.72 | 27.91 | 27.91 |
| 2025 | 4.82 | 9.63 | -0.81 | -0.39 | 1.83 | -8.36 | -0.35 | 3.72 | 1.91 | -12.52 | -3.81 | -11.16 | -11.16 |
| 2026 | -0.56 | 6.53 | -0.44 | 9.48 | 14.21 | 13.96 | 19.76 | 35.51 | 9.43 | 8.02 | 8.02 |
- Net profit
- +9.38%
- $93,802.40
- Buy and hold
- +102.5%
- same period
- Closed trades
- 76
- 27 won · 49 lost
- Profitable
- 35.5%
- of closed trades
- Profit factor
- 1.04
- gross profit ÷ gross loss
- Max drawdown
- 46.39%
- −$727,139.00
One run with the author's default settings, $1,000,000 starting capital, commission as the script sets it. A short position was still open at the last bar. 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.
-
Note
3 settings have no label
In the settings dialog fastLength (line 144), slowlength (line 145), MACDLength (line 146) show 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.
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 |
|---|---|---|---|
| R & DD Table | |||
| Mode | Compound Equity | string | display_array line 27 line 48 line 67 line 115 |
| Return Precision | 2 | int | line 128 line 137 |
| Headers Color | #D4D4D4 | color | line 102 line 103 line 104 line 105 line 106 line 107 line 108 line 109 line 110 line 111 line 112 line 113 line 114 line 115 line 118 |
| Headers Text Color | color.black | color | line 102 line 103 line 104 line 105 line 106 line 107 line 108 line 109 line 110 line 111 line 112 line 113 line 114 line 115 line 118 |
| Positive Color | color.green | color | m_color y_color |
| Negative Color | color.red | color | m_color y_color |
| Zero Color | #DDDDDD | color | m_color y_color |
| Cell Text Color | color.white | color | line 128 line 137 |
| Fast Length (no label in the script) | 12 | int | MACD |
| Slowlength (no label in the script) | 26 | int | MACD |
| MACDLength (no label in the script) | 9 | int | aMACD |
What it calculates
- EMAclose, Fast Length (12)
MACD · line 147 - EMAMACD, MACDLength (9)
aMACD · line 148
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 MacdLE long | (ta.crossover(delta, 0)) | On | 151 |
| Open MacdSE short | (ta.crossunder(delta, 0)) | On | 153 |
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 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
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 | +9.4% | +102.5% | 76 | 36% | 1.04 | 46.4% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +27.2% | +5.5% | 68 | 37% | 1.39 | 12.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −51.8% | +9.8% | 72 | 32% | 0.79 | 76.4% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +3.4% | +8.4% | 76 | 29% | 1.03 | 29.8% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +53.0% | +16.7% | 63 | 49% | 1.13 | 73.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −5.2% | +21.5% | 70 | 33% | 0.96 | 35.1% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −55.5% | +148.3% | 68 | 43% | 0.62 | 62.4% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +3.5% | +17.1% | 77 | 32% | 1.04 | 20.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 | 24 | 38% | −$172,198.00 |
| Sideways market | 36 | 39% | $130,136.00 |
| Falling market | 16 | 25% | $135,865.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
59.8%
The 95th percentile of the worst drawdown when the same 76 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 32.2% to 59.8%; the tick is what actually happened, 46.0%. Order luck alone moves it this much.
All 76 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 15 Mar 2024 69,499.90 | 5 May 2024 64,012.00 | 51 | $78,962.00 |
| long | 5 May 2024 64,012.00 | 11 May 2024 60,826.00 | 6 | −$53,702.20 |
| short | 11 May 2024 60,826.00 | 12 May 2024 61,484.00 | 1 | −$11,091.00 |
| long | 12 May 2024 61,484.00 | 30 May 2024 68,352.20 | 18 | $113,290.00 |
| short | 30 May 2024 68,352.20 | 5 Jun 2024 71,108.00 | 6 | −$45,457.00 |
| long | 5 Jun 2024 71,108.00 | 8 Jun 2024 69,310.50 | 3 | −$27,351.90 |
| short | 8 Jun 2024 69,310.50 | 12 Jul 2024 57,889.10 | 34 | $173,791.00 |
| long | 12 Jul 2024 57,889.10 | 31 Jul 2024 64,628.00 | 19 | $143,003.00 |
| short | 31 Jul 2024 64,628.00 | 19 Aug 2024 59,438.50 | 19 | $110,124.00 |
| long | 19 Aug 2024 59,438.50 | 30 Aug 2024 59,124.00 | 11 | −$7,839.50 |
| short | 30 Aug 2024 59,124.00 | 12 Sep 2024 58,132.30 | 13 | $24,718.40 |
| long | 12 Sep 2024 58,132.30 | 1 Oct 2024 60,805.80 | 19 | $68,912.40 |
| short | 1 Oct 2024 60,805.80 | 14 Oct 2024 66,084.00 | 13 | −$136,054.00 |
| long | 14 Oct 2024 66,084.00 | 26 Oct 2024 67,092.80 | 12 | $21,848.80 |
| short | 26 Oct 2024 67,092.80 | 28 Oct 2024 69,962.20 | 2 | −$62,149.10 |
| long | 28 Oct 2024 69,962.20 | 3 Nov 2024 68,776.00 | 6 | −$23,584.70 |
| short | 3 Nov 2024 68,776.00 | 6 Nov 2024 75,572.00 | 3 | −$135,120.00 |
| long | 6 Nov 2024 75,572.00 | 26 Nov 2024 91,965.20 | 20 | $267,312.00 |
| short | 26 Nov 2024 91,965.20 | 16 Dec 2024 106,059.00 | 20 | −$229,813.00 |
| long | 16 Dec 2024 106,059.00 | 18 Dec 2024 100,204.00 | 2 | −$70,095.50 |
| short | 18 Dec 2024 100,204.00 | 5 Jan 2025 98,363.60 | 18 | $22,034.40 |
| long | 5 Jan 2025 98,363.60 | 9 Jan 2025 92,552.50 | 4 | −$72,177.80 |
| short | 9 Jan 2025 92,552.50 | 15 Jan 2025 100,497.00 | 6 | −$98,680.30 |
| long | 15 Jan 2025 100,497.00 | 28 Jan 2025 101,336.00 | 13 | $8,764.58 |
| short | 28 Jan 2025 101,336.00 | 20 Feb 2025 98,305.00 | 23 | $31,689.60 |
| long | 20 Feb 2025 98,305.00 | 24 Feb 2025 91,552.90 | 4 | −$74,958.80 |
| short | 24 Feb 2025 91,552.90 | 6 Mar 2025 89,931.90 | 10 | $17,995.50 |
| long | 6 Mar 2025 89,931.90 | 8 Mar 2025 86,222.40 | 2 | −$42,665.00 |
| short | 8 Mar 2025 86,222.40 | 15 Mar 2025 84,338.40 | 7 | $21,669.40 |
| long | 15 Mar 2025 84,338.40 | 6 Apr 2025 78,430.00 | 22 | −$70,993.40 |
| short | 6 Apr 2025 78,430.00 | 11 Apr 2025 83,423.80 | 5 | −$60,003.90 |
| long | 11 Apr 2025 83,423.80 | 17 May 2025 103,127.00 | 36 | $208,398.00 |
| short | 17 May 2025 103,127.00 | 18 May 2025 106,454.00 | 1 | −$35,196.30 |
| long | 18 May 2025 106,454.00 | 19 May 2025 105,574.00 | 1 | −$8,731.07 |
| short | 19 May 2025 105,574.00 | 21 May 2025 109,644.00 | 2 | −$40,359.80 |
| long | 21 May 2025 109,644.00 | 24 May 2025 107,762.00 | 3 | −$17,276.80 |
| short | 24 May 2025 107,762.00 | 10 Jun 2025 110,274.00 | 17 | −$23,063.60 |
| long | 10 Jun 2025 110,274.00 | 12 Jun 2025 105,672.00 | 2 | −$40,325.40 |
| short | 12 Jun 2025 105,672.00 | 26 Jun 2025 106,947.00 | 14 | −$11,173.60 |
| long | 26 Jun 2025 106,947.00 | 21 Jul 2025 117,380.00 | 25 | $89,229.40 |
| short | 21 Jul 2025 117,380.00 | 22 Jul 2025 119,954.00 | 1 | −$22,014.30 |
| long | 22 Jul 2025 119,954.00 | 23 Jul 2025 118,756.00 | 1 | −$9,809.53 |
| short | 23 Jul 2025 118,756.00 | 11 Aug 2025 118,686.00 | 19 | $572.89 |
| long | 11 Aug 2025 118,686.00 | 17 Aug 2025 117,405.00 | 6 | −$10,497.70 |
| short | 17 Aug 2025 117,405.00 | 6 Sep 2025 110,188.00 | 20 | $59,143.40 |
| long | 6 Sep 2025 110,188.00 | 23 Sep 2025 111,999.00 | 17 | $16,783.60 |
| short | 23 Sep 2025 111,999.00 | 1 Oct 2025 118,595.00 | 8 | −$61,136.60 |
| long | 1 Oct 2025 118,595.00 | 10 Oct 2025 112,775.00 | 9 | −$47,946.00 |
| short | 10 Oct 2025 112,775.00 | 26 Oct 2025 114,559.00 | 16 | −$14,703.00 |
| long | 26 Oct 2025 114,559.00 | 3 Nov 2025 106,583.00 | 8 | −$63,657.50 |
| short | 3 Nov 2025 106,583.00 | 27 Nov 2025 91,333.90 | 24 | $121,699.00 |
| long | 27 Nov 2025 91,333.90 | 17 Dec 2025 86,243.20 | 20 | −$54,194.40 |
| short | 17 Dec 2025 86,243.20 | 20 Dec 2025 88,360.90 | 3 | −$22,544.20 |
| long | 20 Dec 2025 88,360.90 | 20 Jan 2026 88,427.70 | 31 | $676.64 |
| short | 20 Jan 2026 88,427.70 | 15 Feb 2026 68,832.60 | 26 | $198,605.00 |
| long | 15 Feb 2026 68,832.60 | 22 Mar 2026 67,859.00 | 35 | −$15,485.80 |
| short | 22 Mar 2026 67,859.00 | 25 Mar 2026 71,336.50 | 3 | −$55,313.90 |
| long | 25 Mar 2026 71,336.50 | 26 Mar 2026 68,820.30 | 1 | −$36,121.10 |
| short | 26 Mar 2026 68,820.30 | 6 Apr 2026 68,853.70 | 11 | −$478.75 |
| long | 6 Apr 2026 68,853.70 | 28 Apr 2026 76,342.80 | 22 | $107,404.00 |
| short | 28 Apr 2026 76,342.80 | 4 May 2026 79,861.00 | 6 | −$50,456.50 |
| long | 4 May 2026 79,861.00 | 12 May 2026 80,504.50 | 8 | $8,415.03 |
| short | 12 May 2026 80,504.50 | 13 Jun 2026 64,458.00 | 32 | $209,852.00 |
| long | 13 Jun 2026 64,458.00 | 27 Jun 2026 60,029.00 | 14 | −$86,760.20 |
| short | 27 Jun 2026 60,029.00 | 29 Jun 2026 60,260.20 | 2 | −$4,529.19 |
| long | 29 Jun 2026 60,260.20 | 30 Jun 2026 58,624.70 | 1 | −$31,792.10 |
| short | 30 Jun 2026 58,624.70 | 1 Jul 2026 60,024.00 | 1 | −$27,200.40 |
| long | 1 Jul 2026 60,024.00 | 27 Jul 2026 63,755.90 | 26 | $69,160.40 |
| short | 27 Jul 2026 63,755.90 | 7 Aug 2026 64,923.20 | 11 | −$21,633.50 |
| long | 7 Aug 2026 64,923.20 | 11 Aug 2026 63,600.00 | 4 | −$23,640.10 |
| short | 11 Aug 2026 63,600.00 | 18 Aug 2026 64,725.40 | 7 | −$20,106.70 |
| long | 18 Aug 2026 64,725.40 | 2 Sep 2026 77,340.00 | 15 | $217,535.00 |
| short | 2 Sep 2026 77,340.00 | 3 Sep 2026 81,270.40 | 1 | −$67,777.90 |
| long | 3 Sep 2026 81,270.40 | 4 Sep 2026 79,660.80 | 1 | −$25,072.30 |
| short | 4 Sep 2026 79,660.80 | 21 Sep 2026 86,620.00 | 17 | −$108,402.00 |
| long | 21 Sep 2026 86,620.00 | 29 Sep 2026 83,663.70 | 8 | −$38,650.60 |
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 |
|---|---|---|---|---|---|
| Simple-Compounded Returns & Drawdowns Table this page | — | v5 strategy | +9.4% | 76 | 46.4% |
| 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.
- 3 settings use the untyped input() (line 144, 145, 146). 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 76 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 144: input() → input.int()
- Line 145: input() → input.int()
- Line 146: input() → input.int()
⋯// This is a sample code of a working strategy to show the table in action-fastLength = input(12)+fastLength = input.int(12)-slowlength = input(26)+slowlength = input.int(26)-MACDLength = input(9)+MACDLength = input.int(9)MACD = ta.ema(close, fastLength) - ta.ema(close, slowlength)⋯Does it run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 76 before, 95 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © antondmt-//@version=5+//@version=6strategy("Returns & Drawdowns Table", "R & DD", true, calc_on_every_tick = false, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, process_orders_on_close = true)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 59 ms | Yes 1,000 bars in 261 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/// © antondmt//@version=5strategy("Returns & Drawdowns Table", "R & DD", true, calc_on_every_tick = false, default_qty_type = strategy.percent_of_equity, default_qty_value = 100, process_orders_on_close = true)i_eq_to_dd = input.string("Compound Equity", "Mode", ["Simple Equity", "Compound Equity", "Drawdown"], group = "R & DD Table")i_precision = input.int(2, "Return Precision", group = "R & DD Table")i_headers_col = input.color(#D4D4D4, "Headers Color", group = "R & DD Table")i_headers_text_col = input.color(color.black, "Headers Text Color", group = "R & DD Table")i_pos_col = input.color(color.green, "Positive Color", group = "R & DD Table")i_neg_col = input.color(color.red, "Negative Color", group = "R & DD Table")i_zero_col = input.color(#DDDDDD, "Zero Color", group = "R & DD Table")i_cell_text_col = input.color(color.white, "Cell Text Color", group = "R & DD Table")// TIME {var month_times = array.new_int(0) // Array of all month times new_month = month(time) != month(time[1]) if(new_month or barstate.isfirst) array.push(month_times, time)var year_times = array.new_int(0) new_year = year(time) != year(time[1]) if (new_year or barstate.isfirst) array.push(year_times, time)//}// SIMPLE EQUITY CALCULATIONS {// Simple equity is strictly calculated from start to end of each month/year equity. There is no compoundvar monthly_simp_pnls = array.new_float(0) // Array of all monthly profits and lossesvar yearly_simp_pnls = array.new_float(0) if(i_eq_to_dd == "Simple Equity") var initial_monthly_equity = strategy.equity // Starting equity for each month cur_month_pnl = nz((strategy.equity - initial_monthly_equity) / initial_monthly_equity) // Current month's equity change if(new_month or barstate.isfirst) initial_monthly_equity := strategy.equity array.push(monthly_simp_pnls, cur_month_pnl) else array.set(monthly_simp_pnls, array.size(monthly_simp_pnls) - 1, cur_month_pnl) var initial_yearly_equity = strategy.equity cur_year_pnl = nz((strategy.equity - initial_yearly_equity) / initial_yearly_equity) if (new_year or barstate.isfirst) initial_yearly_equity := strategy.equity array.push(yearly_simp_pnls, cur_year_pnl) else array.set(yearly_simp_pnls, array.size(yearly_simp_pnls) - 1, cur_year_pnl)// }// COMPOUND EQUITY CALCULATIONS {// Compound equity is strictly calculated based on equity state from the beginning of time until the end of each month/year equity. It shows the exact equity movement through timevar monthly_comp_pnls = array.new_float(0) // Array of all monthly profits and lossesvar yearly_comp_pnls = array.new_float(0) if(i_eq_to_dd == "Compound Equity") var initial_equity = strategy.equity cur_month_pnl = nz((strategy.equity - initial_equity) / initial_equity) // Current month's equity change if(new_month or barstate.isfirst) array.push(monthly_comp_pnls, cur_month_pnl) else array.set(monthly_comp_pnls, array.size(monthly_comp_pnls) - 1, cur_month_pnl) cur_year_pnl = nz((strategy.equity - initial_equity) / initial_equity) if (new_year or barstate.isfirst) array.push(yearly_comp_pnls, cur_year_pnl) else array.set(yearly_comp_pnls, array.size(yearly_comp_pnls) - 1, cur_year_pnl)// } // DRAWDOWN CALCULATIONS {// Drawdowns are calculated from highest equity to lowest trough for the month/yearvar monthly_dds = array.new_float(0) // Array of all monthly drawdownsvar yearly_dds = array.new_float(0) if (i_eq_to_dd == "Drawdown") total_equity = strategy.equity - strategy.openprofit var cur_month_dd = 0.0 var m_ATH = total_equity // Monthly All-Time-High (ATH). It is reset each month m_ATH := math.max(total_equity, nz(m_ATH[1])) m_drawdown = -math.abs(total_equity / m_ATH * 100 - 100) / 100 // Drawdown at current bar if(m_drawdown < cur_month_dd) cur_month_dd := m_drawdown if(new_month or barstate.isfirst) cur_month_dd := 0.0 m_ATH := strategy.equity - strategy.openprofit array.push(monthly_dds, 0) else array.set(monthly_dds, array.size(monthly_dds) - 1, cur_month_dd) var cur_year_dd = 0.0 var y_ATH = total_equity y_ATH := math.max(total_equity, nz(y_ATH[1])) y_drawdown = -math.abs(total_equity / y_ATH * 100 - 100) / 100 if(y_drawdown < cur_year_dd) cur_year_dd := y_drawdown if (new_year or barstate.isfirst) cur_year_dd := 0.0 y_ATH := strategy.equity - strategy.openprofit array.push(yearly_dds, 0) else array.set(yearly_dds, array.size(yearly_dds) - 1, cur_year_dd) // }// TABLE LOGIC { var main_table = table(na)table.clear(main_table, 0, 0, 13, new_year ? array.size(year_times) - 1 : array.size(year_times))main_table := table.new(position.bottom_right, columns = 14, rows = array.size(year_times) + 1, border_width = 1)t_set_headers() => // Sets time headers of the table // Set month headers table.cell(main_table, 0, 0, "", text_color = i_headers_text_col, bgcolor = i_headers_col) table.cell(main_table, 1, 0, "Jan", text_color = i_headers_text_col, bgcolor = i_headers_col) table.cell(main_table, 2, 0, "Feb", text_color = i_headers_text_col, bgcolor = i_headers_col) table.cell(main_table, 3, 0, "Mar", text_color = i_headers_text_col, bgcolor = i_headers_col) table.cell(main_table, 4, 0, "Apr", text_color = i_headers_text_col, bgcolor = i_headers_col) table.cell(main_table, 5, 0, "May", text_color = i_headers_text_col, bgcolor = i_headers_col) table.cell(main_table, 6, 0, "Jun", text_color = i_headers_text_col, bgcolor = i_headers_col) table.cell(main_table, 7, 0, "Jul", text_color = i_headers_text_col, bgcolor = i_headers_col) table.cell(main_table, 8, 0, "Aug", text_color = i_headers_text_col, bgcolor = i_headers_col) table.cell(main_table, 9, 0, "Sep", text_color = i_headers_text_col, bgcolor = i_headers_col) table.cell(main_table, 10, 0, "Oct", text_color = i_headers_text_col, bgcolor = i_headers_col) table.cell(main_table, 11, 0, "Nov", text_color = i_headers_text_col, bgcolor = i_headers_col) table.cell(main_table, 12, 0, "Dec", text_color = i_headers_text_col, bgcolor = i_headers_col) table.cell(main_table, 13, 0, str.tostring(i_eq_to_dd), text_color = i_headers_text_col, bgcolor = i_headers_col) // Set year headers for i = 0 to array.size(year_times) - 1 table.cell(main_table, 0, i + 1, str.tostring(year(array.get(year_times, i))), text_color = i_headers_text_col, bgcolor = i_headers_col)t_set_months() => // Sets inner monthly data of the table display_array = switch i_eq_to_dd "Simple Equity" => monthly_simp_pnls "Compound Equity" => monthly_comp_pnls => monthly_dds for i = 0 to array.size(month_times) - 1 m_row = year(array.get(month_times, i)) - year(array.get(year_times, 0)) + 1 m_col = month(array.get(month_times, i)) m_color = array.get(display_array, i) == 0 ? color.new(i_zero_col, transp = 30) : array.get(display_array, i) > 0 ? color.new(i_pos_col, transp = 30) : color.new(i_neg_col, transp = 30) table.cell(main_table, m_col, m_row, str.tostring(math.round(array.get(display_array, i) * 100, i_precision)), bgcolor = m_color, text_color = i_cell_text_col) t_set_years() => // Sets inner yearly data of the table display_array = switch i_eq_to_dd "Simple Equity" => yearly_simp_pnls "Compound Equity" => yearly_comp_pnls => yearly_dds for i = 0 to array.size(year_times) - 1 y_color = array.get(display_array, i) == 0 ? color.new(i_zero_col, transp = 30) : array.get(display_array, i) > 0 ? color.new(i_pos_col, transp = 20) : color.new(i_neg_col, transp = 20) table.cell(main_table, 13, i + 1, str.tostring(math.round(array.get(display_array, i) * 100, i_precision)), bgcolor = y_color, text_color = i_cell_text_col)t_set_headers() t_set_months()t_set_years()// }// PLACE YOUR STRATEGY CODE HERE {// This is a sample code of a working strategy to show the table in actionfastLength = input(12)slowlength = input(26)MACDLength = input(9)MACD = ta.ema(close, fastLength) - ta.ema(close, slowlength)aMACD = ta.ema(MACD, MACDLength)delta = MACD - aMACDif (ta.crossover(delta, 0)) strategy.entry("MacdLE", strategy.long, comment = "MacdLE")if (ta.crossunder(delta, 0)) strategy.entry("MacdSE", strategy.short, comment = "MacdSE")// }