
これは,双均線交差信号に基づく量化取引戦略である.この戦略は,2つの移動平均を採用し,一つは主信号線,もう一つは平滑信号線である.価格と平滑信号線の交差状況を監視して取引信号を生成し,市場動向の把握と動力を追跡する.この戦略の核心的な優位性は,シンプルで効果的な信号生成機構と柔軟なパラメータ配置オプションにある.
策略は,2つのレベルの移動平均計算を使用する. まず,基本移動平均を計算する (デフォルト周期は9) そして,この平均線を二次平滑処理する (デフォルト周期は5). 策略は,単純な移動平均 (SMA),指数移動平均 (EMA),平滑移動平均 (SMMA),加重移動平均 (WMA) および成交量加重移動平均 (VWMA) を含む,複数の平均線計算方法を選択する. 收盘価格が平滑線を上方に突破すると,マルチシグナルを生成する. 收盤価格が平滑線を下方に突破すると,空隙シグナルを生成する.
これは,クラシックなトレンド追跡戦略の改良版であり,双層の移動平均の設計によって,戦略の簡素性を保ちながら,安定性を高めています.戦略は,優れた拡張性と柔軟性を持ち,パラメータの最適化と機能拡張により,異なる市場環境に対応できます.しかし,ユーザーは取引コストの制御とリスク管理に注意する必要があります.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-25 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Moving Average 1.0 Strategy", overlay=true)
// Input for Moving Average Length
len = input.int(9, minval=1, title="Length")
src = input(close, title="Source")
offset = input.int(title="Offset", defval=0, minval=-500, maxval=500)
// Calculate the Moving Average
out = ta.sma(src, len)
// Plot the Moving Average
plot(out, color=color.blue, title="MA", offset=offset)
// Function to choose the type of moving average
ma(source, length, type) =>
switch type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
// Input for Smoothing Method and Length
typeMA = input.string(title="Method", defval="SMA", options=["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="Smoothing")
smoothingLength = input.int(title="Smoothing Length", defval=5, minval=1, maxval=100, group="Smoothing")
// Calculate the Smoothing Line
smoothingLine = ma(out, smoothingLength, typeMA)
// Plot the Smoothing Line
plot(smoothingLine, title="Smoothing Line", color=color.rgb(120, 66, 134, 35), offset=offset)
// Strategy Logic
if (ta.crossover(close, smoothingLine))
strategy.entry("Buy", strategy.long)
if (ta.crossunder(close, smoothingLine))
strategy.entry("Sell", strategy.short)