hgy等高手请进,希望帮助我完成这个指标

Discussion in 'AmiBroker' started by xiyun, Aug 8, 2009.

  1. 希望将下列kdj指标的1小时图形在5分钟图表中同步显示出来,请问应该如何实现,我自己写的系统默认是空值。希望前辈高手帮助改写一下,给个示范。非常感谢

    SetChartOptions(0,0,chartGrid20|chartGrid50|chartGrid80);

    function StochRaw(nLength, nSmoothing)
    {
    Hh = HHV(High, nLength);
    Ll = LLV(Low, nLength);
    Hh = HHV(High, nLength);
    Ll = LLV(Low, nLength);
    return ((Close - ll) / (hh - ll)) * 100;
    }

    function PreferStochK(nLength, nSmoothing)
    {
    percentK =StochRaw(nLength, nSmoothing);

    MAVt[0]=0;
    for(i=1; i<BarCount; i++)
    MAVt = MAVt[i-1] + (percentK - MAVt[i-1]) / nSmoothing;
    return MAVt;
    }

    function PreferStochD(nLength, nSmoothing, nSmoothings)
    {
    percentK = PreferStochK(nLength, nSmoothing);
    MAVt[0] = 0;
    for(i=1; i<BarCount; i++)
    MAVt = MAVt[i-1] + (percentK - MAVt[i-1]) / nSmoothings;
    return MAVt;

    }

    Period = Param("Period", 8, 3, 200);
    Ksmooth = Param("%K Smooth", 3, 3, 200);
    Dsmooth = Param("%D Smooth", 3, 3, 200);
    Upper = Param("%Upper Level", 80, 0, 100);
    Lower = Param("%Lower Level", 20, 0, 100);


    //Plot( PreferStochK(Period, Ksmooth), "percentK", colorBlue);
    //Plot( PreferStochD(Period, Ksmooth, Dsmooth), "percentD", colorRed);

    K = PreferStochK(Period, Ksmooth);
    D = PreferStochD(Period, Ksmooth, Dsmooth);
    J = 3 * PreferStochK(Period, Ksmooth) - 2 * PreferStochD(Period, Ksmooth, Dsmooth);

    Plot(K, "Stochastic %K", ParamColor("%K color", colorGreen ), ParamStyle("%K style"));
    Plot(D, "%D", ParamColor("%D color", colorBlue ), ParamStyle("%D style"));
    Plot(J, "%J", ParamColor("%J color", colorRed ), ParamStyle("%J style"));
    Plot(Upper, "", ParamColor("Upper color", colorBlack ), ParamStyle("Upper style"));
    Plot(Lower, "", ParamColor("Lower color", colorBlack ), ParamStyle("Lower style"));
    _SECTION_END();

    TimeFrameSet(inHourly);
    K_H=TimeFrameExpand(PreferStochK(8, 3),inHourly);
    D_H=TimeFrameExpand(PreferStochD(8, 3, 3),inHourly);
    J_H=3 * K_H - 2 * D_H ;
    TimeFrameRestore();

    Plot( TimeFrameExpand( D_H, inHourly,expandFirst), "D_H", colorPink,styleThick );
    Plot( TimeFrameExpand( J_H, inHourly,expandFirst), "J_H", colorSkyblue,styleThick );
    _SECTION_END();
     
  2. SetChartOptions(0,0,chartGrid20|chartGrid50|chartGrid80);

    hrscount=LastValue(BarIndex())/(3600/Interval());
    fb=BarCount-hrscount; //find the first index of bar under hourly interval.

    function StochRaw(nLength, nSmoothing)
    {
    Hh = HHV(High, nLength);
    Ll = LLV(Low, nLength);
    return ((Close - ll) / (hh - ll)) * 100;
    }

    function PreferStochK(nLength, nSmoothing)
    {
    percentK =StochRaw(nLength, nSmoothing);

    MAVt[0]=0;

    //use fb instead of value 1,to avoid indexing the empty //value, but some bars will be ignored under interval shorter //than hourly. You could remedy this by adding one extra //value to the function. As:
    //function PreferStochK(nLength, nSmoothing, baridx)
    //anyway there is another quick fix.

    for(i=fb; i<BarCount; i++)
    MAVt = MAVt[i-1] + (percentK - MAVt[i-1]) / nSmoothing;
    return MAVt;
    }

    function PreferStochD(nLength, nSmoothing, nSmoothings)
    {
    percentK = PreferStochK(nLength, nSmoothing);
    MAVt[0] = 0;
    for(i=fb; i<BarCount; i++)//use fb instead of value 1,to avoid indexing the empty value
    MAVt = MAVt[i-1] + (percentK - MAVt[i-1]) / nSmoothings;
    return MAVt;
    }

    Period = Param("Period", 8, 3, 200);
    Ksmooth = Param("%K Smooth", 3, 3, 200);
    Dsmooth = Param("%D Smooth", 3, 3, 200);
    Upper = Param("%Upper Level", 80, 0, 100);
    Lower = Param("%Lower Level", 20, 0, 100);


    //Plot( PreferStochK(Period, Ksmooth), "percentK", colorBlue);
    //Plot( PreferStochD(Period, Ksmooth, Dsmooth), "percentD", colorRed);

    K = PreferStochK(Period, Ksmooth);
    D = PreferStochD(Period, Ksmooth, Dsmooth);
    J = 3 * PreferStochK(Period, Ksmooth) - 2 * PreferStochD(Period, Ksmooth, Dsmooth);

    Plot(K, "Stochastic %K", ParamColor("%K color", colorGreen ), ParamStyle("%K style"));
    Plot(D, "%D", ParamColor("%D color", colorBlue ), ParamStyle("%D style"));
    Plot(J, "%J", ParamColor("%J color", colorRed ), ParamStyle("%J style"));
    Plot(Upper, "", ParamColor("Upper color", colorBlack ), ParamStyle("Upper style"));
    Plot(Lower, "", ParamColor("Lower color", colorBlack ), ParamStyle("Lower style"));
    _SECTION_END();

    TimeFrameSet(inHourly);
    K_H=PreferStochK(8, 3);
    D_H=PreferStochD(8, 3, 3);
    J_H=3 * K_H - 2 * D_H ;
    TimeFrameRestore();

    Plot( TimeFrameExpand( D_H, inHourly,expandFirst), "D_H", colorPink,styleThick );
    Plot( TimeFrameExpand( J_H, inHourly,expandFirst), "J_H", colorSkyblue,styleThick );
    _SECTION_END();

    试试看
     
  3. SetChartOptions(0,0,chartGrid20|chartGrid50|chartGrid80);

    hrscount=LastValue(BarIndex())/(3600/Interval());
    fb=BarCount-hrscount;

    function StochRaw(nLength, nSmoothing)
    {
    Hh = HHV(High, nLength);
    Ll = LLV(Low, nLength);
    return Nz(((Close - ll) / (hh - ll)) * 100);
    //use NZ function ensure the null values all have been //convert to 0;
    }

    function PreferStochK(nLength, nSmoothing)
    {
    percentK =StochRaw(nLength, nSmoothing);

    MAVt[0]=0;
    for(i=1; i<BarCount; i++)
    MAVt = MAVt[i-1] + (percentK - MAVt[i-1]) / nSmoothing;
    return MAVt;
    }

    function PreferStochD(nLength, nSmoothing, nSmoothings)
    {
    percentK = PreferStochK(nLength, nSmoothing);
    MAVt[0] = 0;
    for(i=1; i<BarCount; i++)
    MAVt = MAVt[i-1] + (percentK - MAVt[i-1]) / nSmoothings;
    return MAVt;
    }

    Period = Param("Period", 8, 3, 200);
    Ksmooth = Param("%K Smooth", 3, 3, 200);
    Dsmooth = Param("%D Smooth", 3, 3, 200);
    Upper = Param("%Upper Level", 80, 0, 100);
    Lower = Param("%Lower Level", 20, 0, 100);


    //Plot( PreferStochK(Period, Ksmooth), "percentK", colorBlue);
    //Plot( PreferStochD(Period, Ksmooth, Dsmooth), "percentD", colorRed);

    K = PreferStochK(Period, Ksmooth);
    D = PreferStochD(Period, Ksmooth, Dsmooth);
    J = 3 * PreferStochK(Period, Ksmooth) - 2 * PreferStochD(Period, Ksmooth, Dsmooth);

    Plot(K, "Stochastic %K", ParamColor("%K color", colorGreen ), ParamStyle("%K style"));
    Plot(D, "%D", ParamColor("%D color", colorBlue ), ParamStyle("%D style"));
    Plot(J, "%J", ParamColor("%J color", colorRed ), ParamStyle("%J style"));
    Plot(Upper, "", ParamColor("Upper color", colorBlack ), ParamStyle("Upper style"));
    Plot(Lower, "", ParamColor("Lower color", colorBlack ), ParamStyle("Lower style"));
    _SECTION_END();

    TimeFrameSet(inHourly);
    K_H=PreferStochK(8, 3);
    D_H=PreferStochD(8, 3, 3);
    J_H=3 * K_H - 2 * D_H ;
    TimeFrameRestore();

    Plot( TimeFrameExpand( D_H, inHourly,expandFirst), "D_H", colorPink,styleThick );
    Plot( TimeFrameExpand( J_H, inHourly,expandFirst), "J_H", colorSkyblue,styleThick );
    _SECTION_END();
     
  4. hgy 你好,非常感谢你帮助我写出来这个,不过不知道是哪里计算的有问题,画出来的时线数值和时线周期里面的正常数值差距很大,我的qq:377970700,如果方便希望你尽快加我,帮助我具体分析看看是哪里出现的问题,期待回复 。
     
  5. 这个图表里面5分钟的数值是对的,时线数值不对
     
  6. 你公式后面是画出时线K和时线J,不是K和D,是否是这个原因?
    Plot( TimeFrameExpand( D_H, inHourly,expandFirst), "D_H", colorPink,styleThick );
    Plot( TimeFrameExpand( J_H, inHourly,expandFirst), "J_H", colorSkyblue,styleThick );
     
  7. 不是,我就是先比较这2个值,都不对,你这个公式里面得出来的时线J,d值和我时线周期的对应数值都不一样,不知道是什么原因。我猜是前面的循环设置有问题?
     
  8. 俺这里没问题阿
    如图:
     
  9. 用光标随选
     
  10. 只是在原来的公式中改了:
    Nz(((Close - ll) / (hh - ll)) * 100);
    NZ( ); 是把空值设为0
     
  11. 估计是xiyun的品种数据问题,如果是香港市场数据的话可能无法将5分钟和1小时的图完整对应下来,香港下午开盘时间是14:30(不是整点开盘)
     
  12. 谢谢大家,不好意思,是我搞错了。
     
  13. 请问如何在主图或者附图显示这个时线jd金叉,死叉的箭头,我在你程序下面加写了这些,主图不通过,附图不显示,不知道是为什么

    Buy=Cross(TimeFrameExpand( J_H, inHourly,expandFirst),TimeFrameExpand( D_H, inHourly,expandFirst));
    Sell=Cross(TimeFrameExpand( D_H, inHourly,expandFirst),TimeFrameExpand( J_H, inHourly,expandFirst));

    shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
    PlotShapes( shape, IIf( Buy, colorCustom6, colorCustom6 ), 0, IIf( Buy, Low, High ) );

    希望前辈再次帮助我改写一下,非常感谢
     
  14. 在主图上得将画K,D,J和K_h,D_h的plot语句去掉
    在附图:
    PlotShapes( shape, IIf( Buy, colorCustom6, colorCustom6 ), 0, IIf( Buy, Low, High ) );
    这句中的low,high要改掉,范围0-100,直接用k,d或j值也行,如:
    PlotShapes( shape, IIf( Buy, colorCustom6, colorCustom6 ), 0, IIf( Buy,k, k ) );
    另外请确认颜色colorCustom6,或换为:
    PlotShapes( shape, IIf( Buy, colorgreen, colorred ), 0, IIf( Buy,k, k ) );

    p.S.留意是否有wj2000兄提及的数据问题.
     
  15. 非常感谢hgy前辈帮助我解决了这些让我困惑难受了好几天的头疼问题,真是:“不会的难,会的不难”。目前已经实现了我需要的表达方式,数据和数值应该都是没有问题了。我再进一步核实看看。同时也非常感谢这个海洋论坛和wj2000前辈的热心指点。
     
  16. 请问是否可以在出箭头的时间,在当前页面的上或者下位置显示写汉字说明,比如:买-16530 时间-15:00,关于这个怎么写啊? 是不是writeif 还是plottext?哪一个更好,?希望前辈兄长给写个示范。我实在是不知何去何从。非常感谢
     
  17. 还有怎么表达同时出现希望是1-3次的声音报警啊?用下面这个在小时线的金叉会一直报下去,会让我崩溃了的,期待给写个例子
    if(LastValue(Buy)) Say("buy ");
    if(LastValue(Sell)) Say("sell ")
     
  18. 不支持汉字现示说明
    plottext可以直接显示,writeif好像要引用title.
    buyprice=lastvalue(close);
    buybarindex=barcount;
    PlotText("buy: "+NumToStr(BuyPrice,1.2)+" \ntime: "+NumToStr( DateTime(),formatDateTime),buybarindex,buyprice,colorred);

    按需要修改
     
  19. function Saying( text, repeat )
    {
    speak=Nz(StaticVarGet("lastspeak"));
    if( speak<=repeat )
    {
    StaticVarSet("lastspeak", speak+1 );
    Say( text );
    }
    }

    PrevBar=StaticVarGet("PB");
    CurrentBar=LastValue( BarIndex() );
    NewBar = PrevBar != CurrentBar;
    StaticVarSet("PB",CurrentBar);

    if(NewBar) StaticVarSet("lastspeak", 0 );

    Saying("freeze dont move", 2);

    大致可以,你试试看
    用saying代替say,格式
    saying(text,how many time you want repeat);


    上面newbar也可以用在自动交易上,避免重复下单
    原理一样,每逢新的bar,重设一个赋值(或字符)
     
  20. 你好,非常感谢你抽空给我写出来的示范,我抽时间再去测试那些功能,目前我发现应该出箭头信号的地方居然没有 ,有的地方出来了,有的却没有 ,是不是电脑软件计算经常也有错误 ,很简单的kdj金叉死叉语句 ,都感觉有些地方不对 ,是不是我的ami软件出现了故障? 搞的我都没有信心继续写下去了,你有qq吗?我的是377970700,希望你如果方便就加我帮助我看看到底是什么原因?头疼死我了。一直想不通到底是为什么。