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

Script sur invitation seulement

L'accès à ce script est limité aux utilisateurs autorisés par l'auteur et nécessite généralement un paiement. Vous pouvez l'ajouter à vos favoris, mais vous ne pourrez l'utiliser qu'après avoir demandé et obtenu l'autorisation de son auteur. Contactez oisigma pour plus d'informations, ou suivez les instructions de l'auteur ci-dessous.

TradingView ne suggère pas de payer pour un script et de l'utiliser à moins que vous ne fassiez confiance à 100% à son auteur et que vous compreniez comment le script fonctionne. Dans de nombreux cas, vous pouvez trouver une bonne alternative open-source gratuite dans nos Scripts communautaires.

Instructions de l'auteur

visit oisigma.com to subscribe.

Vous voulez utiliser ce script sur un graphique ?

Avertissement: veuillez lire avant de demander l'accès.

Aussi sur:

Clause de non-responsabilité