Skip to content
All library documents

Comparing SMA Crossover Lengths with a Trade-Count-Weighted Score

Article TradingView scripts

Summary

This indicator compares simple moving average lengths from 10 to 1,000 in increments of 10. For each length, it tracks trades triggered when closing price crosses above or below the average, supporting either long-only or long-and-short mode. It calculates trade count, profit factor, and win rate, then ranks candidates with a score that rewards higher profit factor and win rate while also increasing with the logarithm of trade count. A minimum-trade threshold excludes candidates with too few observations, and the selected average and metrics appear on the chart.

The comparison is a historical fit to the chart’s available data, not evidence of future performance. The code uses closing prices for entries and exits and does not model transaction costs, slippage, or position sizing in its custom trade calculations. The broad search across many lengths can select a parameter by chance, and the score’s assumptions may not suit every objective. The document reports no empirical results or out-of-sample validation.

Key ideas

  • The indicator evaluates SMA lengths from 10 through 1,000 at fixed intervals.
  • Price crossings of each average define entries and exits for the selected direction mode.
  • A ranking score combines profit factor, win rate, and the logarithm of trade count.
  • A configurable minimum number of trades filters candidate averages.
  • The selected length is based on historical data and may be affected by overfitting.

Tags

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