
この戦略は,20日線と60日線の移動平均を交差して買入シグナルを形成する.価格が上昇して20日線を突破すると,多めにする.価格が下がって20日線を突破すると,平仓する.同様に,価格が60日線を突破すると,買入シグナルを形成する.この戦略は典型的なトレンドフォロー戦略である.
上記は,この戦略を構成する取引のシグナルとルールである. 価格が平均を突破すると,トレンドが始まることを示すので,トレンドをさらに追跡することができます. 価格が平均を下回ると,トレンドが終わることを示すので,平仓は正しい選択です.
リスク対策:
この戦略は,全体として典型的な双動平均の交差戦略である.その核心構想は,トレンドを追跡し,価格が平均線を破るときにトレンドの位置を確立することである.戦略は,シンプルで実用的で,容易に実行できる.また,パラメータ最適化,ストップ損失回避,ポジション管理などの手段によって,より良い戦略効果を得るためのいくつかの最適化可能なスペースがある.
/*backtest
start: 2022-12-01 00:00:00
end: 2023-12-07 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/
// © Astorhsu
//@version=5
strategy("Astor SMA20/60 TW", overlay=true, margin_long=100, margin_short=100)
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
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)")
//進場條件
longCondition = ta.crossover(close, ta.sma(close, 20))
if (longCondition) and time >= start_time
strategy.entry("open long20", strategy.long, qty=1, comment="站上m20做多")
shortCondition = ta.crossunder(close, ta.sma(close, 20))
if (shortCondition) and time >= start_time
strategy.close("open long20",comment="跌破m20平倉", qty=1)
longCondition1 = ta.crossover(close, ta.sma(close, 60))
if (longCondition1) and time >= start_time
strategy.entry("open long60", strategy.long, qty=1, comment="站上m60做多")
shortCondition1 = ta.crossunder(close, ta.sma(close, 60))
if (shortCondition1) and time >= start_time
strategy.close("open long60",comment="跌破m60平倉", qty=1)