该策略是一个基于22周期指数移动平均线(EMA)交叉信号和摆动点位的交易系统。它通过价格与EMA的交叉来产生交易信号,并利用自适应的摆动高点和低点来设置止盈止损位置。这种方法既保证了趋势跟踪的基本功能,又增加了风险管理的灵活性。
策略的核心逻辑包含以下几个关键要素: 1. 使用22周期EMA作为主要趋势指标,这个周期能较好地过滤市场噪音 2. 当收盘价上穿EMA时触发做多信号,下穿时触发做空信号 3. 通过14周期的历史数据计算摆动高点和低点 4. 做多交易以最近的摆动高点作为止盈目标,摆动低点作为止损位 5. 做空交易以最近的摆动低点作为止盈目标,摆动高点作为止损位
这是一个结构完整、逻辑清晰的趋势跟踪策略。通过EMA交叉产生交易信号,利用摆动点位管理风险,形成了一个平衡的交易系统。策略的主要优势在于其动态适应市场的能力,而主要风险来自于市场状态的突变。通过建议的优化方向,策略的稳定性和盈利能力有望得到进一步提升。
/*backtest
start: 2024-02-21 00:00:00
end: 2025-02-18 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"SOL_USDT"}]
*/
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © GlenMabasa
//@version=6
strategy("22 EMA Crossover Strategy", overlay=true)
// Input for the EMA length
ema_length = input.int(22, title="EMA Length")
// Calculate the 22-day Exponential Moving Average
ema_22 = ta.ema(close, ema_length)
// Plot the 22 EMA
plot(ema_22, color=color.blue, title="22 EMA")
// Buy condition: Price crosses and closes above the 22 EMA
buy_condition = ta.crossover(close, ema_22) and close > ema_22
// Sell condition: Price crosses or closes below the 22 EMA
sell_condition = ta.crossunder(close, ema_22) or close < ema_22
// Swing high and swing low calculations
swing_high_length = input.int(14, title="Swing High Lookback")
swing_low_length = input.int(14, title="Swing Low Lookback")
swing_high = ta.highest(high, swing_high_length) // Previous swing high
swing_low = ta.lowest(low, swing_low_length) // Previous swing low
// Profit target and stop loss for buys
buy_profit_target = swing_high
buy_stop_loss = swing_low
// Profit target and stop loss for sells
sell_profit_target = swing_low
sell_stop_loss = swing_high
// Plot buy and sell signals
plotshape(series=buy_condition, title="Buy Signal", location=location.belowbar, color=color.green, style=shape.labelup, text="BUY")
plotshape(series=sell_condition, title="Sell Signal", location=location.abovebar, color=color.red, style=shape.labeldown, text="SELL")
// Strategy logic for backtesting
if (buy_condition)
strategy.entry("Buy", strategy.long)
strategy.exit("Take Profit/Stop Loss", "Buy", limit=buy_profit_target, stop=buy_stop_loss)
if (sell_condition)
strategy.entry("Sell", strategy.short)
strategy.exit("Take Profit/Stop Loss", "Sell", limit=sell_profit_target, stop=sell_stop_loss)