
この策略は,Zスコア ((Z-Score) という統計学的な概念に基づいている. 価格の局所平均に対する統計的偏差を識別するために使用される. この策略は,閉店価格のZスコアを計算し,その後,短期および長期の移動平均をZスコアを平らげるために適用する. 短期平らなZスコアの上に長期平らなZスコアを通るときに多頭入場信号を生成し,短期平らなZスコアの下に長期平らなZスコアを通るときに平衡信号を生成する.
この戦略の核心は,Zスコアの計算と適用である.Zスコアは,標準差単位で,データポイントがサンプル平均から偏っている程度を測定するための統計量である.この戦略では,Zスコアの計算の公式は次のとおりである. Z = (終了価格 - SMA (終了価格,N)) / STDEV (終了価格,N) Nはユーザ定義の基本周期である.
戦略の実行プロセスは以下の通りです.
追加条件は以下の通りです.
解決策は
スムーズZスコア交差に基づく動的最適化価格統計取引戦略は,統計学原理に基づく簡潔な取引システムで,価格の局所平均値に対する偏差と回帰を捕捉することに焦点を当てている.スムーズ処理,信号間隔制御,動的量フィルタリングにより,この戦略は,ノイズ取引を効果的に減らし,信号品質を向上させる.この戦略は,特に揺れ動いた市場と均等値回帰行動が顕著な金融商品に適している.
しかし,戦略には,統計的仮定,パラメータの感度,単一因子決定などの依存などのいくつかの制限があります. トレンド識別,波動性調整,複数時間枠分析,ストップダストメカニズム,交付量確認,および複数の因子組み合わせなどの最適化措置を追加することによって,戦略の頑丈性とパフォーマンスを大幅に向上させることができます.
全体として,これは理論的な基礎が堅固で,簡潔で,理解しやすい,拡張可能な戦略的枠組みを実現し,取引システムの基本的な構成要素として,または,取引における統計学の応用を理解するトレーダーを支援する教育ツールとして適しています.
/*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))