Why do I get AttributeError: 'mom.MOM' object has no attribute 'period'
when implementing an indicator just like EfficiencyRatio
?
#2768
-
I'm trying to implement a custom indicator The environment is a Python 3.11 virtual environment with from setuptools import setup
from Cython.Build import cythonize
setup(
ext_modules=cythonize("mom.pyx", gdb_debug=True)
) After successfully compiling from myindicators.mom import MOM
from nautilus_trader.indicators.efficiency_ratio import EfficiencyRatio
class DemoStrategy(Strategy):
def __init__(self, primary_bar_type: BarType):
...
self.mom_5 = MOM(5)
self.eff_5 = EfficiencyRatio(5)
... However, when I run the strategy, I get the following error:
Here is a simplified version of # cython: language_level=3
from collections import deque
from nautilus_trader.core.correctness cimport Condition
from nautilus_trader.indicators.base.indicator cimport Indicator
from nautilus_trader.model.data cimport Bar
from nautilus_trader.core.rust.model cimport PriceType
from nautilus_trader.model.data cimport QuoteTick, TradeTick
from nautilus_trader.model.objects cimport Price
cdef class MOM(Indicator):
def __init__(self, int period, PriceType price_type=PriceType.LAST):
Condition.positive_int(period, "period")
super().__init__(params=[period])
self.period = period
self.price_type = price_type
self._inputs = deque(maxlen=5000)
self.value = 0
... The strange thing is, the built-in cdef public int period
cdef public object price_type
cdef public object _inputs
cdef public double value After adding these So my question is: Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I asked ChatGPT about the project's build.py, and I discovered that the .pxd file plays a critical role in type binding. Initially, ChatGPT said that .pxd and .pyi files are only for providing type hint support to Pylance. |
Beta Was this translation helpful? Give feedback.
I asked ChatGPT about the project's build.py, and I discovered that the .pxd file plays a critical role in type binding. Initially, ChatGPT said that .pxd and .pyi files are only for providing type hint support to Pylance.