指标约定函数

本节内容仅用于代码策略,可视化策略不涉及以下内容。

custom_indicator

接口说明

指标约定函数。在代码策略中,指标须先在此函数下注册后,方可使用。

custom_indicator()

麦语言指标:纯代码策略中,如果希望使用 get_MyLang_indicator() 获取技术指标,需要在此约定函数中调用 register_indicator 接口,把策略的麦语言脚本写到代码策略中,才能正常使用 get_MyLang_indicator()。具体操作参考 register_indicator

Python指标:纯代码策略中,如果希望使用 get_Python_indicator() 获取技术指标,需要在此约定函数中调用 register_indicator_Python 接口,把策略的Python脚本写到代码策略中,才能正常使用 get_Python_indicator()。具体操作参考 register_indicator_Python

参数

参数名类型说明默认值范围
----------

返回

返回类型: None

示例说明

在 custom_indicator() 约定函数下,注册一个名为'MA'的指标(麦语言指标)

def custom_indicator(self):
        self.register_indicator(indicator_name='MA', script='''MA1:MA(CLOSE,P1),COLORFF8D1E;MA2:MA(CLOSE,P2),COLOR0CAEE6;''', param_list=['P1', 'P2'])

在 custom_indicator() 约定函数下,注册一个名为'MA'的指标(Python指标)

def custom_indicator(self):
        script='''
    
        indicator('MA5', '移動平均線')

        def ma(n=5):
                return close().sma(n)

        if __name__ == "__main__":
                n1 = input_parameter("n1", 5)
                plot(f"MA{n1}", ma(n1), color=Color.hex("#FF8D1E"))
                output_parameter(MA1=ma(n1))

        '''
        self.register_indicator_Python(indicator_name='MA5', script=script)

示例返回值

--