algorithmic trading - "symbol self.volume[0].value_or not found" when accessing volume data - Stack Overflow

I'm working on a Volume Flow Indicator (VFI) script in Indie, and I'm running into an error w

I'm working on a Volume Flow Indicator (VFI) script in Indie, and I'm running into an error when trying to get a value from self.volume[0]. Specifically, I get this error:

Error: 25:13 symbol self.volume[0].value_or not found

Source code:

# indie:lang_version = 5
import math
from indie import indicator, param, MutSeriesF, level, line_style, color, plot, SeriesF
from indie.algorithms import StdDev, Sma, Sum, Ema

@indicator('VFI')  # Volume Flow Indicator
@param.int('length', default=130, min=1, title='VFI length')
@param.float('coef', default=0.2, title='Cutoff coef')
@param.float('vcoef', default=2.5, title='Max. vol. cutoff')
@param.int('signal_length', default=5, min=1, title='Signal length')
@param.bool('smooth_vfi', default=False, title='Smooth VFI')
@param.bool('show_histo', default=True, title='Show histogram')
@level(0, line_color=color.GRAY, line_style=line_style.DASHED)
@plot.histogram(color=color.GRAY(0.5), line_width=3, id='plot_0')
@plot.line(color=color.RED, title='EMA of VFI', id='plot_1')
@plot.line(color=color.GREEN, line_width=2, title='VFI', id='plot_2')
def Main(self, length, coef, vcoef, signal_length, smooth_vfi, show_histo):
    typical = self.hlc3

    inter = math.log(typical[0]) - math.log(typical[1])
    vinter = StdDev.new(MutSeriesF.new(inter), 30)[0]
    cutoff = coef * vinter * self.close[0]
    vave = Sma.new(self.volume, length)[1]
    vmax = vave * vcoef
    vc = min(self.volume[0].value_or(math.nan), vmax)
    mf = typical[0] - typical[1]

    vcp = MutSeriesF.new(0)
    
    if mf > cutoff:
        vcp[0] = vc  
    elif mf < -cutoff:
        vcp[0] = -vc  

    vfi: SeriesF = MutSeriesF.new(Sum.new(vcp, length)[0] / vave)
    if smooth_vfi:
        vfi = Sma.new(vfi, 3)

    vfima = Ema.new(vfi, signal_length)
    d = vfi[0] - vfima[0]

    return (
        d if show_histo else math.nan,
        vfima[0],
        vfi[0],
    )

I thought that self.volume[0] was a SeriesF, and I needed to use .value_or(math.nan) to extract a float. But Indie says value_or is not found.

  • Do SeriesF built-in variables like self.volume[0] not support .value_or()?
  • How should I properly extract the value of self.volume[0] for use in min()?
  • Is there another way to handle missing values in Indie?

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744371387a4570969.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信