您現在的位置:程序化交易>> 期貨公式>> 交易開拓者(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是天數。


    在橫盤的市場中這個過程選擇了非常慢的趨勢,而在高度趨勢化的周期中加速至非??斓内厔荩ǖ皇?00%)。這個平滑系數是:


    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  有需要幫忙請點擊這里留言!??!進行 有償 編寫!不貴!點擊查看價格!


【字體: 】【打印文章】【查看評論

相關文章

    沒有相關內容
主站蜘蛛池模板: 你懂的视频网站| 国产男女爽爽爽免费视频| 中文字幕在线一区| 最好看的最新中文字幕2018免费视频| 亚洲精品无码高潮喷水在线| 精品国产日韩久久亚洲| 国产一级淫片a| 黄在线观看在线播放720p| 国产精品天干天干综合网| 99在线精品视频| 思思99热在线观看精品| 久久99精品国产麻豆宅宅| 日韩在线观看一区二区三区| 亚洲中文字幕在线无码一区二区 | 在线看免费毛片| 一区二区三区在线观看视频| 攵女yin乱合集小丹| 久久亚洲成a人片| 日韩中文字幕在线| 久久综合国产乱子伦精品免费 | 国产亚洲欧美日韩亚洲中文色| 国产高清精品入口91| 国产精品久久久久三级| 91东航翘臀女神在线播放| 在线天堂中文在线资源网| a级在线免费观看| 女人是男人的未来视频| 一本一本久久a久久综合精品蜜桃| 成年免费a级毛片| 中文字幕日韩人妻不卡一区| 日本三区精品三级在线电影| 久久毛片免费看一区二区三区| 最近韩国免费观看hd电影国语| 亚洲人成色77777在线观看 | 国产凌凌漆国语| 香港aa三级久久三级不卡| 国产女人高潮视频在线观看| 992tv成人影院| 国产成a人片在线观看视频下载| 一级黄色香蕉视频| 男男同志chinese中年壮汉|