移動平均線交差策略は,移動平均線交差を取引信号として利用したトレンド追跡策略である.この策略は,価格と移動平均線交差,および2つの移動平均線交差を買い売り信号として利用し,利益を追求する.
この戦略の基本原則は以下の通りです.
2つの移動平均線を計算し,SMAまたはEMAを選択します.
速線で遅線を突破する時は,多めにやれ. 速線の下で遅線を突破する時は,平仓しろ.
価格が平均線を突破するか,平均線間の交差を取引シグナルとして選択できます.
戦略の実行期間を設定できます.
複数頭市場には多頭,空頭市場には空頭しかできない.
移動平均線パラメータを最適化して,異なる周期に対応する.
この戦略は,移動平均線のトレンド追跡機能を利用し,短期平均線上での長期平均線を横断すると,現在上昇傾向にあることを示すため,多額の取引をすべきである.逆に,短期平均線下での長期平均線を横断すると,現在下降傾向にあることを示すため,取引を減らすべきである.
この戦略の主な利点は以下の通りです.
基本はシンプルで実行しやすいし,取引のシグナルも明確です.
商品の価格や価格の変動を把握し,市場を動かすことができます.
異なる均線パラメータを組み合わせて,多種多様な市場環境に適用できる.
選択的に多量化または空白化して,不確実な反転操作を回避する.
戦略の実行時間を設定し,特定の時間帯を回避できます.
パラメータの最適化により,戦略のパフォーマンスを継続的に改善できます.
この戦略の主なリスクは
偽の信号を発生しやすいので,頻繁に取引を避けるべきです.
表現は平均線参数選択に依存し,誤った選択は損失を引き起こす可能性がある.
遅滞があるため,早すぎる入場と遅すぎる退出を防ぐべきである.
市場環境が不安定である場合には適用されない.
平均線交差はランダム性があるため,完全に損失を回避することはできません.
取引量確認,最適化パラメータ,または他の指標の組み合わせを使用してリスクを減らすことができます.
この戦略は以下の点で最適化できます.
平均線斜率フィルター条件として/% ((Line - ShortMa) /ShortMa) / ((Line - LongMa) /LongMa) /を追加する.
移動平均線周期パラメータを最適化して,異なる組み合わせをテストする.
MACDまたはRSIなどの指標に複数確認を加える.
ストップ・ロスの条件を設定し,単一損失を制限する.
トレンド市と整合市を区別し,条件を適用する.
ポジションの長さや短さを測り,最適の選択肢を探します.
移動均線交差戦略は,シンプルで実用的なトレンド追跡戦略である.優点は,実行が簡単で,トレンドを効果的に追跡できること;欠点は,遅滞性があり,偽信号を多く生み出す可能性があることである.パラメータ最適化,指標フィルターなどの方法によって,この戦略を改良して,トレンドが明らかな市場でより良いパフォーマンスを得ることができる.
/*backtest
start: 2023-09-10 00:00:00
end: 2023-09-17 00:00:00
period: 10m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © gliese581d
//@version=4
strategy(title="Moving Averages Testing", overlay=true, precision=2, calc_on_every_tick=false, max_bars_back=5000, pyramiding=2,
default_qty_type=strategy.percent_of_equity, default_qty_value=50, commission_type=strategy.commission.percent, initial_capital=10000)
//SETTINGS
longs_on = input(title="Long Trades enabled", defval=true)
shorts_on = input(title="Short Trades enabled", defval=true)
long_cond = input(title="Buy/Long Crossover Condition", defval="price x MA1", options=["price x MA1", "price x MA2", "MA1 x MA2"])
short_cond = input(title="Sell/Short Crossunder Condition", defval="price x MA2", options=["price x MA1", "price x MA2", "MA1 x MA2"])
ma1_type = input(title="Moving Average 1 Type", defval="SMA", options=["SMA", "EMA"])
ma1_len = input(defval=20, title="Moving Average 1 Len", type=input.integer, minval=1, maxval=1000, step=1)
ma2_type = input(title="Moving Average 2 Type", defval="SMA", options=["SMA", "EMA"])
ma2_len = input(defval=30, title="Moving Average 2 Len", type=input.integer, minval=1, maxval=1000, step=1)
//MOVING AVERAGES
ma_1 = ma1_type == "EMA" ? ema(close, ma1_len) : sma(close, ma1_len)
ma_2 = ma2_type == "EMA" ? ema(close, ma2_len) : sma(close, ma2_len)
//STRATEGY
//trade entries
long_entry = long_cond == "price x MA1" ? crossover(close, ma_1) : long_cond == "price x MA2" ? crossover(close, ma_2) : long_cond == "MA1 x MA2" ? crossover(ma_1, ma_2) : false
short_entry = short_cond == "price x MA1" ? crossunder(close, ma_1) : short_cond == "price x MA2" ? crossunder(close, ma_2) : short_cond == "MA1 x MA2" ? crossunder(ma_1, ma_2) : false
start_month = input(defval=4, title="Strategy Start Month", type=input.integer, minval=1, maxval=12, step=1)
start_year = input(defval=2018, title="Strategy Start Year", type=input.integer, minval=2000, maxval=2025, step=1)
end_month = input(defval=12, title="Strategy End Month", type=input.integer, minval=1, maxval=12, step=1)
end_year = input(defval=2020, title="Strategy End Year", type=input.integer, minval=2000, maxval=2025, step=1)
in_time = true
strategy.entry("Long", strategy.long, when=longs_on and in_time and long_entry)
strategy.close("Long", when=longs_on and not shorts_on and short_entry)
strategy.entry("Short", strategy.short, when=shorts_on and in_time and short_entry)
strategy.close("Short", when=shorts_on and not longs_on and long_entry)
//PLOTTING
//color background
last_entry_was_long = nz(barssince(long_entry)[1], 5000) < nz(barssince(short_entry)[1], 5000)
bgcol = (longs_on and last_entry_was_long) ? color.green : (shorts_on and not last_entry_was_long) ? color.red : na
bgcolor(color=bgcol, transp=90)
plot((long_cond == "price x MA1" or long_cond == "MA1 x MA2") or (short_cond == "price x MA1" or short_cond == "MA1 x MA2") ? ma_1 : na, color=color.blue)
plot((long_cond == "price x MA2" or long_cond == "MA1 x MA2") or (short_cond == "price x MA2" or short_cond == "MA1 x MA2") ? ma_2 : na, color=color.black)
plotshape(long_entry, style=shape.triangleup, location=location.belowbar, color=color.green)
plotshape(short_entry, style=shape.triangledown, location=location.abovebar, color=color.red)