
쌍 이동평균금차사차 역전 전략은 전형적인 트렌드를 추적하는 양적 거래 전략이다. 이 전략은 쌍 이동평균금차 지표의 9일선과 14일선을 이용하여 구매 및 판매 신호를 구성한다. 9일선이 아래에서 14일선을 뚫고 금차를 형성할 때 구매하고, 9일선이 위에서 14일선을 뚫고 사망차를 형성할 때 판매한다. 가짜 신호를 필터링하기 위해, 전략은 50일선 지표에 가격의 돌파 여부를 판단하기도 한다.
이 전략은 주로 두 개의 이동평균선 지표의 골드포크와 데드포크 신호를 기반으로 거래한다. 두 개의 이동평균선 중, 9일선은 단기 트렌드를, 14일선은 중기 트렌드를 나타내며, 이들의 교차는 시장 트렌드 전환을 판단하는 효과적인 기술 지표이다. 단기 트렌드 라인이 아래쪽에서 중기 트렌드 라인을 뚫고 골드포크를 형성할 때, 단기 트렌드 라인이 강해지면, 구매 신호에 속한다. 위쪽에서 뚫고 데드포크를 형성할 때, 단기 트렌드 라인이 약해지면, 판매 신호에 속한다.
또한, 전략은 50 일선으로도 도입하여 잘못된 신호를 필터링한다. 50 일선보다 가격이 높을 때만 구매가 발생하며, 50 일선보다 가격이 낮을 때만 판매가 발생한다. 50 일선은 중장기적 추세를 나타내고, 중장기적 추세가 동의할 때만 단기적 거래를 한다.
코드의 핵심 논리는 다음과 같습니다.
// 买入条件:9日线上穿14日线 且 当前价格高于50日线
buyCondition = ta.crossover(sma9, sma14) and close > sma50
// 卖出条件:9日线下穿14日线 且 当前价格低于50日线
sellCondition = ta.crossunder(sma9, sma14) and close < sma50
두 개의 이동평균선 전략의 장점은 분명합니다.
이 두 개의 이동평균형 전략에는 위험도 있습니다.
위험성을 고려하여 다음과 같이 최적화할 수 있습니다.
이중 이동평균형 전략은 다음과 같은 측면에서 최적화될 수 있다:
이중 이동 평행선 전략은 전체적으로 효율성과 수익성이 높은 전략이다. 그것은 순차적으로, 지속적으로 수익을 올릴 수 있다. 동시에, 위험도 존재하며, 추가적으로 개선할 필요가 있다. 매개 변수 최적화, 손해 중지 방식 및 전략 조합을 통해 이 전략의 효과를 더욱 강화할 수 있다.
/*backtest
start: 2022-11-24 00:00:00
end: 2023-11-30 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("smaCrossReverse", shorttitle="smaCrossReverse", overlay=true)
// Define the length for the SMAs
sma9Length = input(9, title="SMA 9 Length")
sma14Length = input(14, title="SMA 14 Length")
sma50Length = input(50, title="SMA 50 Length") // Add input for SMA 50
// Calculate SMAs
sma9 = ta.sma(close, sma9Length)
sma14 = ta.sma(close, sma14Length)
sma50 = ta.sma(close, sma50Length) // Calculate SMA 50
// Buy condition: SMA 9 crosses above SMA 14 and current price is above SMA 50
buyCondition = ta.crossover(sma9, sma14) and close > sma50
// Sell condition: SMA 9 crosses below SMA 14 and current price is below SMA 50
sellCondition = ta.crossunder(sma9, sma14) and close < sma50
// Track the time since position was opened
var float timeElapsed = na
if (buyCondition)
timeElapsed := 0
else
timeElapsed := na(timeElapsed[1]) ? timeElapsed[1] : timeElapsed[1] + 1
// Close the buy position after 5 minutes
if (timeElapsed >= 5)
strategy.close("Buy")
// Track the time since position was opened
var float timeElapsedSell = na
if (sellCondition)
timeElapsedSell := 0
else
timeElapsedSell := na(timeElapsedSell[1]) ? timeElapsedSell[1] : timeElapsedSell[1] + 1
// Close the sell position after 5 minutes
if (timeElapsedSell >= 5)
strategy.close("Sell")
// Plot the SMAs on the chart
plot(sma9, title="SMA 9", color=color.blue)
plot(sma14, title="SMA 14", color=color.red)
plot(sma50, title="SMA 50", color=color.green) // Plot SMA 50 on the chart
// Strategy entry and exit conditions using if statements
if (buyCondition)
strategy.entry("Buy", strategy.long)
if (sellCondition)
strategy.entry("Sell", strategy.short)