
이 전략은 EMA23와 EMA50의 교차 신호를 기반으로 거래한다. EMA23이 EMA50을 통과하면 구매 신호가 발생하고, EMA50을 통과하면 판매 신호가 발생한다. 이 전략은 가격이 EMA50을 넘어지면 다단위 포지션을 중지하고, 반대로 공수 포지션을 중지한다. 또한, 이 전략은 가격이 EMA50에 다시 올라갈 때 다시 진입한다. 이 전략은 30분 시간 프레임에 적용된다.
이 전략은 EMA23와 EMA50의 교차 신호를 통해 트렌드를 포착하고, 위험을 제어하고 수익 잠재력을 높이기 위해 중지 및 재입장 메커니즘을 설정하는 양적 거래 전략입니다. 이 전략은 간단하고 이해하기 쉽습니다. 30 분과 같은 중장기 거래에 적합합니다. 그러나 이 전략에는 트렌드 판단이 지연되고, 중지 손실 최적화가 부족하고, 주동 시장이 좋지 않은 성능과 같은 몇 가지 제한이 있습니다.
/*backtest
start: 2023-04-20 00:00:00
end: 2024-04-25 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("EMA Crossover Strategy", overlay=true)
// EMA 23 ve EMA 50'nin hesaplanması
ema23 = ta.ema(close, 23)
ema50 = ta.ema(close, 50)
// Ana alım kuralı: EMA 23 ve EMA 50'nin yukarı kesilmesi
buySignal = ta.crossover(ema23, ema50)
// Ana satış kuralı: EMA 23 ve EMA 50'nin aşağı kesilmesi
sellSignal = ta.crossunder(ema23, ema50)
// Long pozisyon stop seviyesi
longStopLoss = low < ema50 and close < ema50[1]
// Short pozisyon stop seviyesi
shortStopLoss = high > ema50 and close > ema50[1]
// Long pozisyon için tekrar giriş kuralı
longReEntry = high > ema50 and close > ema50 and close > ema50 and ema23 > ema50
// Short pozisyon için tekrar giriş kuralı
shortReEntry = low < ema50 and close < ema50 and close < ema50 and ema23 < ema50
// Long işlemde kar alma seviyesi (%60)
longTakeProfit = strategy.position_avg_price * 1.60
// Short işlemde kar alma seviyesi (%25)
shortTakeProfit = strategy.position_avg_price * 0.75
// Long işlem için yeniden giriş koşulu
longReEntryCondition = strategy.position_size <= 0 and longReEntry
// Short işlem için yeniden giriş koşulu
shortReEntryCondition = strategy.position_size >= 0 and shortReEntry
// Geriye dönük test için başlangıç tarihi (01.01.2022)
startDate = timestamp(2022, 01, 01, 00, 00)
if (time >= startDate)
if (buySignal)
strategy.entry("Buy", strategy.long)
if (sellSignal)
strategy.entry("Sell", strategy.short)
if (strategy.position_size > 0 and (longStopLoss or close >= longTakeProfit))
strategy.close("Buy")
if (strategy.position_size < 0 and (shortStopLoss or close <= shortTakeProfit))
strategy.close("Sell")
if (longReEntryCondition)
strategy.entry("Buy", strategy.long)
if (shortReEntryCondition)
strategy.entry("Sell", strategy.short)