Overview
This strategy is based on the Z-Score statistical concept, used to identify statistical deviations of price relative to its local mean. The strategy calculates the Z-Score of closing prices and applies short-term and long-term moving averages to smooth the Z-Score values. Long entry signals are generated when the short-term smoothed Z-Score crosses above the long-term smoothed Z-Score, and exit signals are generated when the short-term smoothed Z-Score crosses below the long-term smoothed Z-Score. The strategy also includes signal spacing control and momentum-based candle filters to reduce noise trading.
Strategy Principles
The core of this strategy is the calculation and application of Z-Score. Z-Score is a statistical measure that quantifies how far a data point is from the sample mean, measured in standard deviations. In this strategy, the Z-Score calculation formula is:
Z = (Close - SMA(Close, N)) / STDEV(Close, N)
where N is the user-defined base period.
The strategy execution process is as follows:
- Calculate the raw Z-Score of the closing price
- Apply short-term smoothing (SMA) to the raw Z-Score
- Apply long-term smoothing (SMA) to the raw Z-Score
- When the short-term smoothed Z-Score crosses above the long-term smoothed Z-Score, if additional conditions are met, open a long position
- When the short-term smoothed Z-Score crosses below the long-term smoothed Z-Score, if additional conditions are met, close the position
Additional conditions include:
- Signal gap: A minimum number of candles must pass between two signals of the same type (entry or exit)
- Momentum filter: Entry is prohibited when three or more consecutive bullish candles occur; exit is prohibited when three or more consecutive bearish candles occur
Strategy Advantages
- Statistical Foundation: Z-Score is a mature statistical tool that effectively identifies the degree to which prices deviate from their mean, suitable for capturing mean reversion opportunities.
- Smoothing Processing: By applying short-term and long-term smoothing to the raw Z-Score, noise is reduced and signal quality is improved.
- Signal Spacing Control: By setting a minimum signal gap, excessive trading and redundant signals are effectively reduced.
- Momentum Filter: By prohibiting counter-trend trading in strong trends, unnecessary losses in strong market conditions are avoided.
- Simplicity: The strategy only uses closing price data, does not rely on complex indicator combinations, and is easy to understand and implement.
- Real-time P&L Monitoring: Includes a table displaying unrealized profit and loss in real-time, facilitating position status monitoring for traders.
- Parameter Flexibility: Users can adjust the Z-Score base period and smoothing parameters according to different markets and timeframes, improving adaptability.
Strategy Risks
- Statistical Assumption Risk: Z-Score assumes that price distribution approximates a normal distribution and may perform poorly in markets with non-normal distributions.
- Parameter Sensitivity: The choice of Z-Score base period and smoothing parameters has a significant impact on strategy performance. Improper parameter selection may lead to overfitting or signal lag.
- Single-Factor Limitation: The strategy generates signals based solely on Z-Score crossovers, lacking other confirmation indicators, which may lead to false signals.
- Market Environment Dependency: In strong trending markets, mean-reversion based strategies may continuously produce erroneous signals.
- Signal Lag: Due to the use of moving average smoothing, signals may exhibit lag, missing optimal entry or exit points.
Solutions:
- Backtest different market environments to find optimal parameter combinations
- Integrate trend filters to reduce or disable trading in strong trending markets
- Add additional confirmation indicators such as volume analysis or other technical indicators
- Consider using adaptive parameters that automatically adjust based on market volatility
Optimization Directions
- Trend Recognition Integration: Add trend recognition components to adjust strategy behavior in markets with clear trend directions. This can be implemented through long-term moving averages or ADX indicators, avoiding incorrect mean reversion signals in strong trends.
- Volatility Adjustment: Implement adaptive adjustment of Z-Score parameters based on market volatility to automatically optimize the base period and smoothing parameters. This will improve strategy robustness across different market environments.
- Multiple Timeframe Analysis: Integrate Z-Score signals from higher timeframes as confirmation, only trading when signals across multiple timeframes align, reducing false signals.
- Stop Loss Mechanism: Implement dynamic stop losses based on Z-Score fluctuation ranges to enhance risk management capabilities. For example, stops could be set at specific deviation multiples from the entry Z-Score.
- Partial Profit Taking: Implement a staged profit-taking strategy, partially closing positions when Z-Scores reach specific thresholds to optimize capital management.
- Volume Confirmation: Add volume analysis as trade confirmation, executing trades only when Z-Score signals are supported by volume, improving signal quality.
- Indicator Combination: Combine Z-Score with other statistical or technical indicators, such as RSI or Bollinger Bands, to create a multi-factor decision model, enhancing strategy reliability.
Summary
The Momentum-Filtered Smoothed Z-Score Crossover Price Statistical Trading Strategy is a concise trading system based on statistical principles, focused on capturing price deviations and reversions relative to local means. Through smoothing processing, signal spacing control, and momentum filtering, the strategy effectively reduces noise trading and improves signal quality. The strategy is particularly suitable for oscillating markets and financial products with obvious mean-reversion behavior.
However, the strategy also has some limitations, such as dependence on statistical assumptions, parameter sensitivity, and single-factor decision-making. By adding trend recognition, volatility adjustment, multi-timeframe analysis, stop-loss mechanisms, volume confirmation, and multi-factor combinations, the robustness and performance of the strategy can be significantly enhanced.
Overall, this is a strategy framework with solid theoretical foundations, simple implementation, and ease of understanding and extension. It is suitable as a basic component of trading systems or as an educational tool to help traders understand the application of statistics in trading.
Strategy source code
/*backtest
start: 2024-06-03 00:00:00
end: 2025-06-02 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/
//@version=6
strategy("Price Statistical Strategy-Z Score V 1.01", overlay=true)
// === Enable / Disable Z-Score Strategy Block ===
enableZScore = input.bool(true, title="Enable Smoothed Z-Score Strategy", tooltip="When enabled, this block calculates a smoothed Z-Score of the closing price and generates entry/exit signals based on crossover behavior between short-term and long-term smoothed Z-Scores.\n\nRecommended for quick and classic detection of price deviation from mean.\nSensitive to outliers. Best suited for relatively normal-distributed market conditions.")
// === Z-Score Parameters ===
zBaseLength = input.int(3, minval=1, title="Z-Score Base Period")
shortSmooth = input.int(3, title="Short-Term Smoothing")
longSmooth = input.int(5, title="Long-Term Smoothing")
// === Z-Score Calculation Function ===
f_zscore(src, length) =>
mean = ta.sma(src, length)
std_dev = ta.stdev(src, length)
z = (src - mean) / std_dev
z
// === Z-Score Logic ===
zRaw = f_zscore(close, zBaseLength)
zShort = ta.sma(zRaw, shortSmooth)
zLong = ta.sma(zRaw, longSmooth)
// === Minimum gap between identical signals ===
gapBars = input.int(5, minval=1, title="Bars gap between identical signals", tooltip="Minimum number of bars required between two identical signals (entry or exit). Helps reduce signal noise.")
// === Candle-based momentum filters ===
bullish_3bars = close > close[1] and close[1] > close[2] and close[2] > close[3] and close[3] > close[4]
bearish_3bars = close < close[1] and close[1] < close[2] and close[2] < close[3] and close[3] < close[4]
// === Entry and Exit Logic with minimum signal gap and candle momentum filter ===
var int lastEntryBar = na
var int lastExitBar = na
if enableZScore
longCondition = (zShort > zLong)
exitCondition = (zShort < zLong)
if longCondition and (na(lastEntryBar) or bar_index - lastEntryBar > gapBars) and not bullish_3bars
strategy.entry("Z Score", strategy.long)
lastEntryBar := bar_index
if exitCondition and (na(lastExitBar) or bar_index - lastExitBar > gapBars) and not bearish_3bars
strategy.close("Z Score", comment="Z Score")
lastExitBar := bar_index
// === Real-time PnL Table for Last Open Position ===
var table positionTable = table.new(position.bottom_right, 2, 2, border_width=1)
// Header Labels
table.cell(positionTable, 0, 0, "Entry Price", text_color=color.white, bgcolor=color.gray)
table.cell(positionTable, 1, 0, "Unrealized PnL (%)", text_color=color.white, bgcolor=color.gray)
// Values (only when position is open)
isLong = strategy.position_size > 0
entryPrice = strategy.position_avg_price
unrealizedPnL = isLong ? (close - entryPrice) / entryPrice * 100 : na
// Define dynamic text color for PnL
pnlColor = unrealizedPnL > 0 ? color.green : unrealizedPnL < 0 ? color.red : color.gray
// Update Table Content
if isLong
table.cell(positionTable, 0, 1, str.tostring(entryPrice, "#.####"), text_color=color.gray, bgcolor=color.new(color.gray, 90))
table.cell(positionTable, 1, 1, str.tostring(unrealizedPnL, "#.##") + " %", text_color=pnlColor, bgcolor=color.new(pnlColor, 90))
else
table.cell(positionTable, 0, 1, "—", text_color=color.gray, bgcolor=color.new(color.gray, 90))
table.cell(positionTable, 1, 1, "—", text_color=color.gray, bgcolor=color.new(color.gray, 90))
Strategy parameters
The original address: Momentum-Filtered Smoothed Z-Score Crossover Price Statistical Trading Strategy
Really interesting approach! I like how you’ve combined momentum filtering with a smoothed Z-Score crossover — it adds a nice statistical layer to price action strategies. The use of signal smoothing helps reduce noise, which is super helpful in volatile markets. Also appreciate the clear breakdown of the logic and charts to support it. Definitely a strategy worth testing across different market conditions. Looking forward to more innovations like this!