您现在的位置:程序化交易>> 期货公式>> 金字塔等>> 其他期货软件知识>>正文内容

函数不能在IF控制语句中被引用的原理和解决方案 [金字塔]

  • 咨询内容:

    金字塔的公式系统在处于逐周期模式计算时,像例如REF,MA等带有统计性质的函数以及指标公式引用无法直接使用在IF语句之中(序列运行模式可以),因为带变量判断的IF语句会在某些周期无法调用这些统计函数而导致计算结果出现错误。解决办法是将这些函数放到IF语句之外去执行。
    目前有下列函数受此限制:

    "RET","LOD","HOD","VALUEWHEN","MD","LAST","ANY","SETVAL","FILTERX","BARSCOUNT","BARSLAST","BARSSINCE","COUNT","HHV","HHVBARS","LLV","LLVBARS",
    "MA","DMA","EMA","FILTER","REF","WMA","TMA","SMA","SUM","SUMBARS","CROSS","LONGCROSS","AVEDEV","DEVSQ","FORCAST","SLOPE","STD","STDP","VAR","VARP","SAR","BETA","COVAR","ALL",
    "BACKSET","REFX","PARTLINE","SFILTER","RELATE","ALIKE","FILLRGN","NEWHBARS","NEWLBARS","DRL","GEOMEAN","HARMEAN","KURT","SKEW","PEARSON","RSQ",
    "STEYX","INTERCEPT"

    例如:

    input:atrn1(1,1,10),atrn2(5,2,20);

    if atrn1<atrn2 and vol>20000 then
    begin
        TR1:= MAX(MAX((HIGH-LOW),ABS(REF(CLOSE,1)-HIGH)),ABS(REF(CLOSE,1)-LOW));
        ATRn_1:= MA(TR1,atrn1);
        ATRn_2:= MA(TR1,atrn2);
    end;

    上述公式语句由于将REF和MA函数放在了IF语句之中,所以该公式无法正常编译。解决办法是将他们放到IF语句之外去执行:

    input:atrn1(1,1,10),atrn2(5,2,20);

    A1:=REF(CLOSE,1);
    MA1:=MA(TR1,atrn1);
    MA2:=MA(TR1,atrn2);

    if atrn1<atrn2 and vol>20000 then
    begin
        TR1:= MAX(MAX((HIGH-LOW),ABS(A1-HIGH)),ABS(A1-LOW));
        ATRn_1:= MA1;
        ATRn_2:= MA2;
    end;

    这样经过修正的公式就可以正常编译了,此外公式还将两次REF语句引用合并到一个语句中,这样做还可以提高公式系统的运行效率,因为REF统计语句只执行了一次。

    [此贴子已经被作者于2010-11-15 20:54:19编辑过]

     

  • 金字塔客服: 以下是引用admin在2009-11-2 10:19:35的发言:

    金字塔的公式系统由于支持IF语句的变量运行,所以像例如REF,MA等带有统计性质的函数无法直接使用在IF语句之中,因为带变量判断的IF语句会在某些周期无法调用这些统计函数而导致计算结果出现错误。解决办法是将这些函数放到IF语句之外去执行。
    目前有下列函数受此限制:

    "RET","LOD","HOD","VALUEWHEN","MD","LAST","ANY","SETVAL","FILTERX","BARSCOUNT","BARSLAST","BARSSINCE","COUNT","HHV","HHVBARS","LLV","LLVBARS",
    "MA","DMA","EMA","FILTER","REF","WMA","TMA","SMA","SUM","SUMBARS","CROSS","LONGCROSS","AVEDEV","DEVSQ","FORCAST","SLOPE","STD","STDP","VAR","VARP","SAR","BETA","COVAR","ALL",
    "BACKSET","REFX","PARTLINE","SFILTER","RELATE","ALIKE","FILLRGN","NEWHBARS","NEWLBARS"

    例如:

    input:atrn1(1,1,10),atrn2(5,2,20);

    if atrn1<atrn2 and vol>20000 then
    begin
        TR1:= MAX(MAX((HIGH-LOW),ABS(REF(CLOSE,1)-HIGH)),ABS(REF(CLOSE,1)-LOW));
        ATRn_1:= MA(TR1,atrn1);
        ATRn_2:= MA(TR1,atrn2);
    end;

    上述公式语句由于将REF和MA函数放在了IF语句之中,所以该公式无法正常编译。解决办法是将他们放到IF语句之外去执行:

    input:atrn1(1,1,10),atrn2(5,2,20);

    A1:=REF(CLOSE,1);
    MA1:=MA(atrn1,atrn1);
    MA2:=MA(atrn2,atrn2);

    if atrn1<atrn2 and vol>20000 then
    begin
        TR1:= MAX(MAX((HIGH-LOW),ABS(A1-HIGH)),ABS(A1-LOW));
        ATRn_1:= MA1;
        ATRn_2:= MA2;
    end;

    这样经过修正的公式就可以正常编译了,此外公式还将两次REF语句引用合并到一个语句中,这样做还可以提高公式系统的运行效率,因为REF统计语句只执行了一次。

    [此贴子已经被作者于2009-11-2 10:22:11编辑过]

    input:atrn1(1,1,10),atrn2(5,2,20);

    A1:=REF(CLOSE,1);
    MA1:=MA(atrn1,atrn1);
    MA2:=MA(atrn2,atrn2);

    if atrn1<atrn2 and vol>20000 then
    begin
        TR1:= MAX(MAX((HIGH-LOW),ABS(A1-HIGH)),ABS(A1-LOW));
        ATRn_1:= MA1;
        ATRn_2:= MA2;
    end;
    这红色的语句有问题吧

     

  • 用户回复:

    呵呵呵,你好眼力,是笔误。自己看帮助就知道了。。。。。

     

  • 网友回复:

    还有一处好象有问题!

    input:atrn1(1,1,10),atrn2(5,2,20);

    A1:=REF(CLOSE,1);
    MA1:=MA(tr1,atrn1);  //语句顺序错了!这样tr1会提示没有定义的!应直接把TR1:= MAX(MAX((HIGH-LOW),ABS(A1-HIGH)),ABS(A1-LOW));也放在IF语句外面,并在MA1前面!
    MA2:=MA(tr1,atrn2);

    if atrn1<atrn2 and vol>20000 then
    begin
        TR1:= MAX(MAX((HIGH-LOW),ABS(A1-HIGH)),ABS(A1-LOW));
        ATRn_1:= MA1;
        ATRn_2:= MA2;
    end;

    [此贴子已经被作者于2010-5-22 11:02:21编辑过]

     

  • 网友回复:

 

有思路,想编写各种指标公式,程序化交易模型,选股公式,预警公式的朋友

可联系技术人员 QQ: 262069696  点击在线交流进行 有偿 编写!不贵!点击查看价格!

 


【字体: 】【打印文章】【查看评论

相关文章

    指定的模型还没有相关内容!