hgy请进,希望你帮助我完成这个指标

Discussion in 'AmiBroker' started by xiyun, Nov 9, 2008.

  1. N = param("Range", 9, 2, 20, 1);
    M1 = param("%K Period", 3, 1, 20, 1);
    M2 = param("%D Period", 3, 1, 20, 1);

    RSV = (CLOSE - LLV(LOW, N))/(HHV(HIGH, N)- LLV(LOW, N)) * 100;
    K = EMA(RSV, M1);
    D = EMA(K, M2);
    J = 3 * K-2 * D;
    plot(J, "Stochastic %J", colorred);
    plot(D, "Stochastic %D", colorblue);
    plot(K, "Stochastic %K", colorgreen);
    plot(80, "", colorblack);
    plot(20, "", colorblack);
    _SECTION_END()
    请问如何在这个kjd指标里面加入当j大于90时想在主图出现做空向下的箭头?当j小于5时出现向上的箭头,是编辑在这个指标里面,还是编辑在主图指标里面?希望给写个示范看看。期待具体指点,我的qq:377970700。tygxy@163.com ,MSN:wypzh89@hotmail.com 非常感谢
    我增加了下面这个,说是无法编辑,我不知道该怎么办了,我把你上次写的那个编辑后出来不是我想要的效果,不知道为什么。
    Buy=( Buy, Sell );
    Sell=( Buy, Sell );

    shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
    PlotShapes( shape, IIf( Buy, colorRed ,colorGreen ), 0, IIf( Buy, J<=5, J>=90 ) );//draw the buy/sell indicator
     
  2. n=Param("Value for N",9,1,20);
    overlap=ParamToggle("Overlapping JDK","off|on",0 );
    showArrow=ParamToggle("Show Arrow","off|on",0 );
    m1=3;m2=3;
    Plot(C,"",1,64|styleNoDraw);
    RSV = (Close - LLV(Low, N))/(HHV(High, N)- LLV(Low, N)) * 100;
    K = EMA(RSV, M1);
    D = EMA(K, M2);
    J = 3 * K-2 * D;
    if(Overlap)
    {
    Plot(J, "Stochastic %J", colorRed,1|styleLeftAxisScale|styleOwnScale);
    Plot(D, "Stochastic %D", colorBlue,1|styleLeftAxisScale|styleOwnScale);
    Plot(K, "Stochastic %K", colorGreen,1|styleLeftAxisScale|styleOwnScale);
    Plot(80, "", colorBlack,1|styleLeftAxisScale);
    Plot(20, "", colorBlack,1|styleLeftAxisScale);
    }

    Buy=Cross(k,d);
    Sell=Cross(d,k);

    shape = Buy * shapeSmallUpTriangle + Sell * shapeSmallDownTriangle;
    extreme = (j>90)*shapeHollowDownTriangle + (j<20)*shapeHollowUpTriangle;
    if(showArrow)
    {
    PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High ) );//draw the buy/sell indicator
    PlotShapes( extreme, colorYellow, 0, IIf( j>90, High, Low ) );
    }
    if(LastValue(Buy)) Say("buy");
    if(LastValue(Sell)) Say("sell");

    kdcolor=IIf(j>90,colorYellow,IIf(j<20,colorRed,colorBlack));//if K greater or equal to 90,set bar color to yellow
    Plot(C,"close",kdcolor,64); //draw the candle bars
    //Plot(MA(C,10),"MA AVG",colorBlue,5);//plot the MA line

    小细节,自个对照手册改下吧
     
  3. 首先谢谢hgy给的参考例子,不打算用一个指标文件调用另一个指标文件了,那个我搞不定。
    做了个一般指标和根据指标信号在k线图上标示箭头信号的对比,想学的就自己用点功对比着看看,只想要现成的,那我也没话可说了,我下面也没时间也不会再花时间帮忙写什么指标了。
    这个写的指标有点缺陷,我也没能力解决了,凑合着用吧。
    缺陷是如果要overlay到主图上,就只能先Overlay到主图上,而且只能overlay一次,否则就要出错,而双击显示在附图上没限制。
    例子:
    原始指标,不带买卖信号箭头提示:
    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, 200);
    Lower = Param("%Lower Level", 20, 0, 200);

    //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"));



    对比的带买卖信号箭头提示:
    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, 200);
    Lower = Param("%Lower Level", 20, 0, 200);

    overlap=ParamToggle("Overlapping JD","off|on",0 );
    showArrow=ParamToggle("Show Arrow","off|on",1 );


    //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);

    if(Overlap)
    {
    //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"));
    }

    Big = Param("Big Level", 90, 0, 200);
    Small = Param("Small Level", 5, 0, 200);

    Buy=Cross(J, Small);
    Sell=Cross(Big, J);

    shape = Buy * shapeUpArrow + Sell * shapeDownArrow;

    Plot( Close, "Price", colorBlack, styleCandle );

    if(showArrow)
    {

    PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High ) );}
    上面红色部分为指标定义部分,可以用你需要的任何指标定义来取代。
    蓝色部分为显示箭头信号的主要“必须”部分。
    绿色部分是为了方便调节使用的可选项
     
    Last edited by a moderator: Nov 12, 2008
  4. 下面是对上面指标对比的一些注解:
    overlap=ParamToggle("Overlapping JD","off|on",0 ); //选择开关选项,不显示指标
    showArrow=ParamToggle("Show Arrow","off|on",1 ); //选择开关选项,显示箭头
    这2句分别定义是否显示指标和信号箭头的选择开关,我选择的默认是不显示指标,显示k线箭头信号。

    if(Overlap)
    {
    。。。。。。
    }
    是否显示指标的判断和执行语句。

    if(showArrow)
    {
    。。。。。。
    }
    是否显示箭头信号的判断和执行语句。

    Big = Param("Big Level", 90, 0, 200);
    Small = Param("Small Level", 5, 0, 200);
    此2句是定义你的信号判断参数值,用来方便调节参数而不需要修改指标文件。

    Buy=Cross(J, Small);
    Sell=Cross(Big, J);

    shape = Buy * shapeUpArrow + Sell * shapeDownArrow;
    此3句为信号判断生成条件,根据你需要的不同指标文件你可以用不同的指标名替换上面的big、small和J,
    其中Cross(J, Small)表示的是J从下向上穿越Small,如果你要表示J从上向下穿越Small,就需要更改为Cross(Small,J)。
    本例中是以J值从大于90向下穿越90时发出卖出sell箭头信号,以J值从小于5向上穿越5时发出买入箭头信号。

    Plot( Close, "Price", colorBlack, styleCandle );

    PlotShapes( shape, IIf( Buy, colorGreen, colorRed ), 0, IIf( Buy, Low, High ) );
    上面语句实现在k线上标示出信号箭头。
     
  5. 我对amibroker的指标编写体系也不熟悉,匆匆的看了些例子和帮助,上面的买卖箭头信号花了3天时间,下面也不想再花时间搞了,想用想学就自己花点时间看看,看看帮助文件和说明书。
    上面的注解也算比较详细的,如果不愿意花时间,那也就没办法了。
     
  6. wj2000兄所言极是,熟悉软件的第一步一定得狠啃手册


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

    function PreferStochKD(delta, nSmoothing)
    {
    percentK=delta;
    MAvt=0;
    MAVt[0]=0;
    for(i=1; i<BarCount; i++)
    MAVt = MAVt[i-1] + (percentK - MAVt[i-1]) / nSmoothing;
    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, 200);
    Lower = Param("%Lower Level", 20, 0, 200);

    overlap=ParamToggle("Overlapping JD","off|on",0 );
    showArrow=ParamToggle("Show Arrow","off|on",1 );

    K = PreferStochKD(StochRaw(period), Ksmooth);
    D = PreferStochKD(k, Dsmooth);
    J = 3 * k - 2 *d;//这里直接调k&d,不用再计算一次

    可以把k和d两个function合并为一,因为它们的运算一样

    if(Overlap)
    {
    ......
    Plot(Lower, "", ParamColor("Lower color", colorBlack ), ParamStyle("Lower style")|styleLeftAxisScale);
    }

    这个后面加styleLeftAxisScale防止中叠时变形
     
  7. 是,真的想用外软的话,一定得自己钻进去。

    这里下载一个指标,那里批发一个系统,修修补补,就用来交易是很危险的。因为别人可以帮你一时,但是帮不到一世。而心血来潮的系统,长期而言失败率之高千万不能轻视。