This Zorro lite-C script plots a EUR/USD daily chart that combines a traditional SMA indicator with an external ARIMA forecast. It imports selected functions from AutoAri32.dll and defines a minimal AUTO_ARIMA_RESULT structure so the DLL can return the selected ARIMA order, convergence state, forecast value, and AICc score. During each run, the script loads EUR/USD closing prices, calculates a 20-period simple moving average, and skips execution until the LookBack period is complete. The ARIMA model uses the previous 120 completed closing prices to generate a one-step forecast. Before forecasting, the price series is validated, and the result is checked for convergence, invalid values, and a realistic EUR/USD range. If ARIMA fails, the script safely falls back to the previous close. It then plots price, SMA20, ARIMA forecast, and forecast error in pips, while printing diagnostic model statistics to the log.

Code
// Arima01.c
// EUR/USD SMA + ARIMA forecast
// Requires AutoAri32.dll in the same folder as this script.

// Minimal copy of AUTO_ARIMA_RESULT from aa_arima_types.h.
// Field names can be local; order and types must match the DLL.
typedef struct
{
    int p;
    int d;
    int q;
    int converged;

    var sse;
    var aicc;
    var forecast;

    var* ar;
    var* ma;

    int arCap;
    int maCap;

} AUTO_ARIMA_RESULT;

#define PRAGMA_API init_auto_arima_result;AutoAri32!init_auto_arima_result
#define PRAGMA_API free_auto_arima_result;AutoAri32!free_auto_arima_result
#define PRAGMA_API auto_arima_forecast;AutoAri32!auto_arima_forecast
#define PRAGMA_API aa_validate_price_series;AutoAri32!aa_validate_price_series

void init_auto_arima_result(AUTO_ARIMA_RESULT* R);
void free_auto_arima_result(AUTO_ARIMA_RESULT* R);
int auto_arima_forecast(vars Close,int N,var TickSize,int MaxP,int MaxQ,AUTO_ARIMA_RESULT* Result);
int aa_validate_price_series(vars Close,int N);

#define ARIMA_WINDOW 120

function run()
{
    set(PLOTNOW,LOGFILE);

    BarPeriod = 1440;
    LookBack = ARIMA_WINDOW + 50;
    MaxBars = 800;

    PlotWidth = 1200;
    PlotHeight1 = 600;
    PlotBars = 300;

    asset("EUR/USD");

    vars Price = series(priceClose());

    var SMA20 = SMA(Price,20);

    if(is(LOOKBACK))
        return;

    var Forecast = Price[1]; // safe fallback
    int Status = 0;

    AUTO_ARIMA_RESULT R;
    init_auto_arima_result(&R);

    // The library documents price-series validation before model use.
    // It checks positive prices, invalid values, and enough samples.
    if(aa_validate_price_series(Price+1,ARIMA_WINDOW))
    {
        Status = auto_arima_forecast(Price+1,ARIMA_WINDOW,PIP,3,3,&R);

        if(Status and R.converged and !invalid(R.forecast))
        {
            if(R.forecast > 0.5 and R.forecast < 2.0)
                Forecast = R.forecast;
        }
    }

    var ErrorPips = (Price[0] - Forecast) / PIP;

    plot("Close",Price[0],MAIN|LINE,BLUE);
    plot("SMA20",SMA20,MAIN|LINE,RED);
    plot("ARIMA",Forecast,MAIN|LINE,GREEN);
    plot("ErrPips",ErrorPips,NEW|LINE,BLACK);

    printf(
        "\nBar %i Close %.5f SMA20 %.5f ARIMA %.5f Err %.2f pips Status %i p=%i d=%i q=%i AICc %.4f",
        Bar,
        Price[0],
        SMA20,
        Forecast,
        ErrorPips,
        Status,
        R.p,
        R.d,
        R.q,
        R.aicc
    );

    free_auto_arima_result(&R);
}