本策略基于单一指标——平滑海坚线,实现简单的趋势跟踪买卖操作。策略利用平滑海坚线指标识别趋势方向,结合历史K线形态判断入场时机,以获利退出。
该策略通过计算移动平均线,构建平滑海坚线。具体来说,是计算开盘价、最高价、最低价、收盘价的移动平均线,然后计算平滑海坚线的开盘价、最高价、最低价、收盘价。
判断买入条件:当前K线收盘价大于前一K线收盘价,前一K线收盘价大于前两K线收盘价,近三K线都是阳线。
判断卖出条件:当前K线收盘价小于前一K线收盘价,前一K线收盘价小于前两K线收盘价,近三K线都是阴线。
买入和卖出条件都要满足最近一次信号为0或相反信号,避免连续重复交易。
可通过结合其它指标判断长期趋势,优化止损策略,注意大盘环境等进行改进。
本策略利用海坚线指标的趋势跟踪功能,配合K线形态判断入场时机,通过过滤重复信号控制交易频率。策略逻辑简单清晰,容易实现。但可通过多指标组合、优化止损、关注大盘等进行改进,使策略更稳健可靠。
/*backtest
start: 2022-09-30 00:00:00
end: 2023-10-06 00:00:00
period: 2d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//Masoud Abdoli
//Heikin Ashi Smoothed Buy & Sell Strategy Rev.4
//Date: 01-Oct-2021
//@version=4
strategy(title="Abdoli's Heikin Ashi Smoothed Buy & Sell Strategy Rev.4", shorttitle="Heikin-Ashi Smoothed Rev.4", overlay=true,
initial_capital=1000, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
MaPeriod = input (title="Moving Average Period?", type=input.integer, defval=65, minval=5, maxval=100, step=5)
maOpen = ema(open , MaPeriod)
maHigh = ema(high , MaPeriod)
maLow = ema(low , MaPeriod)
maClose = ema(close, MaPeriod)
haClose = (maOpen+maHigh+maLow+maClose)/4
haOpen = 0.0
haOpen:= na(haOpen[1]) ? (maOpen[1]+maClose[1])/2 : (haOpen[1]+haClose[1])/2
haHigh = max(maHigh, max(haClose, haOpen))
haLow = min(maLow , max(haClose, haOpen))
plotcandle(haOpen, haHigh, haLow, haClose, title="heikin-Ashi smoothed", color=haOpen>haClose ? color.orange : color.blue)
B0 = haClose - haOpen
B1 = haClose[1] - haOpen[1]
B2 = haClose[2] - haOpen[2]
BuyCondition = B0 > 0.0 and B1 > 0.0 and B2 > 0.0 and haClose > haClose[1] and haClose[1] > haClose[2]
SellCondition= B0 < 0.0 and B1 < 0.0 and B2 < 0.0 and haClose < haClose[1] and haClose[1] < haClose[2]
last_signal = 0
Buy_final = BuyCondition and (nz(last_signal[1]) == 0 or nz(last_signal[1]) ==-1)
Sell_final = SellCondition and (nz(last_signal[1]) == 0 or nz(last_signal[1]) == 1)
last_signal := Buy_final ? 1 : Sell_final ? -1 : last_signal[1]
plotshape(Buy_final , style=shape.labelup , location=location.belowbar, color=color.blue, title="Buy label" , text="BUY" , textcolor=color.white)
plotshape(Sell_final, style=shape.labeldown, location=location.abovebar, color=color.red , title="Sell label", text="SELL", textcolor=color.white)
strategy.entry("Buy", strategy.long, when=Buy_final)
strategy.close("Buy", when=Sell_final)