A moving-average crossover is easy to describe and easy to over-search. A fast average may cross above or below a slower average, producing a rule event. The difficulty is deciding which averages, signal timing, exit and cost assumptions were specified before looking at the results—and whether an attractive parameter pair is only the best among many attempts.
Write one version before making a grid
Choose the instrument, timeframe, data source and dates. State the input price, averaging method and periods for both windows. Define a bullish event as the fast average crossing above the slow one on a completed bar, or define the opposite direction; do not substitute a state such as “fast average currently above slow” without recording that as a separate rule. Set the first eligible signal time after the warm-up, the later entry-price convention, permitted direction, exit, position size and maximum hold. The Pine Script v6 reference distinguishes moving-average and crossover built-ins; document the functions and source values used if reproducing a rule there.
For a simple moving average, the value at bar t is the arithmetic mean of the current close and the preceding n − 1 closes. That makes the input price and when the bar is complete part of the definition. An exponential moving average assigns different weights and can cross on a different bar; never swap SMA for EMA after seeing which version looks better.
Work a crossover by hand
Consider six fictional closes: 100, 99, 98, 99, 100, 102. Use a 3-bar SMA as the fast average and a 5-bar SMA as the slow average. At bar 5, the fast average is (98 + 99 + 100) ÷ 3 = 99.00, while the slow average is (100 + 99 + 98 + 99 + 100) ÷ 5 = 99.20. The fast line is still below the slow line.
At bar 6, the fast average becomes (99 + 100 + 102) ÷ 3 = 100.33. The slow average is (99 + 98 + 99 + 100 + 102) ÷ 5 = 99.60. Comparing the relationship on consecutive completed bars identifies an upward cross: it changed from below to above. The calculation does not say whether to trade, how much to risk or where to exit. These six prices exist only to make the arithmetic inspectable.
If the close is used in the averages, a bar-6 signal is not known at that bar’s open. Under TradingView Pine v6’s default strategy behavior, a strategy calculated after the close creates a market order for the next available tick, ordinarily the following bar’s open. That is a platform-specific broker-emulator convention, not a guarantee of a real fill; settings can change the modeled timing. In your own test, write the signal timestamp and modeled fill timestamp as separate fields. A same-bar-open entry based on the final close leaks information from the future.
For a small illustration, a researcher might predeclare fast windows of 3, 5 and 8 bars and slow windows of 10, 15 and 20 bars, producing nine candidate pairs. These are teaching values, not recommended settings. Periods are measured in bars, so a “20-period” rule means different holding horizons on 5-minute and daily data. A larger grid may be justified, but every tested combination adds to the record of choices. Name the metric you will compare, the benchmark, and the maximum acceptable drawdown or other failure criteria before running the grid. Avoid choosing a new metric after seeing which one makes the chart look best.
Include a simple baseline suited to the question. For example, compare the rule’s equity path with holding the same starting capital in the underlying over the identical interval, then report the strategy’s average exposure and any cash not deployed. A fully invested buy-and-hold path and a frequently changing, partially invested strategy have different risk and exposure; one return percentage cannot settle which process was better. If direction is long-only, do not silently count periods below the slow average as profitable short positions. If the rule is long/short, model both sides explicitly.
Keep evaluation chronological
Use earlier observations to implement and compare candidate settings. Keep later observations out of the tuning process. Evaluate the selected rule once on that later interval, then mark the interval as used if it affects a further adjustment. Overlapping rolling windows mean adjacent signals are not necessarily independent, and a large number of hourly rows is not the same as a large number of distinct market regimes.
Report the whole grid or a faithful summary of it. Show the median and spread of candidate outcomes as well as the chosen setting, and explain whether the chosen pair was set in advance or selected from results. Inspect small changes around the chosen periods. If nearby windows produce very different behavior, describe the result as parameter-sensitive. A simple out-of-sample split limits one form of data reuse but does not erase experiments already conducted by the researcher.
Confirm the signal is causal
An average that includes a candle’s final close is only known after that candle closes. Do not use it to fill earlier in the same candle. Document the timestamp and price used for the signal and the subsequent entry. Confirm the implementation against a small hand-calculated example or a separate unit test. Handle early windows with insufficient history as unavailable observations, not zero-valued indicators.
The SuperQuant trend implementation uses a fast/slow SMA crossover at the previous closed hourly bar and evaluates entry at the next bar’s open under common engine rules. The product’s defaults are example settings, not validated recommendations. Its supplied data are synthetic, and its run cannot establish a live market edge. Other applications may define EMA, SMA, persistent-state entries or exits differently. Confirm the actual code and configuration before describing what a tool tests. TradingView’s current Pine Script v6 strategy documentation describes its broker emulator and default next-tick fill convention; those controls explain that platform only.
Add the costs and preserve the result
Apply the same fee, spread, slippage and funding assumptions to each candidate. If these costs change with notional or instrument, represent that or name the approximation. Perpetuals also require the actual funding convention, direction and eligible settlement times. Report the chosen rule next to the median and spread of all candidate results, the total trial count, the number of trades and the weakest reasonable cost scenario. A low trade count or one favorable window is a limitation to state, not a reason to hide other trials.
Compare the outcomes to a baseline, and retain a ledger with trades, return path, drawdown, holding time and exposure. Keep rejected settings, code version, data fingerprint and dates together so another person can reproduce which rule was examined. Separate parameters fixed before the study from those chosen using the training interval. A later holdout stops being untouched once it changes a parameter, filter, metric or even the next research question; preserve that result and obtain a new evaluation period for the changed rule.
For background, read crypto trend following, the look-ahead bias guide, and the backtest-overfitting guide. The backtest audit checklist records the assumptions. This is an implementation and research method, not a performance claim or individualized investment advice.