
This strategy is based on the crossover signals of EMA23 and EMA50 for trading. When EMA23 crosses above EMA50, it generates a buy signal, and when it crosses below, it generates a sell signal. The strategy also implements a stop-loss for long positions when the price falls below EMA50 and for short positions when the price rises above EMA50. Additionally, the strategy re-enters the market when the price moves back above EMA50. The strategy is suitable for the 30-minute timeframe.
This strategy is a quantitative trading strategy based on the crossover of two moving averages, EMA23 and EMA50. It captures trends through the crossover signals and implements stop-loss and re-entry mechanisms to control risk and increase profit potential. The strategy is simple and easy to understand, suitable for medium to short-term trading on the 30-minute timeframe. However, the strategy also has some limitations, such as lagging trend identification, suboptimal stop-loss placement, and poor performance in ranging markets. In the future, the strategy can be optimized by introducing more technical indicators, optimizing stop-loss positions, controlling trading frequency, differentiating between trending and ranging markets, and implementing dynamic take-profit levels to achieve more robust returns.
/*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)