
双均線突破戦略は,比較的典型的なトレンドを追跡する量化取引戦略である.この戦略は,異なる周期の単純な移動平均を計算し,取引信号を価格突破移動平均として設定して,保有を判断する.この戦略は,20日線と60日線を取引信号として使用する.
この戦略の核となる論理は価格の傾向を捉えるために異なる周期の移動平均を使用し,価格が移動平均を突破すると取引シグナルを発信する。
具体的には,この戦略は20日間のシンプル・ムービング・平均と60日間のシンプル・ムービング・平均を使用しています. この2つの移動平均は,短期的な傾向と中期的な傾向を捕捉するためのツールとして見ることができます.
コードで通過ta.crossoverそしてta.crossunder価格が移動平均を突破するか,破るかを判断する. 突破が起きたとき,高値または低値の指示を発行する.
この戦略は以下の利点があります.
この戦略にはいくつかのリスクがあります.
双均線突破戦略は,以下のいくつかの次元から最適化できます.
双均線突破戦略は,シンプルで実用的なトレンド追跡戦略である.それは中長期のトレンドを効果的に捕捉し,短期市場の騒音の干渉を避けることができる.同時に,戦略は容易に理解し,実行し,パラメータは可数であり,量化取引の要求に適しています.もちろん,戦略には,パラメータの最適化,信号の追加フィルタリング,および停止ロジックなどの面で改善の余地があり,戦略をより安定させ,利潤を高める.
/*backtest
start: 2024-01-04 00:00:00
end: 2024-02-03 00:00:00
period: 4h
basePeriod: 15m
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/
// © Astorhsu
//@version=5
strategy("Astor SMA20/60", overlay=true)
backtest_year = input(2018, title='backtest_year') //回測開始年分
backtest_month = input.int(01, title='backtest_month', minval=1, maxval=12) //回測開始月份
backtest_day = input.int(01, title='backtest_day', minval=1, maxval=31) //回測開始日期
start_time = timestamp(backtest_year, backtest_month, backtest_day, 00, 00) //回測開始的時間函數
//Indicators
sma10 = ta.sma(close,10)
sma20 = ta.sma(close,20)
sma60 = ta.sma(close,60)
plot(sma20, color=color.green, title="sma(20)")
plot(sma60, color=color.red, title="sma(60)")
//進場條件
// trend1 = sma60 > sma20 //假設目前趨勢為60>20
longCondition = ta.crossover(close, ta.sma(close, 20))
if (longCondition)
strategy.entry("open long20", strategy.long, qty=1, comment="站上m20做多")
shortCondition = ta.crossunder(close, ta.sma(close, 20))
if (shortCondition)
strategy.close("open long20",comment="跌破m20平倉", qty=1)
longCondition1 = ta.crossover(close, ta.sma(close, 60))
if (longCondition1)
strategy.entry("open long60", strategy.long, qty=1, comment="站上m60做多")
shortCondition1 = ta.crossunder(close, ta.sma(close, 60))
if (shortCondition1)
strategy.close("open long60",comment="跌破m60平倉", qty=1)
// longCondition2 = ta.crossover(close, ta.sma(close, 10))
// if (longCondition2)
// strategy.entry("open long10", strategy.long, qty=1, comment="站上m10做多")
// shortCondition2 = ta.crossunder(close, ta.sma(close, 10))
// if (shortCondition2)
// strategy.close("open long10",comment="跌破m10平倉", qty=1)