Tracking Monthly and Yearly Strategy Returns in Pine Script
Summary
This Pine Script example adds a monthly and yearly return table to a strategy chart. It derives per-bar percentage changes from the strategy equity curve, compounds those changes within each calendar month and year, and stores completed period returns with their timestamps. On the last chart bar, it presents a grid with months as columns, years as rows, and an annual total column, using color to distinguish positive from non-positive returns. The included trading logic uses pivot highs and lows to place stop entries just beyond the most recently detected pivot levels.
The excerpt ends partway through the table-rendering logic, so the full display behavior cannot be checked from the supplied text. It provides code rather than measured evidence that a particular strategy is profitable. Monthly summaries can help inspect return distribution over time, but they do not show drawdowns, exposure, or whether results survive fees and execution effects. The example includes commission settings, though the excerpt reports no resulting monthly figures or backtest period.
Key ideas
- The example calculates bar-level returns from changes in strategy equity.
- It compounds bar returns within each month and calendar year, then stores completed period values.
- The table layout places months across columns and years down rows, with a separate annual return column.
- The associated strategy uses pivot highs and lows to set stop entries beyond detected turning points.
- The provided excerpt is incomplete and contains no reported return figures or other backtest results.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.