Skip to content
All library documents

Autocorrelation Forecasting for Long-Only Strategy Backtests

Article TradingView scripts

Summary

This backtest template uses autocorrelation to detect repeating behavior in closing prices, then applies a linear regression of recent percentage returns to form a forecast component. When the autocorrelation exceeds a fixed threshold, the latest regression value is retained and used to estimate a future price. A long entry is submitted when the resulting hypothetical gain clears a user-set threshold and no trade is open; the take-profit limit is set to that projected gain.

Order quantity is derived from a configurable percentage of the strategy's initial capital. The strategy settings also specify commission, slippage, and processing orders on bar close. It is long-only and has no stop-loss, so a bad forecast can leave capital tied up in a losing position. The document presents source code and a usage example, but no test results or evidence that the forecast has predictive power. Its forecast construction and fixed modeling choices should therefore be treated as an educational template, not a validated trading system.

Key ideas

  • Autocorrelation between price series is used to flag a potential cycle.
  • A linear regression of recent returns supplies the forecast component when the cycle condition holds.
  • Long entries require projected gain to exceed a configurable threshold, with a limit take-profit based on that estimate.
  • Position quantity is calculated from a selected share of initial capital.
  • There is no stop-loss, and the document provides no performance evidence for the forecasting rule.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.