
A estratégia é baseada no cruzamento de sinais de EMA23 e EMA50. A estratégia gera um sinal de compra quando a EMA23 atravessa a EMA50 e um sinal de venda quando a EMA23 atravessa a EMA50. A estratégia também faz um stop loss em posições de alta posição quando o preço cai abaixo da EMA50 e, ao contrário, faz um stop loss em posições de baixa posição. Além disso, a estratégia também entra novamente quando o preço retorna à EMA50.
A estratégia é uma estratégia de negociação quantitativa baseada em cruzamentos de duplas equilíbrios para capturar tendências por meio de sinais de cruzamentos de EMA23 e EMA50, e configura mecanismos de parada e reentrada para controlar o risco e aumentar o potencial de lucro. A estratégia é simples e fácil de entender, adequada para negociações de curto prazo, como 30 minutos.
/*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)