Pine Script中request.security函数股息计算异常问题咨询
Pine Script中request.security处理股息的异常解决方法
问题根源
request.security函数默认返回**前复权(Forward-Adjusted)**数据,该数据会提前将未来的股息、拆股等事件纳入历史价格计算,导致除息日前的历史价格被向上修正,和真实的除权后收盘价出现偏差。这就是你观察到的:除息日(2025年9月11日)前价格虚高、回溯至ETF成立时偏差更大的原因——加密货币无股息事件,所以不会触发这个问题。
解决方法
在request.security调用中添加adjustment参数,指定使用未复权的原始价格(参数值为adjustment.none),即可获取和直接调用close一致的真实收盘价。修改后的测试脚本如下:
//@version=6 indicator("request.security dividend issue fixed") plot(request.security(symbol = 'GETTEX:IQQA', timeframe = timeframe.period, expression = close, adjustment = adjustment.none), title = 'Unadjusted Close (request.security)', color=color.red ) plot(close, title = 'Standard close values (please select IQQA on Gettex)', color=color.green)
参数说明
adjustment参数有三个可选值:
adjustment.all(默认):返回前复权数据,提前调整历史价格以匹配当前价格水平adjustment.none:返回未复权的原始价格,完整保留股息、拆股等事件带来的价格跳空adjustment.dividends_only:仅针对股息进行复权调整,不处理拆股事件
内容的提问来源于stack exchange,提问作者Foto Koen
相关产品推荐
相关产品推荐

