TradingView RSI策略入场延迟求助:实现同Bar收盘价入场
RSI交易策略入场/平仓延迟问题及解决方案
问题详情
- 需求:当某根K线收盘时RSI(5)低于20,在该K线收盘价执行多单入场;当持仓盈利时,在K线收盘价平仓。
- 现状:所有入场、平仓指令都延迟了一根K线执行。
- 疑问:推测是RSI基于收盘价计算导致无法在同一根K线内触发交易,但不确定是否正确;想知道能否在收盘前计算RSI以实现收盘后同一根K线内成交,且仅用于回测,无需实盘。
当前代码片段
// Open a long position when RSI(5) is below 20 if (rsiValue < 20) entryPrice := na(entryPrice) ? close : entryPrice // Store entry price when first entering // Exit each individual lot when the lot is profitable at the close of a bar exitCondition = close > entryPrice
解决方案(已验证)
截至2024年11月26日问题已解决,感谢@Starr Lucky。只需在策略声明中添加参数:
strategy("Your Strategy Name", process_orders_on_close = true)
该参数会让策略在K线收盘价确定后,于同一根K线内处理交易指令,解决延迟问题。
内容的提问来源于stack exchange,提问作者Scott Brooks
相关产品推荐
相关产品推荐

