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

自定义candle对象数组调用array.min报错:需传入float[]而非candle[]

解决自定义对象数组获取最小值的类型不匹配问题

你遇到的报错是因为array.min()函数仅支持传入float[]类型的数组,但你直接传入了自定义的candle[]对象数组,类型不匹配导致报错。要获取candle对象中Low字段的最小值,需要先提取所有对象的Low值生成float数组,再调用array.min()。

修正后的代码

type candle 
    int index
    float Low 

// 示例:往candle数组添加新元素(需根据你的实际逻辑补充)
// array.push(candle, candle.new(bar_index, low))

// 维护数组最多保留6个元素(简化原判断条件)
if array.size(candle) > 6
    array.shift(candle)

// 提取所有candle对象的Low值到float数组
float[] lowValues = array.new_float()
for candleItem in candle
    array.push(lowValues, candleItem.Low)

// 计算Low字段的最小值
minimum = array.min(lowValues)

关键说明

  • 先创建空的float[]数组lowValues,遍历candle数组时将每个对象的Low字段存入该数组
  • 此时array.min(lowValues)的参数类型符合要求,可正常计算最小值
  • 原代码中的判断条件(array.size(candle) - 1) > 5可简化为array.size(candle) > 6,逻辑完全一致且更易读

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.21 03:27:37