该策略基于枢轴点(Pivot Points)来识别市场反转点,并以此为基础进行交易。当市场在左侧4根K线内出现枢轴点高点(Pivot High)时,策略开仓做多;当市场在左侧4根K线内出现枢轴点低点(Pivot Low)时,策略开仓做空。策略的止损设置在开仓价格的上下一个最小价格变动单位(syminfo.mintick)。策略的退出条件有两个:1)当出现下一个相反方向的枢轴点时平仓;2)当浮亏达到30%时平仓。
该策略基于枢轴点指标构建了一个双向交易系统,通过在枢轴点高点做多、低点做空来捕捉市场反转机会。策略具有一定的理论基础和实践价值,但是由于枢轴点指标本身的局限性,策略在实际运行中可能面临一些风险和挑战。通过优化枢轴点指标类型、参数、过滤条件、止盈止损等,有望进一步提升该策略的稳健性和盈利能力。
/*backtest start: 2023-04-24 00:00:00 end: 2024-04-29 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("Pivot Reversal Strategy with Pivot Exit", overlay=true) leftBars = input(4) rightBars = input(2) var float dailyEquity = na // Reset equity to $10,000 at the beginning of each day isNewDay = ta.change(time("D")) != 0 if (isNewDay) dailyEquity := 10000 // Calculate pivot highs and lows swh = ta.pivothigh(leftBars, rightBars) swl = ta.pivotlow(leftBars, rightBars) // Define long entry condition swh_cond = not na(swh) hprice = 0.0 hprice := swh_cond ? swh : hprice[1] le = false le := swh_cond ? true : (le[1] and high > hprice ? false : le[1]) // Enter long position if long entry condition is met if (le) strategy.entry("PivRevLE", strategy.long, comment="EnterLong", stop=hprice + syminfo.mintick) // Define short entry condition swl_cond = not na(swl) lprice = 0.0 lprice := swl_cond ? swl : lprice[1] se = false se := swl_cond ? true : (se[1] and low < lprice ? false : se[1]) // Enter short position if short entry condition is met if (se) strategy.entry("PivRevSE", strategy.short, comment="EnterShort", stop=lprice - syminfo.mintick) // Exit condition: Exit at the next pivot point exitAtNextPivot() => if strategy.opentrades > 0 if strategy.position_size > 0 // Exiting long position at next pivot low if not na(swl) strategy.exit("ExitLong", "PivRevLE", stop=swl - syminfo.mintick) else // Exiting short position at next pivot high if not na(swh) strategy.exit("ExitShort", "PivRevSE", stop=swh + syminfo.mintick) // Call exitAtNextPivot function exitAtNextPivot() // Exit condition: Exit if profit is less than 30% exitIfProfitLessThanThirtyPercent() => if strategy.opentrades > 0 if strategy.position_size > 0 // Calculate profit percentage for long position profit_percentage_long = (close - strategy.position_avg_price) / strategy.position_avg_price * 100 // Exiting long position if profit is less than 30% if profit_percentage_long < -30 strategy.close("PivRevLE") else // Calculate profit percentage for short position profit_percentage_short = (strategy.position_avg_price - close) / strategy.position_avg_price * 100 // Exiting short position if profit is less than 30% if profit_percentage_short < -30 strategy.close("PivRevSE") // Call exitIfProfitLessThanThirtyPercent function exitIfProfitLessThanThirtyPercent()