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

technical indicator - Pos arg 1 of <class 'float'> type does not match with the param of type &

programmeradmin2浏览0评论

I'm working on an Indie v5 indicator that applies an EMA to a price series, but I'm running into this error when calling Ema.new():

Error: 25:21 could not find function definition that matches `indie.algorithms.Ema.new` call, reason: pos arg `1` of <class 'float'> type does not match with the param of type `<class 'indie.Series[float]'>`

Code:

# indie:lang_version = 5
import math
from indie import indicator, param, plot, color, MutSeriesF, Optional
from indie.algorithms import Ema, Atr, Bb

@indicator('Heikin Ashi Trend Channel Advanced', overlay_main_pane=True)
@param.int('ema_length', default=10, min=1, title='EMA Length for Smoothing')
@param.int('ema_length2', default=20, min=1, title='Secondary EMA Length')
@param.float('atr_multiplier', default=2.0, min=0.5, max=5.0, title='ATR Multiplier')
@param.bool('use_bb_smoothing', default=False, title='Use Bollinger Band Smoothing?')
@param.int('bb_length', default=20, min=1, title='Bollinger Band Length')
@param.bool('use_heikin_ashi', default=True, title='Use Heikin Ashi Close?')

@plot.line('upper_band', color=color.BLUE, title='Upper Band')
@plot.line('middle_band', title='Middle Band')
@plot.line('lower_band', color=color.BLUE, title='Lower Band')
@plot.line('breakout_signal', color=color.YELLOW, title='Breakout Signal')

@plot.fill('lower_band', 'upper_band', color=color.GRAY(0.1), title='Trend Channel')

def Main(self, ema_length, ema_length2, atr_multiplier, use_bb_smoothing, bb_length, use_heikin_ashi):
    price_close = (self.open[0] + self.high[0] + self.low[0] + self.close[0]) / 4 if use_heikin_ashi else self.close[0]
    price_series = price_close  

    smoothed_price = Ema.new(price_series, ema_length)  
    smoothed_price2 = Ema.new(smoothed_price, ema_length2)  

    atr_value = Atr.new(ema_length)[0]  

    price_ratio = self.close[0] / price_close if price_close != 0 else 1
    adaptive_multiplier = atr_multiplier * price_ratio

    middle_band = smoothed_price2[0]

    if use_bb_smoothing:
        bb_middle, _, _ = Bb.new(smoothed_price2, bb_length, 2.0)
        middle_band = bb_middle[0]

    upper_band = middle_band + (adaptive_multiplier * atr_value)
    lower_band = middle_band - (adaptive_multiplier * atr_value)

    middle_band_color = color.GREEN if middle_band > smoothed_price2[1] else color.RED

    breakout_signal: Optional[float] = None
    if self.close[0] > upper_band:
        breakout_signal = upper_band  
    elif self.close[0] < lower_band:
        breakout_signal = lower_band

    return (
        plot.Line(upper_band),
        plot.Line(middle_band, color=middle_band_color),
        plot.Line(lower_band),
        plot.Line(breakout_signal.value_or(math.nan)),
        plot.Fill()
    )

I thought I could just pass self.close[0] into Ema.new(), but the error suggests that it expects a Series[float]. I’m a bit confused because self.close is a series, so I assumed self.close[0] would be fine.

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论