
이 전략은 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)