OPEN-SOURCE SCRIPT

ARIMA Moving Average and Forecaster [SS]

Actualizado
Finally releasing this. This took months, over 3 months to be precise, to figure out, code and troubleshoot! I honestly was going to give up on this project, but I finally got it to actually work fairly reliably. So hopefully you like it!

This is a very basic ARIMA modeler. It can do the following:

1. Provide you with an ARIMA based Moving Average;
2. Provide you with a standard error band;
3. Auto-select a lag length for assessment based on stationarity;
3. Provide you with the option of extending the error range by a user selected amount of standard deviations; and
4. Forecasting and plotting the forecast on the chart.

I will go over each function individually, but before I do, I think its important to talk a bit about what an ARIMA Model is and does:

ARIMA stands for AutoRegressive Integrated Moving Average and is an approach to modeling and time series forecasting. In simple terms, it combines autoregressive (AR) and moving average (MA) components to capture the underlying patterns in a time series data. The "AutoRegressive" part accounts for the relationship between an observation and its previous values, while the "Moving Average" part considers the relationship between an observation and a residual error from past observations. The "Integrated" component involves differencing the time series to make it stationary, which aids in stabilizing the model. ARIMA models help predict future values based on patterns observed in historical data, making them useful for forecasting in various fields such as economics, finance, and weather prediction.

The benefits to ARIMA is it will forecast based on the current trend, but it also provides for both the up and down scenario of the trend (i.e., if we are in a downtrend, what it would look like and what values we could expect if the trend reverses and vice versa). All of this is within the scope of this indicator, believe it or not!

If you would like more information on ARIMA, you can check out my educational post about it here:
All about ARIMA Modeling


Alrighty, now for the indicator functions.

ARIMA Moving Average and Standard Error Band

imagen

The ARIMA moving average is very simple, it takes the SMA of the current trend, lags it and plots out the lagged SMA. You can toggle the auto-select lag on, or you can pick your own lag manually. The above image is an auto-selected lag, but if we manually lag it by 5, this is what it looks like:

imagen

Its simply a lagged average of the 5 SMA (that is essentially how ARIMA works, by creating a moving average and lagging the moving average).

There are some implications to selecting a lag factor when it comes to forecasting, but I will cover this in the forecasting section. But I do want to make mention, you can use the ARIMA moving average in lieu of other moving averages. The advantage to doing this is it will be able to plot out the error bands. For example, if we wanted to get an ARIMA MA of the 200 SMA, we can toggle on the error bands and this is what we get:

imagen

Or the 50 MA:

imagen

NOTE: You ABSOLUTELY SHOULD NEVER use more than a lag of 4 or 5 for Forecasting (will be discussed later).

Auto-Select Lag

The indicator pulls the ARIMA modeler framework from my Forecasting library and pulls the stationarity assessment from my SPTS library. When you are doing an ARIMA model for forecasting, we need to ensure the data is stationary. Thus, if you want to forecast out the current trend, its highly recommended you select the "Auto Determine Lag Length" to find the most appropriate lag and forecast accordingly.

You can, however, chose your own lag order (model order), but this should never be above 4 or 5.

You should never select a lag of more than 5 because you are introducing too much "trendiness" into the equation, and you will get astronomical readings. ARIMA models never generally exceed a lag of 3 or 4 at most, as they are supposed be stationary and de-trended.


Extending by Standard Deviation

There is an option to select a standard deviation extension band. This is helpful for active day trading. Here is NIO extended by 2 standard deviations:

imagen

General suggestion is to only extend by 2 standard deviations and this is sufficient for most stocks.

Forecasting

The hallmark of an ARIMA model is the ability to use it for forecasting. Thus, the forecasting feature is a large portion of this indicator. You can see it displayed in the main chart above, but let's show some other examples:

NIO on the 1 hour:

imagen

TSLA on the 4 hour:

imagen

You can also display a forecasting table:

imagen

The result row shows the most likely, conservative, price at each time increment.
The Upper Confidence and Lower Confidence show what the trend would look like if it continued up or down at the current rate and the 95% confidence intervals show the values that the true source is likely to fall between at various increments in time with a 95% confidence (i.e. 95% probability that it should fall between these levels at period xyz assuming normal distribution).

The important levels, in my opinion, are the upper and lower confidence levels. These show you the current rate of decline or increase that the stock is expecting and what the trend would look like with a continuation or a reversal. This is ARIMA's biggest strength, as it has the ability to plot both outcomes assuming the current trend rate and time remains constant.


And that is the indicator! ARIMA is a bit of a complex process, but its a very powerful tool when used properly!

Troubleshooting:

One thing of note. Sometimes when autoselecting a length for forecasting, if there has been a heavy trend in one direction, you will not get the upper or lower confidence levels because of the lack of any up or down movement. In this case, manually select a lag of 3 to 5 to correct for this.

Let me know if you have any questions below and safe trades everyone!

Notas de prensa
Just had to fix a spelling error and default lag value as it was annoying me.

But also just wanted to respond to a question, as you can't anchor this indicator in the past, if you want to use it for forecasting weekly levels or intraday, draw out the trendlines and then just mute the indicator. Here are some sample forecasts for this week:

SPY:
imagen

NQ:
imagen


NVDA
imagen

Its surpassed my own expectations so I do hope you enjoy it and find it helpful!

Safe trades everyone!
Notas de prensa
Per request, I have added the ability to customize your rounding values for the forecast functions:
imagen

This is critical for you FOREX traders who need more decimal points.
IF you are trading FOREX, suggested round number is 5.
forecastingstatistics

Script de código abierto

Siguiendo fielmente el espíritu de TradingView, el autor de este script lo ha publicado en código abierto, permitiendo que otros traders puedan entenderlo y verificarlo. ¡Olé por el autor! Puede utilizarlo de forma gratuita, pero tenga en cuenta que la reutilización de este código en la publicación se rige por las Normas internas. Puede añadir este script a sus favoritos y usarlo en un gráfico.

¿Quiere utilizar este script en un gráfico?


For real-time updates and premium indicators, consider joining my group at: patreon.com/steversteves
También en:

Exención de responsabilidad