该策略利用EMA快线和慢线的金叉和死叉来判断趋势,并结合预设的止盈比例来实现趋势跟踪交易。该策略适用于任意时间周期,可以实现指数和个股的趋势捕捉。
该策略使用长度为3和30的EMA线作为交易信号。当3EMA上穿30EMA时,表明价格开始上涨,符合买入条件;当3EMA下穿30EMA时,表明价格开始下跌,符合卖出条件。
同时,策略还设置了止盈条件。当价格上涨达到策略进入价按照设置的止盈比例后,就会 EXIT。这样可以锁定更多利润,实现趋势跟踪交易。
该策略总体来说是一个非常实用的趋势跟踪策略。它利用简单的EMA指标判断趋势方向,设置合理的止盈规则,可以有效控制风险,适合长线追踪股票和指数的中长线走势。通过参数优化和配套指标验证,可以进一步提升策略的稳定性和Profit Factor。
/*backtest start: 2023-02-12 00:00:00 end: 2024-02-18 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("EMA Crossover Strategy with Target", shorttitle="EMACross", overlay=true) // Define input parameters fastLength = input(3, title="Fast EMA Length") slowLength = input(30, title="Slow EMA Length") profitPercentage = input(100.0, title="Profit Percentage") // Calculate EMAs fastEMA = ta.ema(close, fastLength) slowEMA = ta.ema(close, slowLength) // Plot EMAs on the chart plot(fastEMA, color=color.blue, title="Fast EMA") plot(slowEMA, color=color.red, title="Slow EMA") // Buy condition: 3EMA crosses above 30EMA buyCondition = ta.crossover(fastEMA, slowEMA) // Sell condition: 3EMA crosses below 30EMA or profit target is reached sellCondition = ta.crossunder(fastEMA, slowEMA) or close >= (strategy.position_avg_price * (1 + profitPercentage / 100)) // Target condition: 50 points profit //targetCondition = close >= (strategy.position_avg_price + 50) // Execute orders // strategy.entry("Buy", strategy.long, when=buyCondition) // strategy.close("Buy", when=sellCondition ) if (buyCondition) strategy.entry("Buy", strategy.long) if (sellCondition) strategy.close("Buy") // // Execute sell orders // strategy.entry("Sell", strategy.short, when=sellCondition) // strategy.close("Sell", when=buyCondition) // Plot buy and sell signals on the chart plotshape(series=buyCondition, title="Buy Signal", color=color.green, style=shape.labelup, location=location.belowbar) plotshape(series=sellCondition, title="Sell Signal", color=color.red, style=shape.labeldown, location=location.abovebar)