本策略运用双均线系统,在特定的股票或数字货币中寻找潜在的突破机会。其基本原理是当短期均线从长期均线下方反弹时,买入股票或数字货币。当价格重新测试长期均线时,卖出股票或数字货币。
该策略使用两个不同周期的简单移动平均线(SMA)作为交易信号。第一个SMA周期较长,代表整体趋势方向。第二个SMA周期较短,用于捕捉短期价格波动。
当短期SMA从下方上穿长期SMA时,代表价格在整体上涨趋势中,因此策略打开多头仓位。当价格下跌重新测试长期SMA时,预示着短期 pullback 结束,这时策略会考虑止损或利润了结仓位。
另外,策略还设定了“超卖”和“超买”条件,避免在极端情况下交易。只有同时满足双均线交叉和合理估值条件时,才会开仓。
该策略还有进一步优化的空间:
本策略整合趋势跟踪与回调交易的优势,利用双均线系统来判断机会的出现。同时,内置一定的超买超卖条件,可避免不必要的头寸打开。这是一个非常实用的量化交易策略,值得深入研究与优化。
/*backtest start: 2023-02-20 00:00:00 end: 2024-02-26 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ // @version=5 strategy("Profitable Pullback Trading Strategy", overlay=true,initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100) // Inputs ma_length1 = input.int(280,'MA length 1', step = 10,group = 'Moving Avg. Parameters', inline = 'MA') ma_length2 = input.int(13,'MA length 2', step = 1,group = 'Moving Avg. Parameters', inline = 'MA') sl = input.float(title="Stop Loss (%)", defval=0.07, step=0.1, group="Moving Avg. Parameters") too_deep = input.float(title="Too Deep (%)", defval=0.27, step=0.01, group="Too Deep and Thin conditions", inline = 'Too') too_thin = input.float(title="Too Thin (%)", defval=0.03, step=0.01, group="Too Deep and Thin conditions", inline = 'Too') // Calculations ma1 = ta.sma(close,ma_length1) ma2 = ta.sma(close,ma_length2) too_deep2 = (ma2/ma1-1) < too_deep too_thin2 = (ma2/ma1-1) > too_thin // Entry and close condtions var float buy_price = 0 buy_condition = (close > ma1) and (close < ma2) and strategy.position_size == 0 and too_deep2 and too_thin2 close_condition1 = (close > ma2) and strategy.position_size > 0 and (close < low[1]) stop_distance = strategy.position_size > 0 ? ((buy_price - close) / close) : na close_condition2 = strategy.position_size > 0 and stop_distance > sl stop_price = strategy.position_size > 0 ? buy_price - (buy_price * sl) : na // Entry and close orders if buy_condition strategy.entry('Long',strategy.long) if buy_condition[1] buy_price := open if close_condition1 or close_condition2 strategy.close('Long',comment="Exit" + (close_condition2 ? "SL=true" : "")) buy_price := na plot(ma1,color = color.blue) plot(ma2,color = color.orange)