
Chiến lược này giao dịch dựa trên tín hiệu chéo của EMA23 và EMA50. Khi EMA23 vượt qua EMA50, nó tạo ra tín hiệu mua và khi vượt qua EMA50, nó tạo ra tín hiệu bán. Chiến lược này cũng sẽ dừng lỗ khi giá giảm xuống EMA50, và ngược lại dừng lỗ khi giá giảm xuống EMA50. Ngoài ra, chiến lược này cũng sẽ quay trở lại khi giá tăng lên EMA50.
Chiến lược này là một chiến lược giao dịch định lượng dựa trên giao lộ hai đường bằng nhau để nắm bắt xu hướng thông qua tín hiệu giao nhau của EMA23 và EMA50, và thiết lập các cơ chế dừng lỗ và tái nhập để kiểm soát rủi ro và nâng cao tiềm năng lợi nhuận. Chiến lược này đơn giản, dễ hiểu và phù hợp cho giao dịch ngắn hạn như 30 phút. Tuy nhiên, chiến lược này cũng có một số hạn chế, chẳng hạn như đánh giá xu hướng sau khi quá hạn, không tối ưu hóa dừng lỗ, thị trường xung đột không hoạt động tốt.
/*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)