
この戦略は,移動平均の金叉原理に基づいて取引する.この戦略は,2つの移動平均を使用し,短期移動平均が下から長期移動平均を突破すると買いのシグナルを生成する.価格が別の移動平均を下回ると売りのシグナルを生成する.この戦略は,トレンド市場に適用され,一部のノイズ取引を効果的にフィルターし,主要なトレンドを捕まえて取引する.
この戦略は,ユーザがカスタマイズした短期移動平均周期,長期移動平均周期,退出移動平均周期および各移動平均の計算方法を使用する.
短期移動平均が下から長期移動平均を突破すると,買入シグナルが生じます。これは短期トレンドが上昇トレンドに変換され,買入できることを示します。
閉店価格が移動平均から退出するときに,売り込みシグナルが生じます. これは,トレンドが逆転し,ポジションから退出すべきことを示します.
したがって,この戦略の取引シグナルは,短期移動平均と長期移動平均の交差,および閉店価格と退出移動平均の関係から得られます.
この戦略の利点は以下の通りです.
シンプルで理解しやすい,実行しやすい.
市場状況に応じてカスタマイズ可能なパラメータ
移動平均で騒音をフィルターし,主要トレンドを把握する.
トレンド,サポート,レジスタンスなどの技術指標をさらに最適化できます.
利回りは制御可能で,止損メカニズムがあります.
この戦略には以下のリスクもあります.
傾向が弱い整合市場では,誤ったシグナルが生じやすい.
パラメータを正しく設定しない場合,トレンドを逃したり,無効取引を過剰に発生させることもあります.
ストップダメージ位置の不合理な設定は,損失を拡大する可能性がある.
突破に失敗すると,損失が伴う.
市場の変化に対応するためにパラメータを適時調整する必要があります.
リスクに対応する解決方法には,最適化パラメータ設定,他の指標のフィルター信号と組み合わせ,ストップ・ロスの位置を調整,トレンドを特定した後で参加するなどが含まれます.
この戦略は以下の点で最適化できます.
トレンド判断の仕組みを開発し,トレンドを特定し,取引信号を生成する.
取引量または波動指標を組み合わせてフィルターする.
動的最適化移動平均周期パラメータ。
移動式止損を実現する.
サポートとレジスタンスと他の指標を組み合わせて,取引信号をさらに確認します.
異なる品種,周期に応じてパラメータを調整する。
この移動平均線金叉取引戦略は,全体としてシンプルで実用的なトレンド追跡戦略である.市場状況に応じてパラメータを調整し,トレンドの行情で主要なトレンド方向を捉えることができる.しかし,トレンド判断誤りなどのリスクを防ごうにも注意し,市場変化に適応するために継続的に最適化する必要がある.全体的に,この戦略は,実用性が良好である.
/*backtest
start: 2022-10-30 00:00:00
end: 2023-11-05 00:00:00
period: 1d
basePeriod: 1h
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/
// © TwoChiefs
//@version=4
strategy("John EMA Crossover Strategy", overlay=true)
////////////////////////////////////////////////////////////////////////////////
// BACKTESTING RANGE
// From Date Inputs
fromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
fromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
fromYear = input(defval = 2020, title = "From Year", minval = 1970)
// To Date Inputs
toDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
toMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
toYear = input(defval = 2021, title = "To Year", minval = 1970)
// Calculate start/end date and time condition
startDate = timestamp(fromYear, fromMonth, fromDay, 00, 00)
finishDate = timestamp(toYear, toMonth, toDay, 00, 00)
time_cond = true
////////////////////////////////////////////////////////////////////////////////
//CREATE USER-INPUT VARIABLES
periodShort = input(13, minval=1, title="Enter Period for Short Moving Average")
smoothingShort = input(title="Choose Smoothing Type for Short Moving Average", defval="EMA", options=["RMA", "SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "LSMA"])
periodLong = input(48, minval=1, title="Enter Period for Long Moving Average")
smoothingLong = input(title="Choose Smoothing Type for Long Moving Average", defval="EMA", options=["RMA", "SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "LSMA"])
periodExit = input(30, minval=1, title="Enter Period for Exit Moving Average")
smoothingExit = input(title="Choose Smoothing Type for Exit Moving Average", defval="EMA", options=["RMA", "SMA", "EMA", "WMA", "VWMA", "SMMA", "DEMA", "TEMA", "HullMA", "LSMA"])
src1 = close
pivot = (high + low + close) / 3
//MA CALCULATION FUNCTION
ma(smoothing, src, length) =>
if smoothing == "RMA"
rma(src, length)
else
if smoothing == "SMA"
sma(src, length)
else
if smoothing == "EMA"
ema(src, length)
else
if smoothing == "WMA"
wma(src, length)
else
if smoothing == "VWMA"
vwma(src, length)
else
if smoothing == "SMMA"
na(src[1]) ? sma(src, length) : (src[1] * (length - 1) + src) / length
else
if smoothing == "HullMA"
wma(2 * wma(src, length / 2) - wma(src, length), round(sqrt(length)))
//ASSIGN A MOVING AVERAGE RESULT TO A VARIABLE
shortMA=ma(smoothingShort, pivot, periodShort)
longMA=ma(smoothingLong, pivot, periodLong)
exitMA=ma(smoothingExit, pivot, periodExit)
//PLOT THOSE VARIABLES
plot(shortMA, linewidth=4, color=color.yellow,title="The Short Moving Average")
plot(longMA, linewidth=4, color=color.blue,title="The Long Moving Average")
plot(exitMA, linewidth=1, color=color.red,title="The Exit CrossUnder Moving Average")
//BUY STRATEGY
buy = crossover(shortMA,longMA) ? true : na
exit = crossunder(close,exitMA) ? true : na
strategy.entry("long",true,when=buy and time_cond)
strategy.close("long",when=exit and time_cond)
if (not time_cond)
strategy.close_all()