SMA와 가격 크로스오버에 기반한 양적 거래 전략

저자:차오장, 날짜: 2024-02-22 17:34:09
태그:

img

전반적인 설명

이 전략은 SMA와 가격 교차를 기반으로 한 양적 거래 전략 (Quantitative Trading Strategy Based on Price Crossover with SMA) 이라고 불린다. 주로 다른 기간의 SMA를 계산하고 SMA와 가격 교차를 추적하여 거래 신호를 생성한다. 가격이 SMA를 상향으로 넘으면 구매 신호를 유발한다. 가격이 SMA를 하향으로 넘으면 판매 신호를 유발한다.

전략 논리

이 전략의 핵심 논리는 21일 간 간편 이동 평균 (SMA) 으로 가격 교차를 추적하는 것입니다. 한편, 일반적인 추세를 결정하기 위해 50일 간편 이동 평균 (SMA) 과 200일 간편 이동 평균 (SMA) 을 계산합니다.

구체적으로, 전략은 주어진 날짜 범위 내에서 가격 폐쇄를 요청하고 입력 기간에 따라 다른 SMA를 계산합니다. 가격이 21 일간의 SMA를 상향으로 돌파하면 구매 신호를 설정합니다. 가격이 21 일간의 SMA를 하향으로 돌파하면 판매 신호를 설정합니다.

이 전략은 SMA를 계산하고 크로스오버를 결정하는 것 외에도 현재 포지션을 추적합니다. 구매 신호 트리거를 할 때 포지션을 입력하고, 판매 신호 트리거를 할 때 포지션을 평평하게합니다. 이러한 방식으로 SMA 크로스오버에 기반한 자동 거래 시스템을 실현합니다.

이점 분석

이 전략의 가장 큰 장점은 간단하고 이해하기 쉽고 구현하기 쉽다는 것입니다. SMA는 일반적으로 사용되는 기술 지표이며 SMA 크로스오버는 가장 일반적인 거래 신호 중 하나입니다. 이러한 유형의 지표 크로스오버 전략은 자동 거래에 다른 주식과 시간 범위에 쉽게 적용 할 수 있습니다.

또 다른 장점은 이 전략이 SMA 매개 변수를 조정하여 최적화 될 수 있다는 것입니다. 예를 들어, 우리는 특정 주식에 최적의 것을 찾기 위해 SMA 기간의 다른 조합을 테스트 할 수 있습니다. 또한, 전략은 확인 및 최적화를 위해 다른 지표를 추가하여 개선 할 수 있습니다.

위험 과 해결책

이 전략의 가장 큰 위험은 지표 기반 전략이 과도한 잘못된 신호를 생성하는 경향이 있다는 것입니다. 예를 들어, 가격은 범위 제한 기간 동안 종종 SMA를 교차하여 불필요한 거래로 이어질 수 있습니다.

일반적인 솔루션은 스톱 로스 설정, 튜닝 매개 변수 또는 필터 조건을 추가하는 것을 포함합니다. 예를 들어, 위험을 제한하기 위해 최대 손실 비율을 설정하거나, 더 안정적인 매개 변수를 찾기 위해 SMA 기간을 조정하거나, 일부 거래 신호를 필터하기 위해 다른 지표를 사용할 수 있습니다.

최적화 방향

이 전략은 다음과 같은 측면에서 최적화 될 수 있습니다.

  1. 최적의 SMA 매개 변수 조합을 테스트하고 선택하십시오. 최상의 기간을 찾기 위해 다른 SMA 길이를 테스트하십시오.

  2. 필터 시그널 확인을 위한 다른 지표를 추가하십시오. RSI, MACD 등과 같이. 이것은 잘못된 신호를 필터링하는 데 도움이됩니다.

  3. 스톱 로스 로직을 적용하고 최대 허용 손실 또는 후속 스톱을 설정하여 위험을 더 잘 제어합니다.

  4. 진입 시기를 최적화하십시오. SMA 크로스오버를 엄격히 따르는 것보다 주요 브레이크오프를 돌고 진입하는 것을 고려하십시오.

  5. 복합적인 전략을 테스트하고 트렌드를 따르는 것과 같은 다른 전략 유형과 결합합니다.

결론

이 전략은 간단한 SMA 크로스오버 신호로 자동화 된 거래를 실현합니다. 장점은 이해하기 쉽고 구현하기 쉽습니다. 단점은 과도한 신호이며 윙사에 예민합니다. 우리는 매개 변수 조정, 필터 추가, 스톱 로스 등을 통해 개선 할 수 있습니다. 이 전략은 우리에게 기본적인 프레임워크를 제공합니다. 더 많은 구성 요소를 통합하여 풍부 할 수 있습니다.


/*backtest
start: 2023-02-15 00:00:00
end: 2024-02-21 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=5
strategy("Price Cross Above/Below SMA Strategy", shorttitle="Tressy Strat", overlay=true)

// Define start and end year inputs
start_year = input.int(2022, title="Start Year")
end_year = input.int(2022, title="End Year")

// Define start and end month inputs
start_month = input.int(1, title="Start Month", minval=1, maxval=12)
end_month = input.int(12, title="End Month", minval=1, maxval=12)

// Define SMA length inputs
sma_length = input.int(21, title="SMA Length")
sma_length_50 = input.int(50, title="50 SMA Length")
sma_length_200 = input.int(200, title="200 SMA Length")

// Filter data within the specified date range
filter_condition = true
filtered_close = request.security(syminfo.tickerid, "D", close[0], lookahead=barmerge.lookahead_on)

// Define SMAs using the input lengths
sma = ta.sma(filtered_close, sma_length)
sma_50 = ta.sma(filtered_close, sma_length_50)
sma_200 = ta.sma(filtered_close, sma_length_200)

// Initialize position
var bool in_position = false

// Condition for a price cross above SMA within the date range
cross_above = filter_condition and ta.crossover(filtered_close, sma)

// Condition for a price cross below SMA within the date range
cross_below = filter_condition and ta.crossunder(filtered_close, sma)

// Buy condition
if cross_above
    in_position := true

// Sell condition
if cross_below
    in_position := false

// Strategy entry and exit
if cross_above
    strategy.entry("Buy", strategy.long)
if cross_below
    strategy.close("Buy")

// Plot the SMAs on the chart
plot(sma, color=color.blue, title="21 SMA")
plot(sma_50, color=color.red, title="50 SMA")
plot(sma_200, color=color.orange, title="200 SMA")

// Plot the Buy and Sell signals with "tiny" size
plotshape(cross_above, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.tiny, title="Buy Signal")
plotshape(cross_below, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.tiny, title="Sell Signal")


더 많은