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

Pine Script报错:无法调用'operator <',参数类型不匹配求协助

问题解决:Pine Script中float[]与simple float类型不匹配错误

错误原因

request.security_lower_tf()函数返回的是float[]数组类型,它会抓取当前主K线周期内所有更低周期的K线数据;而bar_5m_prev_low是单个浮点数(simple float),直接用<运算符比较数组和单个数值,必然触发类型不匹配的报错。

解决方案

你需要从request.security_lower_tf()返回的数组中提取单个浮点数元素,才能和bar_5m_prev_low进行比较。比如取当前主K线内最后一根低周期K线的收盘价:

min_bars_5m = input.timeframe(title="5 min bar imbalence", defval="5m")
bar_5m_prev_low = request.security(syminfo.tickerid,  timeframe=min_bars_5m, expression=low[1])
bar_5m_prev_high = request.security(syminfo.tickerid,  timeframe=min_bars_5m, expression=high[1])

min_bars_1s = input.timeframe(title="1s bar close", defval="10s")
// 提取低周期数组的最后一个元素(最新收盘价)
bar_1s_prev_close = request.security_lower_tf(syminfo.tickerid,  timeframe=min_bars_1s, expression=close)[0]

float bear_imbalence=0

if bar_1s_prev_close < bar_5m_prev_low
    bear_imbalence := low / 1.02

补充说明

  • 数组索引[0]代表数组的最后一个元素(最新的低周期K线数据),如果需要获取更早的低周期数据,可以调整索引值,比如[1]代表倒数第二个元素。
  • 也可以用array.size(bar_1s_prev_close)-1作为索引,效果和[0]一致,都是取数组最后一个元素。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.26 09:02:16