通过通达信主力散户公式来买卖股票策略来买卖该怎么写?

新手专区
标签: #<Tag:0x00007f4cdb022568>

(Lingking) #1

我有一个公式不知道该怎么改写后放进去,哪位大神可以帮帮忙?

VAR0:=(2*CLOSE+HIGH+LOW)/4;
VAR1:=(HHV(HIGH,24)-CLOSE)/(HHV(HIGH,24)-LLV(LOW,24))*100;
VAR2:=(CLOSE-LLV(LOW,18))/(HHV(HIGH,18)-LLV(LOW,18))*100;
B:=EMA((VAR0-LLV(LOW,26))/(HHV(HIGH,34)-LLV(LOW,26))*100,16);
主力:SMA(SMA(VAR2,2,1)+3,2,1),COLOR0000FF,LINETHICK2;
跟风:EMA(B,4),LINETHICK2,COLORWHITE;
散户:SMA(VAR1,3,1),COLORGREEN,LINETHICK2;

当 主力线 上穿 散户线, 买入 并 持有

当主力线 下跌 跟风线, 卖出


(life_dxy) #3

如果放到输入特征列表 应该是这个样子吧

ZL = ta_sma2(ta_sma2((close_0 - ts_min(low_0, 18)) / (ts_max(low_0, 18) - ts_min(low_0, 18)) * 100, 2, 1) + 3, 2, 1)
GF = ta_ema(ta_ema(((2 * close_0 + high_0 + low_0) / 4 - ts_min(low_0, 26)) / (ts_max(high_0, 34) - ts_min(low_0, 26)) * 100, 16), 4)
SH = ta_sma2((ts_max(high_0, 24) - close_0) / (ts_max(low_0, 24) - ts_min(low_0, 24)) * 100, 3, 1)




(Lingking) #4

谢谢您。

那 当 主力线 上穿 散户线, 买入 并 持有

当主力线 下跌 跟风线, 卖出

这个该放在哪个地方?如何表达?


(Lingking) #5

[2019-10-15 22:53:33.957799] ERROR: bigquant: module name: stock_ranker_train, module version: v5, trackeback: Traceback (most recent call last): 一键搜索答案

--------------------------------------------------------------------------- ValueError Traceback (most recent call last) <ipython-input-3-a1319217e468> in <module>() 179 max_bins=1023, 180 feature_fraction=1, --> 181 m_lazy_run=False 182 ) 183 ValueError: max() arg is an empty sequence


(达达) #6
克隆策略

    {"Description":"实验创建于2019/10/17","Summary":"","Graph":{"EdgesInternal":[{"DestinationInputPortId":"-9:features","SourceOutputPortId":"-4:data"},{"DestinationInputPortId":"-16:features","SourceOutputPortId":"-4:data"},{"DestinationInputPortId":"-16:input_data","SourceOutputPortId":"-9:data"},{"DestinationInputPortId":"-33:input_data","SourceOutputPortId":"-16:data"},{"DestinationInputPortId":"-9:instruments","SourceOutputPortId":"-24:data"},{"DestinationInputPortId":"-46:input_data","SourceOutputPortId":"-33:data"},{"DestinationInputPortId":"-33:features","SourceOutputPortId":"-41:data"},{"DestinationInputPortId":"-46:features","SourceOutputPortId":"-54:data"}],"ModuleNodes":[{"Id":"-4","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nVAR0=(2*close_0+high_0+low_0)/4\nVAR1=(ts_max(high_0,24)-close_0)/(ts_max(high_0,24)-ts_min(low_0,24))*100\nVAR2=(close_0-ts_min(low_0,18))/(ts_max(high_0,18)-ts_min(low_0,18))*100","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-4"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-4","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":1,"Comment":"","CommentCollapsed":true},{"Id":"-9","ModuleId":"BigQuantSpace.general_feature_extractor.general_feature_extractor-v7","ModuleParameters":[{"Name":"start_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"before_start_days","Value":"90","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"instruments","NodeId":"-9"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-9"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-9","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":2,"Comment":"","CommentCollapsed":true},{"Id":"-16","ModuleId":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v3","ModuleParameters":[{"Name":"date_col","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_col","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"drop_na","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"remove_extra_columns","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-16"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-16"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-16","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":3,"Comment":"","CommentCollapsed":true},{"Id":"-24","ModuleId":"BigQuantSpace.instruments.instruments-v2","ModuleParameters":[{"Name":"start_date","Value":"2019-01-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"end_date","Value":"2019-05-01","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"market","Value":"CN_STOCK_A","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_list","Value":"","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"max_count","Value":0,"ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"rolling_conf","NodeId":"-24"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-24","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":4,"Comment":"","CommentCollapsed":true},{"Id":"-33","ModuleId":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v3","ModuleParameters":[{"Name":"date_col","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_col","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"drop_na","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"remove_extra_columns","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-33"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-33"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-33","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":5,"Comment":"","CommentCollapsed":true},{"Id":"-41","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\nB=ta_ema((VAR0-ts_min(low_0,26))/(ts_max(high_0,34)-ts_min(low_0,26))*100,16)\nzhuli=ta_sma2(ta_sma2(VAR2,2,1)+3,2,1)\nsanhu= ta_sma2(VAR1,3,1)\n\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-41"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-41","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":6,"Comment":"","CommentCollapsed":true},{"Id":"-46","ModuleId":"BigQuantSpace.derived_feature_extractor.derived_feature_extractor-v3","ModuleParameters":[{"Name":"date_col","Value":"date","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"instrument_col","Value":"instrument","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"drop_na","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"remove_extra_columns","Value":"False","ValueType":"Literal","LinkedGlobalParameter":null},{"Name":"user_functions","Value":"{}","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"input_data","NodeId":"-46"},{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features","NodeId":"-46"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-46","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":7,"Comment":"","CommentCollapsed":true},{"Id":"-54","ModuleId":"BigQuantSpace.input_features.input_features-v1","ModuleParameters":[{"Name":"features","Value":"\n# #号开始的表示注释,注释需单独一行\n# 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征\ngenfeng=ta_ema(B,4)\n","ValueType":"Literal","LinkedGlobalParameter":null}],"InputPortsInternal":[{"DataSourceId":null,"TrainedModelId":null,"TransformModuleId":null,"Name":"features_ds","NodeId":"-54"}],"OutputPortsInternal":[{"Name":"data","NodeId":"-54","OutputType":null}],"UsePreviousResults":true,"moduleIdForCode":8,"Comment":"","CommentCollapsed":true}],"SerializedClientData":"<?xml version='1.0' encoding='utf-16'?><DataV1 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><Meta /><NodePositions><NodePosition Node='-4' Position='598,241,200,200'/><NodePosition Node='-9' Position='426,360,200,200'/><NodePosition Node='-16' Position='481,462,200,200'/><NodePosition Node='-24' Position='292,249,200,200'/><NodePosition Node='-33' Position='611,577,200,200'/><NodePosition Node='-41' Position='786,454,200,200'/><NodePosition Node='-46' Position='705,703,200,200'/><NodePosition Node='-54' Position='912,602,200,200'/></NodePositions><NodeGroups /></DataV1>"},"IsDraft":true,"ParentExperimentId":null,"WebService":{"IsWebServiceExperiment":false,"Inputs":[],"Outputs":[],"Parameters":[{"Name":"交易日期","Value":"","ParameterDefinition":{"Name":"交易日期","FriendlyName":"交易日期","DefaultValue":"","ParameterType":"String","HasDefaultValue":true,"IsOptional":true,"ParameterRules":[],"HasRules":false,"MarkupType":0,"CredentialDescriptor":null}}],"WebServiceGroupId":null,"SerializedClientData":"<?xml version='1.0' encoding='utf-16'?><DataV1 xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'><Meta /><NodePositions></NodePositions><NodeGroups /></DataV1>"},"DisableNodesUpdate":false,"Category":"user","Tags":[],"IsPartialRun":true}
    In [23]:
    # 本代码由可视化策略环境自动生成 2019年10月17日 18:09
    # 本代码单元只能在可视化模式下编辑。您也可以拷贝代码,粘贴到新建的代码单元或者策略,然后修改。
    
    
    m1 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    VAR0=(2*close_0+high_0+low_0)/4
    VAR1=(ts_max(high_0,24)-close_0)/(ts_max(high_0,24)-ts_min(low_0,24))*100
    VAR2=(close_0-ts_min(low_0,18))/(ts_max(high_0,18)-ts_min(low_0,18))*100"""
    )
    
    m4 = M.instruments.v2(
        start_date='2019-01-01',
        end_date='2019-05-01',
        market='CN_STOCK_A',
        instrument_list='',
        max_count=0
    )
    
    m2 = M.general_feature_extractor.v7(
        instruments=m4.data,
        features=m1.data,
        start_date='',
        end_date='',
        before_start_days=90
    )
    
    m3 = M.derived_feature_extractor.v3(
        input_data=m2.data,
        features=m1.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={}
    )
    
    m6 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    B=ta_ema((VAR0-ts_min(low_0,26))/(ts_max(high_0,34)-ts_min(low_0,26))*100,16)
    zhuli=ta_sma2(ta_sma2(VAR2,2,1)+3,2,1)
    sanhu= ta_sma2(VAR1,3,1)
    
    """
    )
    
    m5 = M.derived_feature_extractor.v3(
        input_data=m3.data,
        features=m6.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={}
    )
    
    m8 = M.input_features.v1(
        features="""
    # #号开始的表示注释,注释需单独一行
    # 多个特征,每行一个,可以包含基础特征和衍生特征,特征须为本平台特征
    genfeng=ta_ema(B,4)
    """
    )
    
    m7 = M.derived_feature_extractor.v3(
        input_data=m5.data,
        features=m8.data,
        date_col='date',
        instrument_col='instrument',
        drop_na=False,
        remove_extra_columns=False,
        user_functions={}
    )
    
    In [24]:
    m7.data.read_df().tail()
    
    Out[24]:
    close_0 date high_0 instrument low_0 VAR0 VAR1 VAR2 B zhuli sanhu genfeng
    492480 13.764368 2019-04-30 13.895145 603993.SHA 13.470118 13.723500 91.818170 8.181830 27.911192 10.738984 89.984543 32.647850
    492481 12.270498 2019-04-30 12.593002 603996.SHA 12.101568 12.308892 97.317081 2.682919 22.593843 7.503916 94.447517 26.934935
    492482 15.138978 2019-04-30 15.374299 603997.SHA 13.899621 14.887969 73.927386 26.072614 52.936386 20.247253 73.360039 60.189411
    492483 39.380741 2019-04-30 40.521641 603998.SHA 38.711937 39.498765 56.284762 31.621618 69.375977 46.915943 48.575733 74.157715
    492484 14.832354 2019-04-30 14.905419 603999.SHA 14.515735 14.771465 89.570548 10.429452 41.073967 15.292889 83.007256 47.563122

    (Lingking) #7

    老大,谢谢写这个。不过,我不懂唉。
    我把你这个复制了形成新的测量,但是他只会生成这个表,不能测试过去的股票成绩。
    我需要添加什么吗?


    (达达) #9

    需要自己定义买卖逻辑,可以参考模板里那些海龟策略/双均线策略等回测模块的写法