INVITE-ONLY SCRIPT

MAPE of Expected Value and Percent Residuals

Overview

This indicator calculates and visualizes the Mean Absolute Percentage Error (MAPE) and the percent residuals of the expected value compared to the actual closing price. The purpose of this indicator is to provide insights into the accuracy of price forecasts by comparing predicted values to actual market outcomes. The expected values are derived from the transform model, which uses the mean line from the mean and standard deviation lines as an indicator for expected price movement. Users can customize the number of periods over which calculations are averaged.

Inputs

  1. Mean Period (Bars): Specifies the number of bars used to calculate the moving average of the change between closing prices. This value should match the value used in the mean and standard deviation lines indicator.
  2. MAPE Period (Bars): Specifies the number of bars used to calculate the moving average of the absolute percentage error.


Outputs

  1. Percent Residuals Histogram: Displays the percentage error between the predicted (expected) value and the actual closing price. The bars are color-coded, with green indicating positive residuals (i.e., the actual value is higher than the predicted value) and red indicating negative residuals (i.e., the actual value is lower than the predicted value).
  2. Reference Line: A horizontal line at zero is added to the chart to indicate the baseline for percent residuals.
  3. Mean Absolute Percentage Error (MAPE) Line: Plots the moving average of the absolute percentage error over the specified period, helping users gauge the average accuracy of their predictions over time.


Methodology

  1. Calculation of Individual Bar Normalized Residuals: The normalized residuals for each bar are computed by taking the difference between the actual closing price and the predicted (expected) value, divided by the closing price. If the actual closing price is above the expected value, the residual is considered positive and is represented in green; otherwise, it is negative and represented in red. This normalization provides a standardized measure of deviation that allows for consistent comparison across different bars.
  2. Mean Absolute Percentage Error (MAPE) Calculation: Over the user-defined period, the absolute values of the normalized residuals are computed and subsequently averaged to determine the Mean Absolute Percentage Error (MAPE). This metric quantifies the average magnitude of the forecast errors, providing a clear indication of the model's predictive accuracy over time.


How to Use

  1. Add Indicators to Chart: First, apply the mean and standard deviation lines indicator to the chart, then add the MAPE of Expected Value and Percent Residuals indicator to evaluate the accuracy of price forecasts.
  2. Set Parameters: Set the `Mean Period (Bars)` to be the same value in both the mean and standard deviation lines indicator and the MAPE indicator to ensure accuracy. Adjust the `MAPE Period (Bars)` to fine-tune the length of historical data used in calculating the MAPE.
  3. Interpret Residuals and MAPE: Use the percent residuals histogram to understand how the actual closing price deviates from predictions. The MAPE line helps track the average prediction accuracy over time.


This tool is particularly useful for traders who want to evaluate the performance of their price prediction models based on the transform model and track how well their expected values, derived from mean and standard deviation lines, align with actual market movements.

forecastingstatistics

僅限邀請腳本

僅限作者授權的用戶訪問此腳本,並且通常需要付費。您可以將其增加到收藏腳本中,但是只有在向作者請求並獲得許可之後,才能使用它。 請聯繫oisigma以了解更多信息,或按照下面作者的說明進行操作。

TradingView 不建議購買並使用此腳本,除非您 100% 信任其作者並了解腳本的工作原理。在許多情況下,您可以在我們的社群腳本中免費找到良好的開源替代方案。

作者的說明

visit oisigma.com to subscribe.

想在圖表上使用此腳本?

警告:請閱讀,然後再請求訪問權限。

更多:

免責聲明