Tracking Monthly and Yearly Strategy Returns in Pine Script
Summary
This document shows how to add a calendar-based return table to a TradingView strategy. It derives each bar’s equity return from consecutive strategy equity values, compounds those returns within the current month and year, and stores completed period results for display. A table places monthly figures by calendar year and adds an annual total, with cell colors distinguishing positive and nonpositive results.
The example combines this reporting tool with a pivot-point strategy that places stop entries around detected swing highs and lows. The stated purpose of the table is to make it easier to inspect periods of stronger or weaker historical performance without exporting trades for manual analysis. No performance results or comparative evidence are provided. The figures reflect the strategy’s backtest equity and should be treated as historical diagnostics; the author cautions that past performance may not persist as market conditions change.
Key ideas
- The script calculates bar-level returns from changes in strategy equity.
- It compounds bar returns separately within each calendar month and year.
- A table organizes monthly returns by year and displays an annual figure.
- The example strategy uses pivot highs and lows to define stop-entry levels.
- Historical return tables help locate periods for further review but do not establish future performance.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.