最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin7浏览0评论

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?
发布评论

评论列表(0)

  1. 暂无评论