
쌍평평선 돌파 전략은 비교적 전형적인 트렌드를 추적하는 양적 거래 전략이다. 이 전략은 다양한 주기에서 간단한 이동 평균을 계산하고 거래 신호를 가격 돌파 이동 평균으로 설정하여 지위를 판단한다. 이 전략은 20 일선과 60 일선을 거래 신호로 사용합니다.
이 두 가지 전략의 핵심 논리는가격 트렌드를 포착하기 위해 다른 주기의 이동 평균을 사용 하 고 가격이 이동 평균을 돌파 할 때 거래 신호를 발산。
구체적으로, 이 전략은 20일 간단한 이동 평균과 60일 간단한 이동 평균을 사용합니다. 이 두 가지 이동 평균은 각각 단기 경향과 중장기 경향을 포착하는 도구로 볼 수 있습니다. 단기 가격이 중장기 가격을 돌파할 때, 현재 상승 추세를 나타냅니다.
코드에서 통과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)