Guide
How does the Monthly Returns of a Strategy in a Chart strategy work ?
The "Monthly Returns of a Strategy in a Chart" on TradingView visualizes the monthly performance of a trading strategy through a table that resembles a bar chart. Due to TradingView's lack of direct support for such charts, this creative approach uses a table to emulate the visual representation of returns. You can customize the appearance of the 'chart' by configuring the location, bar height, bar width, and color schemes.
The strategy makes use of pivot points to initiate trades. A pivot high triggers a long entry (strategy.entry("PivRevLE")), and a pivot low triggers a short entry (strategy.entry("PivRevSE")). The plot changes based on these pivot points, using green lines for pivot highs and red lines for pivot lows.
The script then computes the monthly return of the equity, adding to the array of monthly returns each time a new month starts or at the last tick of the dataset. The visual output is dynamically updated based on the specified plot settings. The bar colors are green for positive returns and red for negative returns, reflecting the performance for each month. Monthly return percentages and the associated month are displayed on the bars upon hover for quick reference.
To achieve scalability of the bars according to the highest absolute return, a scaling coefficient is used, allowing users to get a visual sense of performance relative to the most significant gains or losses. The table's cells are carefully drawn to represent bars for each month, with tooltips providing details like the return percentage and the month. Additionally, the script outlines the Y-axis increments and labels for a cleaner look at the monthly performance overview. This innovative solution to displaying monthly returns on a chart is built using Pine Script in TradingView, courtesy of the collaborative efforts of the community.