本策略运用50周期平滑移动平均线(SMMA)和20周期简单移动平均线(SMA)的交叉信号来判断买入和卖出时机。当快线SMA向上突破慢线SMMA时产生买入信号;当SMA向下跌破SMMA时产生卖出信号。同时,策略preset了固定止盈位和动态止损位来锁定利润和控制风险。
1.可以测试不同参数(周期数、过滤条件等)的组合,寻找最佳参数;
2.可以结合其他因子过滤信号,例如成交量突增;
3.可以采用参数优化工具寻找最优参数;
可以考虑结合移动止盈、比例止盈等其他止盈方式;
可以结合市场波动率计算动态止损幅度。
本策略整体运行简单,通过双均线捕捉趋势方向;灵活运用固定止盈和动态止损来锁定利润和控制风险,可谓风险和收益并重。本策略可进一步通过参数和规则优化来适应更广泛的市场环境。
/*backtest start: 2023-01-26 00:00:00 end: 2024-02-01 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=4 strategy("50 SMMA and 20 SMA Crossover with TP and SL", overlay=true) // Define 50 SMMA smma50 = sma(close, 50) // Define 20 SMA sma20 = sma(close, 20) // Plotting the SMMA and SMA plot(smma50, color=color.blue, title="50 SMMA") plot(sma20, color=color.red, title="20 SMA") // Initialize TP and SL variables tp = 150 var float sl_price = na // Buy Signal buySignal = crossover(sma20, smma50) strategy.entry("Buy", strategy.long, when = buySignal) strategy.exit("Take Profit/Stop Loss", from_entry="Buy", profit=tp, loss=sl_price) // Sell Signal sellSignal = crossunder(sma20, smma50) strategy.entry("Sell", strategy.short, when = sellSignal) strategy.exit("Take Profit/Stop Loss", from_entry="Sell", profit=tp, loss=sl_price) // Update stop loss level on every crossover if (buySignal or sellSignal) sl_price := close[bar_index + 1] // Plot Stop Loss level plotshape(series=sl_price != na, title="Stop Loss Level", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)