
평균선 교차 전략은 두 가지 다른 파라미터 세트의 SMA 평균선의 교차를 계산하여 거래 신호를 생성한다. 빠른 SMA 평균선이 느린 SMA 평균선을 통과하면 구매 신호를 생성한다. 느린 SMA 평균선이 빠른 SMA 평균선을 통과하면 판매 신호를 생성한다. 이 전략은 두 개의 SMA 평균선 파라미터를 동시에 사용한다.
이 전략은 두 가지의 SMA 평균선 변수를 사용합니다.smaB1、smaB2그리고smaS1、smaS2。smaB1그리고smaB2구매 신호를 결정하기 위해, 그들은 각각 느리고 빠른 평균선을 나타냅니다.smaB1입으세요smaB2구매 신호가 발생했을 때smaS1그리고smaS2판매 신호를 결정하는 데 사용되며, 마찬가지로 각각 느리고 빠른 평균선을 나타냅니다.smaS2옷 벗고smaS1매매 신호를 생성할 때. 이렇게 하면 구매 및 매매 조건이 다른 시장 환경에 적응할 수 있도록 유연하게 조정될 수 있다.
구체적으로, 이 전략은 클로즈 가격의 SMA 값을 계산하고, 실시간으로 두 개의 SMA 평균선의 교차 상황을 모니터링하여 구매와 판매의 시간을 판단한다. SMA 빠른 선에서 느린 선을 통과할 때, 가격 움직임이 긍정적으로 올라간다고 생각하기 때문에 이 때 더 많이 한다.
이 전략의 주요 장점은 다음과 같습니다.
이 전략에는 몇 가지 위험도 있습니다.
위와 같은 위험을 제어하기 위해, SMA 변수 조합을 최적화하여, 동적 스톱로스를 결합하여 수익을 잠금하는 방법과 같은 방법을 개선할 수 있다.
이 전략은 다음과 같은 부분에서 최적화될 수 있습니다.
평균선 교차 전략은 두 세트의 SMA 평균선의 교차 상황을 계산하여 간단한 효과적인 거래 신호를 생성한다. 이 전략은 다양한 품종에 적용하여 파라미터를 유연하게 조정할 수 있으며, 일반적인 트렌드 추적 전략이다. 파라미터 최적화, 신호 필터링 등의 방법으로이 전략을 더 개선하여 더 신뢰할 수있는 신호를 생성 할 수 있습니다.
/*backtest
start: 2023-11-15 00:00:00
end: 2023-11-22 00:00:00
period: 5m
basePeriod: 1m
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/
// © melihtuna
//@version=4
strategy("SMA Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=10000, currency=currency.USD, commission_value=0.1, commission_type=strategy.commission.percent)
smaB1 = input(title="smaB1",defval=377)
smaB2 = input(title="smaB2",defval=200)
smaS1 = input(title="smaS1",defval=377)
smaS2 = input(title="smaS2",defval=200)
smawidth = 2
plot(sma(close, smaB1), color = #EFB819, linewidth=smawidth, title='smaB1')
plot(sma(close, smaB2), color = #FF23FD, linewidth=smawidth, title='smaB2')
plot(sma(close, smaS1), color = #000000, linewidth=smawidth, title='smaS1')
plot(sma(close, smaS2), color = #c48dba, linewidth=smawidth, title='smaS2')
// === INPUT BACKTEST RANGE ===
FromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)
FromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)
FromYear = input(defval = 2020, title = "From Year", minval = 2017)
ToMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)
ToDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)
ToYear = input(defval = 9999, title = "To Year", minval = 2017)
// === FUNCTION EXAMPLE ===
start = timestamp(FromYear, FromMonth, FromDay, 00, 00)
finish = timestamp(ToYear, ToMonth, ToDay, 23, 59)
window() => time >= start and time <= finish ? true : false
longCondition = crossover(sma(close, smaB1),sma(close, smaB2))
if (window() and longCondition)
strategy.entry("BUY", strategy.long)
shortCondition = crossover(sma(close, smaS2),sma(close, smaS1))
if (window() and shortCondition)
strategy.entry("SELL", strategy.short)