You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PineScript V5中input.timeframe多时间框架功能失效问题求助

解决Parabolic WMA多时间框架功能失效的问题

你添加了时间框架输入但未生效,核心原因是没有基于指定时间框架获取对应的数据源,当前脚本仍在使用当前图表周期的数据计算PWMA。需要修改以下内容:

1. 替换数据源为指定时间框架的数据

将原有的源数据定义,改为通过request.security()函数拉取目标时间框架下的数据——这是Pine Script实现多时间框架指标的核心操作:

// 先保留源数据输入选项,再通过request.security获取指定周期的数据
sourceInput = input(title='Source', defval=close)
src = request.security(syminfo.tickerid, Timeframe, sourceInput)

request.security()的作用是从当前交易标的(syminfo.tickerid)、指定时间框架(Timeframe)中,获取你设置的源数据(比如收盘价)。

2. 可选:调整数据合并逻辑(按需选择)

如果目标时间框架比当前图表周期大,指标线会呈现阶梯状跳变,这是多时间框架指标的正常表现。若需要更连贯的显示,可给request.security()添加参数:

src = request.security(syminfo.tickerid, Timeframe, sourceInput, gaps=barmerge.gaps_on, lookahead=barmerge.lookahead_on)
  • gaps_on:保留周期切换时的间隙
  • lookahead_on:用未来数据填充间隙(注意实盘使用可能存在信号延迟问题)

修改后的完整脚本

//@version=5
// Copyright (c) 2019-present, Alex Orekhov (everget)
// Parabolic Weighted Moving Average script may be freely distributed under the MIT license.
indicator('Parabolic WMA', shorttitle='PWMA', overlay=true)

length = input(title='Length', defval=14)
power = input.int(title='Power', minval=0, defval=2)
Timeframe = input.timeframe(defval = "60", title = "Timeframe")
sourceInput = input(title='Source', defval=close)
highlightMovements = input(title='Highlight Movements ?', defval=true)

// 获取指定时间框架的数据源
src = request.security(syminfo.tickerid, Timeframe, sourceInput)

sum = 0.0
weightSum = 0.0

for i = 0 to length - 1 by 1
    weight = math.pow(length - i, power)
    sum += nz(src[i]) * weight
    weightSum += weight

pwma = sum / weightSum

pwmaColor = highlightMovements ? pwma > pwma[1] ? color.green : color.red : #6d1e7f
plot(pwma, title='PWMA', linewidth=2, color=pwmaColor, transp=0)

内容的提问来源于stack exchange,提问作者boy thunder

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.04 23:26:14