当前位置:→ 公式网 > 公式解答 > 正文 

    问:请求将飞狐周MACD指标修改成大智慧指标?

    学生学浅才疏,完全不懂编写循环语句。想将南客老师写的无引用的飞狐指标  周MACD/周RSI/周KDJ  修改成大智慧所用,请求老师帮助解决!诚谢!


    三个指标的原码如下:
    {周MACD}
    input:long(26,20,100),short(12,5,40),m(9,2,60);
    wtj1:=datediff(ref(date,1),date)<>weekday-ref(weekday,1) or barpos=1;
    wtj:=refx(wtj1,1) or weekday=5;  //周末标记
    fc:=close;
    start:=barpos-barssince(wtj);
    diff:0*close;
    dea:0*close;
    tmp:=setlbound(diff,start[datacount]);
    tmp:=setlbound(dea,start[datacount]);
    d1:=fc[start[datacount]];d2:=d1;wdea:=0;
    for i=start[datacount]+1 to datacount do begin
      if wtj then begin
        d1:=(2*fc+(short-1)*d1)/(short+1);
        d2:=(2*fc+(long-1)*d2)/(long+1);
        wdiff:=d1-d2;
        wdea:=(2*wdiff+(m-1)*wdea)/(m+1);
        diff:=wdiff;
        dea:=wdea;
      end else begin
        diff:=(2*fc+(short-1)*d1)/(short+1)-
                 (2*fc+(long-1)*d2)/(long+1);
        dea:=(2*diff+(m-1)*wdea)/(m+1);
      end;
    end;
    macd:2*(diff-dea),colorstick;

    {//以下检查dea数据是否正确
    weekdea:"macd.dea#week";
    drawicon(wtj,0,10);
    tt:count(round(weekdea*100000-dea*100000)*wtj,0);//每个周末的数据是否相同进行统计,精确小数点后5位。}

    低位金叉:=CROSS(DIFF,DEA) AND DIFF<-0.1;
    STICKLINE(低位金叉,0,0.3,8,0),COLORYELLOW;
    JCCOUNT:=COUNT(CROSS(DIFF,DEA),BARSLAST(DEA>=0));
    二次金叉:=CROSS(DIFF,DEA) AND DEA<0 AND COUNT(JCCOUNT=2,21)=1;
    STICKLINE(二次金叉,0,0.2,8,0),COLORff80ff;
    DRAWICON(二次金叉,dea*0.9,1) ;
    A1:=BARSLAST(REF(CROSS(DIFF,DEA),1));
    底背离:=REF(CLOSE,A1+1)>CLOSE AND DIFF>REF(DIFF,A1+1) AND CROSS(DIFF,DEA);
    STICKLINE(底背离,0,0.1,8,0),COLORRED;
    DRAWLINE(A1=0,DEA,底背离,DEA,0),COLORRED,linethick1;
    A2:=BARSLAST(REF(CROSS(DEA,DIFF),1));
    顶背离:=REF(CLOSE,A2+1)<CLOSE AND REF(DIFF,A2+1)>DIFF AND CROSS(DEA,DIFF);
    DRAWLINE(A2=0,DEA,顶背离,DEA,0),COLORGREEN,linethick1;

     

    ====================
    {周KDJ}
    input:n(9,1,100),m1(3,2,40),m2(3,2,40);
    wtj1:=datediff(ref(date,1),date)<>weekday-ref(weekday,1) or barpos=1;
    wtj:=refx(wtj1,1);  //周末标记
    hn:=sumbars(wtj,n+1);
    n0:=lbound(hn);
    a:=setlbound(hn,1);
    nn:=if(barpos<n0,barpos,hn-1);
    RSV:=(CLOSE-LLV(LOW,nN))/(HHV(HIGH,nN)-LLV(LOW,nN))*100;
    start:=barpos-barssince(wtj);
    wk:=rsv[start[datacount]];
    k[start[datacount]]:wk;
    wd:=k[start[datacount]];
    d[start[datacount]]:wd;
    for i=start[datacount]+1 to datacount do begin
      if wtj then begin
        wk:=(rsv+(m1-1)*wk)/m1;
        wd:=(wk+(m2-1)*wd)/m2;
        k:=wk;
        d:=wd;
      end else begin
        k:=(rsv+(m1-1)*wk)/m1;
        d:=(k+(m2-1)*wd)/m2;
      end;
    end;
    j:3*k-2*d;

    {//验证代码:
    drawicon(wtj,0,10);
    zk:"kdj.k#week";
    tt:count((round(zk*1000)-round(k*1000))*wtj,0);}


    ========================================================
    {周RSI}

    input:n1(6),n2(12),n3(24);
    wtj1:=datediff(ref(date,1),date)<>weekday-ref(weekday,1) or barpos=1;
    wtj:=refx(wtj1,1);  //周末标记
    lc := ref(close,barslast(wtj1)+1);
    wcc:=barpos-sumbars(wtj,count(wtj,0)-1)+1;
    start:=wcc[datacount];
    maxc:=max(close-lc,0);
    absc:=abs(close-lc);
    r11:=maxc[start]; r12:=absc[start];
    r21:=r11; r31:=r11; r22:=r12; r32:=r12;
    zrsi1[start]:r11/r12*100;
    zrsi2[start]:r21/r22*100;
    zrsi3[start]:r31/r32*100;
    for i=start+1 to datacount do begin
      if wtj then begin
        r11:=(maxc+(n1-1)*r11)/n1;
        r12:=(absc+(n1-1)*r12)/n1;
        r21:=(maxc+(n2-1)*r21)/n2;
        r22:=(absc+(n2-1)*r22)/n2;
        r31:=(maxc+(n3-1)*r31)/n3;
        r32:=(absc+(n3-1)*r32)/n3;
        zrsi1:=r11/r12*100;
        zrsi2:=r21/r22*100;
        zrsi3:=r31/r32*100;
      end else begin
        zrsi1:=(maxc+(n1-1)*r11)/(absc+(n1-1)*r12)*100;
        zrsi2:=(maxc+(n2-1)*r21)/(absc+(n2-1)*r22)*100;
        zrsi3:=(maxc+(n3-1)*r31)/(absc+(n3-1)*r32)*100;
      end;
    end;
     

    {公式在线提供:www.gszx.com.cn}答案:

    南客老师的指标看着就让人感觉赏心悦目,理由就是南客对公式语言的理解至深。在各大公式网站上这三个指标基本都有类似的求助,没有解决的原因可能在于,都用南客在飞狐中的循环思路来解决大智慧的问题。其实,南客在指标中告诉我们的是飞狐中MACD、KDJ、RSI指标以及用到的EMA、SMA函数的写法。而在大智慧中这些有它自己的表达方式。这个,以前我写过

    {周MACD}

    INPUT:long(26,20,100),short(12,5,40),m(9,2,60);
    VARIABLE:y=0,y1=0,dea=0;
    wtj:=days1970-ref(days1970,1)<>weekday-ref(weekday,1) or barpos=1;
    zm:=barslast(wtj)+1;
    y:=(2*c+(short-1)*ref(y,zm))/(short+1);
    y1:=(2*c+(long-1)*ref(y1,zm))/(long+1);
    diff:y-y1;
    dea:(2*diff+(m-1)*ref(dea,zm))/(m+1);
    macd:2*(diff-dea),colorstick;

    {//以下检查dea数据是否正确
    weekdea:"macd.dea#week";
    drawicon(wtj,0,10);
    tt:count(FLOOR(weekdea*100000-dea*100000)*wtj,0);//每个周末的数据是否相同进行统计,精确小数点后5位。};

     

    {周RSI}

    input:n1(6),n2(12),n3(24);
    variable:y11=0,y12=0,y21=0,y22=0,y31=0,y32=0;
    REFLINE: 0, 20, 50, 80, 100;
    wtj:=days1970-ref(days1970,1)<>weekday-ref(weekday,1) or barpos=1;
    zm:=barslast(wtj)+1;
    LC:=ref(close,zm);
    y1:=max(close-LC,0);  
    y2:=abs(close-LC);
    y11:=(y1+(n1-1)*ref(y11,zm))/n1;
    y12:=(y2+(n1-1)*ref(y12,zm))/n1;
    zrsi1:y11/y12*100;
    y21:=(y1+(n2-1)*ref(y21,zm))/n2; 
    y22:=(y2+(n2-1)*ref(y22,zm))/n2;
    zrsi2:y21/y22*100;
    y31:=(y1+(n3-1)*ref(y31,zm))/n3; 
    y32:=(y2+(n3-1)*ref(y32,zm))/n3;
    zrsi3:y31/y32*100;

     


    {周KDJ}

    input:n(9,1,100),m1(3,2,40),m2(3,2,40);
    variable:k=0,d=0;
    REFLINE: 0, 20, 50, 80, 100;
    wtj1:=days1970-ref(days1970,1)<>weekday-ref(weekday,1) or barpos=1;
    zm:=barslast(wtj1)+1;
    wtj:="
    REFX@REFX"(wtj1,1);  {周末标记}
    nn:=sumbars(wtj,n+1)-1;
    RSV:=(CLOSE-LLV(LOW,nn))/(HHV(HIGH,nn)-LLV(LOW,nn))*100;
    k:if(barpos=1,rsv,(ref(k,zm)*(m1-1)+rsv)/m1);
    d:if(barpos=1,k,(ref(d,zm)*(m2-1)+k)/m2);
    j:3*k-2*d;

    {//验证代码:
    drawicon(wtj,0,10);
    zk:"kdj.k#week";
    tt:count((FLOOR(zk*1000)-FLOOR(k*1000))*wtj,0);};
    {说明:"
    REFX@REFX"引用DLL插件,需把下面附件解压放入大智慧跟目录下,  refx.rar (47.96 KB)  refx.rar (47.96 KB)

     

    互动内容:
    昵称: 验证码:验证码 

关于我们 - 联系我们 - 广告合作 - 下载声明 - 网站帮助 - 友情链接 - 网站地图 - RSS订阅 - TOP
湘ICP备09016573号-3 增值电信业务经营ICP许可证:湘B2-20210269 湘公网安备43108102000039号
Copyright © 铭网科技,All Rights Reserved.
股票公式,股票指标,股票软件,股票知识