该策略主要通过识别特定的K线形态–Pin Bar来判断潜在的市场反转点。Pin Bar是一种由长影线和小实体组成的K线形态,表明市场在该点位出现了较大的波动,但最终价格回撤,显示出该点位可能是一个支撑或阻力位。该策略采用50周期简单移动平均线(SMA)来判断当前趋势方向,并使用20周期SMA作为交易量过滤条件,只有在Pin Bar出现时交易量大于该均线才认为是有效信号。此外,该策略还计算了相对强弱指标(RSI),但并未直接用于入场和出场条件中,而是作为进一步过滤信号的可选条件。
该Pin Bar反转策略采用了简单有效的思路,通过趋势过滤、交易量过滤等方式提高了信号识别的准确性。虽然目前还有一些可以改进的地方,但整体思路是可行的,值得进一步优化测试。Pin Bar本身作为一种经典的价格形态,也可以和其他指标或信号结合使用,以期获得更稳健的交易系统。
/*backtest start: 2024-05-01 00:00:00 end: 2024-05-31 23:59:59 period: 1h basePeriod: 15m exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("Filtered Pin Bar Strategy with Relaxed Volume", overlay=true) // Define the size of the pin bar's wick and body wickSize = 0.6 bodySize = 0.3 // Calculate the size of the wicks and body upperWick = high - math.max(open, close) lowerWick = math.min(open, close) - low body = math.abs(close - open) // Define a simple moving average to determine the trend smaLength = 50 sma = ta.sma(close, smaLength) // Define a more relaxed volume threshold volumeThreshold = ta.sma(volume, 20) * 1.0 // Define RSI parameters rsiLength = 14 rsiOverbought = 70 rsiOversold = 30 rsi = ta.rsi(close, rsiLength) // Define the conditions for a bullish pin bar bullishPinBar = (lowerWick > (wickSize * (high - low))) and (body < (bodySize * (high - low))) and (close > open) and (close > sma) and (volume > volumeThreshold) // Define the conditions for a bearish pin bar bearishPinBar = (upperWick > (wickSize * (high - low))) and (body < (bodySize * (high - low))) and (close < open) and (close < sma) and (volume > volumeThreshold) // Plot the bullish and bearish pin bars on the chart plotshape(series=bullishPinBar, title="Bullish Pin Bar", location=location.belowbar, color=color.green, style=shape.labelup, text="PB") plotshape(series=bearishPinBar, title="Bearish Pin Bar", location=location.abovebar, color=color.red, style=shape.labeldown, text="PB") // Entry and exit rules if (bullishPinBar) strategy.entry("Bullish Pin Bar", strategy.long) if (bearishPinBar) strategy.entry("Bearish Pin Bar", strategy.short) // Optional: Set stop loss and take profit stopLoss = 2 * body takeProfit = 3 * body strategy.exit("Exit Long", from_entry="Bullish Pin Bar", stop=low - stopLoss, limit=high + takeProfit) strategy.exit("Exit Short", from_entry="Bearish Pin Bar", stop=high + stopLoss, limit=low - takeProfit)