
この戦略は,1/2/4周期のシンプル移動平均 (SMA) 交差信号に基づく取引システムである.短周期と中期平均線が長周期平均線と同方向に交差する点を観察することで,市場のトレンドの転換点を捉え,トレンド追跡とタイムリーなストップロスを実現する.戦略は,簡潔で効率的に設計され,理解し,実行しやすい.
戦略の核心は,3つの異なる周期 ((1/2/4) の単純な移動平均を利用して,短周期 ((1期) と中期期 ((2期) の平均線が同時に長周期 ((4期) の平均線を上方に横切っているかどうかを判断することによって,買入シグナルを決定することであり,逆に,短周期と中期期間の平均線が同時に長周期平均線を下方に横切るときに売り出しシグナルを生成することである.この複数の確認機構は,偽信号を効果的に軽減し,取引の正確性を向上させる.具体的には,ta.crossover ((((((とta.crossunder (((() の関数を用いて,交差が満たされていることを検知し,買入条件が満たされたときに多頭ポジションを開く,売り出し条件が満たされたときに平時ポジションを開き,空頭ポジションを開く.
この戦略は,複数の移動平均の交差によって市場動向を捉え,設計理念は明確で,実装方法はシンプルで有効である.ある程度の遅れや偽信号のリスクがあるものの,合理的なパラメータの最適化と付加指標の補足によって,より完善した取引システムを構築することができる.戦略は,拡張性が強く,基礎フレームワークのさらなる最適化と完善に適している.
/*backtest
start: 2024-10-20 00:00:00
end: 2025-02-18 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/
//@version=6
strategy("1/2/4 Moving Average STR 1.0.0", overlay=true)
o_length = input(1, title="1 Closed")
t_length = input(2, title="2 Closed")
f_length = input(4, title="4 Closed")
// Calculate the simple moving averages.
ma_o = ta.sma(close, o_length)
ma_t = ta.sma(close, t_length)
ma_f = ta.sma(close, f_length)
// Plot the moving averages on the chart.
plot(ma_o, color=color.green, title="1 MA")
plot(ma_t, color=color.red, title="2 MA")
plot(ma_f, color=color.blue, title="4 MA")
// Assign the crossover and crossunder results to global variables.
crossover_o = ta.crossover(ma_o, ma_f)
crossover_t = ta.crossover(ma_t, ma_f)
crossunder_o = ta.crossunder(ma_o, ma_f)
crossunder_t = ta.crossunder(ma_t, ma_f)
// Generate signals based on the global crossover variables.
// Buy signal: both 1 and 2 SMAs cross over the 4 SMA on the same bar.
buy_signal = crossover_o and crossover_t
// Sell signal: both 1 and 2 SMAs cross under the 4 SMA on the same bar.
sell_signal = crossunder_o and crossunder_t
// Enter trades based on the signals.
// For a long position, enter on a buy signal and exit when a sell signal occurs.
if buy_signal
strategy.entry("Long", strategy.long)
if sell_signal
strategy.close("Long")
// For a short position, enter on a sell signal and exit when a buy signal occurs.
if sell_signal
strategy.entry("Short", strategy.short)
if buy_signal
strategy.close("Short")