
이 전략은 간단한 이동 평균 교차 전략이다. 그것은 빠른 EMA에서 느린 EMA를 통과할 때 더 많이 하고, 빠른 EMA 아래에서 느린 EMA를 통과할 때 공백을 한다. 이 전략은 중지, 중지, 이동 중지와 결합하여 위험을 효과적으로 제어 할 수 있다.
이 전략은 빠르고 느린 이동 평균을 기반으로 한다. 빠른 선은 9일 EMA, 느린 선은 21일 EMA이다. 빠른 선이 아래에서 느린 선을 통과할 때, 더 많이 한다. 빠른 선이 위에서 아래에서 느린 선을 통과할 때, 공백을 한다.
스톱 로드는 클로즈의 일정한 비율로 설정되고, 스톱 로드는 클로즈의 일정한 비율로 설정된다. 이동 스톱 로드는 클로즈의 일정한 비율로 설정되며, 가격이 그 수준에 도달하면 스톱 로드는 포지션 개시 가격으로 이동한다.
이 전략은 다음과 같은 장점을 가지고 있습니다.
이 전략에는 몇 가지 위험도 있습니다.
해결책:
이 전략은 다음과 같은 측면에서 최적화될 수 있습니다.
이 이동 평균 크로스 금 전략은 전체적으로 논리적으로 명확하고 구현하기 쉬운 반면, 중지, 중지 및 이동 중지와 결합하여 위험을 제어한다. 합리적인 매개 변수 설정과 다양한 시장에 대한 최적화 조정으로 이 전략은 더 나은 효과를 얻을 수 있다. 그러나 여전히 잘못된 보도 위험과 매개 변수 최적화의 어려움을 주의해야 한다.
/*backtest
start: 2022-12-20 00:00:00
end: 2023-12-26 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=4
strategy("XAUUSD Strategy with SL, TP, and BE", shorttitle="EA", overlay=true)
// Define strategy parameters
fastLength = input(9, title="Fast EMA Length")
slowLength = input(21, title="Slow EMA Length")
stopLossPercent = input(1, title="Stop Loss (%)", minval=0, maxval=5) / 100
takeProfitPercent = input(2, title="Take Profit (%)", minval=0, maxval=5) / 100
breakEvenPercent = input(1, title="Break Even (%)", minval=0, maxval=5) / 100
// Calculate EMAs
fastEMA = ema(close, fastLength)
slowEMA = ema(close, slowLength)
// Plot EMAs on the chart
plot(fastEMA, color=color.blue, title="Fast EMA")
plot(slowEMA, color=color.red, title="Slow EMA")
// Strategy logic
enterLong = crossover(fastEMA, slowEMA)
exitLong = crossunder(fastEMA, slowEMA)
enterShort = crossunder(fastEMA, slowEMA)
exitShort = crossover(fastEMA, slowEMA)
// Calculate stop loss, take profit, and break-even levels
longStopLoss = close * (1 - stopLossPercent)
longTakeProfit = close * (1 + takeProfitPercent)
shortStopLoss = close * (1 + stopLossPercent)
shortTakeProfit = close * (1 - takeProfitPercent)
longBreakEven = close * (1 + breakEvenPercent)
shortBreakEven = close * (1 - breakEvenPercent)
// Execute strategy with stop loss, take profit, and break-even
strategy.entry("Long", strategy.long, when = enterLong)
strategy.exit("Take Profit/Stop Loss Long", from_entry="Long", profit = longTakeProfit, loss = longStopLoss)
strategy.entry("Short", strategy.short, when = enterShort)
strategy.exit("Take Profit/Stop Loss Short", from_entry="Short", profit = shortTakeProfit, loss = shortStopLoss)
// Move stop loss to break even when price reaches break-even level
strategy.exit("Break Even Long", from_entry="Long", loss = longBreakEven)
strategy.exit("Break Even Short", from_entry="Short", loss = shortBreakEven)