您现在的位置:程序化交易>> 期货公式>> 交易开拓者(TB)>> 开拓者知识>>正文内容

AMA策略 [开拓者 TB]

  • 咨询内容: 本帖最后由 duck_arrow 于 2013-10-16 17:15 编辑

    Adaptive Moving Average System by Perry Kaufman


    The adaptive moving average that was discussed in the interview with Perry Kaufman in the 1998 STOCKS & COMMODITIES Bonus Issue (the article originally appeared in March 1995) is an excellent alternative to standard moving average calculations. In this month's Traders' Tips, I will present two Easy Language studies and an Easy Language system that are based on the adaptive moving average.

    The adaptive moving average calculation that is used in the studies and system in TradeStation or SuperCharts is performed primarily by a function referred to as "AMA." Another function referred to as "AMAF" is used to calculate the adaptive moving average filter. As always, the functions should be created prior to the development of the studies/system.







    Type: Function, Name: AMA
    Inputs: Period(Numeric);
    Vars: Noise(0), Signal(0), Diff(0), efRatio(0), Smooth(1), Fastest(.6667), Slowest(.0645), AdaptMA(0);
    Diff = AbsValue(Close - Close[1]);
    IF CurrentBar <= Period Then AdaptMA = Close;
    IF CurrentBar > Period Then Begin
    Signal = AbsValue(Close - Close[Period]);
    Noise = Summation(Diff, Period);
    efRatio = Signal / Noise;
    Smooth = Power(efRatio * (Fastest - Slowest) + Slowest, 2);
    AdaptMA = AdaptMA[1] + Smooth * (Close - AdaptMA[1]);
    End;
    AMA = AdaptMA;




    Type: Function, Name: AMAF
    Inputs: Period(Numeric), Pcnt(Numeric);
    Vars: Noise(0), Signal(0), Diff(0), efRatio(0), Smooth(1), Fastest(.6667), Slowest(.0645), AdaptMA(0), AMAFltr(0);
    Diff = AbsValue(Close - Close[1]);
    IF CurrentBar <= Period Then AdaptMA = Close;
    IF CurrentBar > Period Then Begin
    Signal = AbsValue(Close - Close[Period]);
    Noise = Summation(Diff, Period);
    efRatio = Signal / Noise;
    Smooth = Power(efRatio * (Fastest - Slowest) + Slowest, 2);
    AdaptMA = AdaptMA[1] + Smooth * (Close - AdaptMA[1]);
    AMAFltr = StdDev(AdaptMA-AdaptMA[1], Period) * Pcnt;
    End;
    AMAF = AMAFltr;




    The "MovAvg Adaptive Fltr" system below is based on the rules set forth for entries based on the filtered adaptive moving average calculation.

    Type: System, Name: Adaptive Moving Average Fltr System
    Inputs: Period(10), Pcnt(.15);
    Vars: AMAVal(0), AMAFVal(0), AMALs(0), AMAHs(0);
    AMAVal = AMA(Period);
    AMAFVAl = AMAF(Period, Pcnt);
    IF CurrentBar = 1 Then Begin
    AMALs = AMAVal;
    AMAHs = AMAVal;
    End Else Begin
    IF AMAVal < AMAVal[1] Then
    AMALs = AMAVal;
    IF AMAVal > AMAVal[1] Then
    AMAHs = AMAVal;
    IF AMAVal - AMALs Crosses Above AMAFVal Then
    Buy This Bar on Close;
    IF AMAHs - AMAVal Crosses Above AMAFVal Then
    Sell This Bar on Close;
    End;




    The second indicator, "Mov Avg Adaptive Fltr," takes the filtering concept and applies it to an indicator. Based on the filtered adaptive moving average (AMAF) parameters, this indicator will plot a vertical blue or red line, depending on the condition that is met. The values reflected by the vertical lines reflect the value of the AMA filter calculation. Some suggested format settings are given after the indicator code.





    Type: Indicator, Name: Adaptive Moving Average Fltr System
    Inputs: Period(10), Pcnt(.15);
    Vars: AMAVal(0), AMAFVal(0), AMALs(0), AMAHs(0);
    AMAVal = AMA(Period);
    AMAFVAl = AMAF(Period, Pcnt);
    IF CurrentBar = 1 Then Begin
    AMALs = AMAVal;
    AMAHs = AMAVal;
    End Else Begin
    IF AMAVal < AMAVal[1] Then
    AMALs = AMAVal;
    IF AMAVal > AMAVal[1] Then
    AMAHs = AMAVal;
    IF AMAVal - AMALs Crosses Above AMAFVal Then
    Buy This Bar on Close;
    IF AMAHs - AMAVal Crosses Above AMAFVal Then
    Sell This Bar on Close;
    End;

    AMA趋势交易系统(含代码)
    这个系统脱胎于卡夫曼的AMA自适应系统,我自己做了改进,根据我自己的习惯加了BOLL和MA30.

    以下为Perry J.Kaufman的自适应移动平均系统
    关于移动平均
    由一个时间周期的价格平均值构成,并以单位时间的价格周期不断计算,加入新的一个单位时间的价格时去掉第一个单位时间的价格,并计算平均值。一个过去几天的平均值,减少了人为的由消息引起的过激反应的影响。平均较长的数据周期,给出了较平滑的趋势,其结果经常是长期市场方向的一个很好的代表,也反映了市场运行状况和人们对于利率和政策的预期。


    趋势系统


    趋势计算把价格移动归纳为一个净方向,并假设价格将会继续沿着这个方向运动。趋势跟踪系统则是对趋势作出反应,而不是对它们进行预期。


    噪音


    一个持续横盘的期的波动水平,可以很方便的用来测量内在噪音。如果一个趋势是由一个不大于市场内在噪音水平移动所引起的,那么这个趋势就是不可靠的。
    自适应


    当市场沿着一个方向快速移动时,快得移动平均值是最好的。


    当市场在横盘的市场中立拉锯时,慢的移动平均值是最好的。


    三种价格波动性测量


    a. 简单地计算价格的净变化,从开始点到结束点。这倾向于最保守的测量,因为它平滑了从开始到结尾之间发生的任何价格移动。


    b. 高-低范围更好地描述了在周期内可能产生的任意极端值。


    c. 所有变化总和,它是最概括的测量,因为能识别一个价格移动从高到低的次数。


    自适应移动平均值


    步骤1:价格方向


    价格方向被表示为整个时间段中的净价格变化。比如,使用n天的间隔(或n小时):


    步骤2:波动性


    波动性是市场噪音的总数量,计算了时间段内价格变化的总和


    volatility= @ sum( @ abs(price-price[1]),n)


    步骤3:效率系数(ER)


    方向移动对噪音之比,成为效率系数ER


    Efficiency_Ratio = direction/volatility


    步骤4:变换上述系数为趋势速度


    为了应用于一个指数式移动平均值,比率将被变换为一个平滑系数c,依靠使用下面的公式,每天的均线速度可以简单地用改变平滑系数来改变,成为自适应性的。公式:


    @exp_ma=@exp_ma[1]+c*(price- @ exp_ma[1])


    公式表明,EMA以一个百分比c来接近于今日的收盘价。系数c与一个标准移动平均值中天数密切相关,这关系是2/(n-1),其中n是天数。


    在横盘的市场中这个过程选择了非常慢的趋势,而在高度趋势化的周期中加速至非常快的趋势(但不是100%)。这个平滑系数是:


    fastest =2/(N+1) =2/(2+1) =0.6667


    slowest =2/(N+1) =2/(30+1) =0.0645


    smooth =ER*(fastest-slowest)+slowest


    c=smooth*smooth


    平方平滑迫使c的数值趋向于0,这意味着较慢的移动平均值将比快速的移动平均值用得更多。这和在出现不确定状况时你就更加保守是一样的道理。


    AMA = AMA[1] + c * (price - AMA[1])

    卡夫曼的原代码:
    Params
             Numeric        FilterSet(0.1);//过滤器偏移量
             Numeric        lots(1);
             Numeric        terms(10);//自适应计算周期
             Numeric        AMAOffSetPercent(0.55);//前后两日均线差值触发值百分比
    Vars
             NumericSeries        AMAValue;
             Numeric        ExtHigh;//前高
             Numeric        ExtLow;//前低
             Numeric        filter;
             Numeric        AMAOffSet;
             Bool        LongEntryCon(false);
             Bool        ShortEntryCon(false);
    Begin
             AMAValue = AdaptiveMovAvg(close,terms,2,30);
             if(close == AMAValue)
                     return;       //如果bar个数小于计算周期,直接返回
             AMAOffSet=AvgPrice()*AMAOffSetPercent/100;       //取当前均价的0.0055作为均线触发值
             filter = StandardDev(AMAValue,20,2)*FilterSet;        //计算过滤器的值
             if(AMAValue>AMAValue[1]and AMAValue[1]<AMAValue[2])
                     ExtLow = AMAValue[1];        //计算前低
             if(AMAValue<AMAValue[1]and AMAValue[1]>AMAValue[2])
                     ExtHigh = AMAValue[1];       //计算前高
          
             if(AMAValue>AMAValue[1])   //如果今天的均线值大于昨天
             {
                     if(ExtLow!=0)    //如果前低不为零
                     {
                                    if((AMAValue - ExtLow)>filter)     //将均线值减去最低值,看是否大于过滤器
                                     LongEntryCon = true;
                     }Else
                     {
                             if((AMAValue-AMAValue[1])>AMAOffSet )   //如果前低为零,即没有产生前低,则直接比较两日的均线值是否大于触发值
                                             LongEntryCon = true;
                     }
             }
                   
             if(AMAValue<AMAValue[1])
             {
                     if(ExtHigh!=0)
                     {
                             if((AMAValue - ExtHigh)>filter)
                                     ShortEntryCon = true;
                     }Else
                     {
                             f((AMAValue[1]-AMAValue)>AMAOffSet )
                                     ShortEntryCon = true;
                     }
             }
             Commentary("AMA:"+TEXT(AMAValue));
             Commentary("filter:"+TEXT(filter));
             Commentary("ExtLow:"+TEXT(ExtLow));
             Commentary("ExtHigh:"+TEXT(ExtHigh));
             Commentary("LongCon:"+IIFString(LongEntryCon,"true","false"));
             Commentary("ShortCon:"+IIFString(ShortEntryCon,"true","false"));
             Commentary("AMAOffSet:"+text(AMAOffSet));
             if(MarketPosition !=1 and LongEntryCon)
                     buy(lots,NextOpen);
             if(MarketPosition !=-1 and ShortEntryCon)
                     SellShort(lots,NextOpen);
    end

     

  • TB技术人员: 谢谢分享!
    但这是多久前编写的啊,居然还有nextopen的?

 

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

可联系技术人员 QQ: 1145508240  有需要帮忙请点击这里留言!!!进行 有偿 编写!不贵!点击查看价格!


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

相关文章

    没有相关内容