该策略基于近期最高价和最低价设置止损点,以快速切入趋势并严格控制风险。当价格出现连续上涨时开多单,连续下跌时开空单。持仓时,多单止损位置为最近几根K线的最低价,空单止损位置为最近几根K线的最高价。这种动态止损方式能高效捕捉趋势,同时严格限制损失。
input
函数设置最高价和最低价参考周期hiLen
和loLen
,默认为20。ta.highest(high, hiLen)[1]
计算前一根K线为止的最高价hiHighs
,用ta.lowest(low, loLen)[1]
计算前一根K线为止的最低价loLows
。loLows
,空单止损位置为hiHighs
,不持仓时不画,方便直观确认。higherCloses
lowerCloses
isFlat
isFlat
和higherCloses
时开多单,满足isFlat
和lowerCloses
时开空单。loLows
,空单持仓时,止损价格为hiHighs
。简言之,该策略用近期最高最低价设置移动止损,快速切入强劲趋势并严格限损,能高效捕捉趋势收益。
该最高最低价格止损策略基于价格本身设置动态止损,能高效捕捉强劲趋势,严格控制风险。其优点是简单有效,快速切入,止损严格,适应性强。但在震荡市、趋势末期、极端行情下表现欠佳,参数设置也需要注意。未来可通过增加趋势和动量判断、优化止损和仓位管理等方式改进。总的来说,这是一个兼顾趋势捕捉和风险控制的简单有效策略,值得在实践中深入研究和优化。
/*backtest start: 2023-03-02 00:00:00 end: 2024-03-07 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy(title="Highest high/lowest low stop", overlay=true) // STEP 1: // Make inputs for length of highest high and lowest low hiLen = input.int(20, title="Highest High Lookback", minval=2) loLen = input.int(20, title="Lowest Low Lookback", minval=2) // STEP 2: // Calculate recent extreme high and low hiHighs = ta.highest(high, hiLen)[1] loLows = ta.lowest(low, loLen)[1] // Plot stop values for visual confirmation plot(strategy.position_size > 0 ? loLows : na, style=plot.style_circles, color=color.green, linewidth=3, title="Lowest Low Stop") plot(strategy.position_size < 0 ? hiHighs : na, style=plot.style_circles, color=color.red, linewidth=3, title="Highest High Stop") // Trading conditions for this example strategy higherCloses = close > close[1] and close[1] > close[2] and close[2] > close[3] lowerCloses = close < close[1] and close[1] < close[2] and close[2] < close[3] isFlat = strategy.position_size == 0 // Submit entry orders if isFlat and higherCloses strategy.entry("EL", strategy.long) if isFlat and lowerCloses strategy.entry("ES", strategy.short) // STEP 3: // Submit stops based on highest high and lowest low if strategy.position_size > 0 strategy.exit("XL HH", stop=loLows) if strategy.position_size < 0 strategy.exit("XS LL", stop=hiHighs)