Strategi ini memanfaatkan garis EMA untuk mengikuti tren dua arah, dan mengatur garis stop loss dinamis untuk posisi panjang dan pendek untuk menangkap pergerakan tren di pasar.
Peningkatan seperti manajemen risiko berbasis ATR, mengoptimalkan aturan stop loss, menambahkan indikator filter dll dapat membantu meningkatkan strategi.
Pada akhirnya, ini adalah tren yang sangat tipikal mengikuti strategi. crossover EMA ganda dengan stop loss dinamis dapat secara efektif mengunci keuntungan tren. Sementara itu risiko seperti sinyal tertinggal dan stop overwide masih ada. melalui penyesuaian parameter, manajemen risiko, penambahan filter dll, penyempurnaan lebih lanjut dapat mengarah pada hasil yang lebih baik.
/*backtest start: 2023-12-01 00:00:00 end: 2023-12-31 23:59:59 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("EMA Crossover Strategy", shorttitle="EMAC", overlay=true,calc_on_every_tick=true) // Input parameters shortEmaLength = input(5, title="Short EMA Length") longEmaLength = input(20, title="Long EMA Length") priceEmaLength = input(1, title="Price EMA Length") // Set stop loss level with input options (optional) longLossPerc = input.float(0.05, title="Long Stop Loss (%)", minval=0.0, step=0.1) * 0.01 shortLossPerc = input.float(0.05, title="Short Stop Loss (%)", minval=0.0, step=0.1) * 0.01 // Calculating indicators shortEma = ta.ema(close, shortEmaLength) longEma = ta.ema(close, longEmaLength) //priceEma = ta.ema(close, priceEmaLength) vwap = ta.vwap(close) // Long entry conditions longCondition = ta.crossover(shortEma, longEma) and close > vwap // Short entry conditions shortCondition = ta.crossunder(shortEma, longEma) and close > vwap // STEP 2: // Determine stop loss price longStopPrice = strategy.position_avg_price * (1 - longLossPerc) shortStopPrice = strategy.position_avg_price * (1 + shortLossPerc) if (longCondition) strategy.entry("Enter Long", strategy.long) strategy.exit("Exit Long",from_entry = "Enter Long",stop= longStopPrice) plotshape(series=longCondition, title="Long Signal", color=color.green, style=shape.triangleup, location=location.belowbar) if (shortCondition) strategy.entry("Enter Short", strategy.short) strategy.exit("Exit Short", from_entry = "Enter Short",stop = shortStopPrice) plotshape(series=shortCondition, title="Short Signal", color=color.red, style=shape.triangledown, location=location.abovebar) // Stop loss levels //longStopLoss = (1 - stopLossPercent) * close //shortStopLoss = (1 + stopLossPercent) * close // Exit conditions //strategy.exit("Long", from_entry="Long", loss=longStopLoss) //strategy.exit("Short", from_entry="Short", loss=shortStopLoss) // Plotting indicators on the chart plot(shortEma, color=color.yellow, title="Short EMA") plot(longEma, color=color.green, title="Long EMA") plot(close, color=color.black, title="Close") plot(vwap, color=color.purple, title="VWAP") // Plot stop loss values for confirmation plot(strategy.position_size > 0 ? longStopPrice : na, color=color.red, style=plot.style_line, linewidth=2, title="Long Stop Loss") plot(strategy.position_size < 0 ? shortStopPrice : na, color=color.blue, style=plot.style_line, linewidth=2, title="Short Stop Loss") // Plotting stop loss lines //plot(longStopLoss, color=color.red, title="Long Stop Loss", linewidth=2, style=plot.style_line) //plot(shortStopLoss, color=color.aqua, title="Short Stop Loss", linewidth=2, style=plot.style_line)