您現(xiàn)在的位置:程序化交易>> 期貨公式>> 交易開拓者(TB)>> 開拓者知識(shí)>>正文內(nèi)容

AMA策略 [開拓者 TB]

  • 咨詢內(nèi)容: 本帖最后由 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趨勢(shì)交易系統(tǒng)(含代碼)
    這個(gè)系統(tǒng)脫胎于卡夫曼的AMA自適應(yīng)系統(tǒng),我自己做了改進(jìn),根據(jù)我自己的習(xí)慣加了BOLL和MA30.

    以下為Perry J.Kaufman的自適應(yīng)移動(dòng)平均系統(tǒng)
    關(guān)于移動(dòng)平均
    由一個(gè)時(shí)間周期的價(jià)格平均值構(gòu)成,并以單位時(shí)間的價(jià)格周期不斷計(jì)算,加入新的一個(gè)單位時(shí)間的價(jià)格時(shí)去掉第一個(gè)單位時(shí)間的價(jià)格,并計(jì)算平均值。一個(gè)過去幾天的平均值,減少了人為的由消息引起的過激反應(yīng)的影響。平均較長(zhǎng)的數(shù)據(jù)周期,給出了較平滑的趨勢(shì),其結(jié)果經(jīng)常是長(zhǎng)期市場(chǎng)方向的一個(gè)很好的代表,也反映了市場(chǎng)運(yùn)行狀況和人們對(duì)于利率和政策的預(yù)期。


    趨勢(shì)系統(tǒng)


    趨勢(shì)計(jì)算把價(jià)格移動(dòng)歸納為一個(gè)凈方向,并假設(shè)價(jià)格將會(huì)繼續(xù)沿著這個(gè)方向運(yùn)動(dòng)。趨勢(shì)跟蹤系統(tǒng)則是對(duì)趨勢(shì)作出反應(yīng),而不是對(duì)它們進(jìn)行預(yù)期。


    噪音


    一個(gè)持續(xù)橫盤的期的波動(dòng)水平,可以很方便的用來測(cè)量?jī)?nèi)在噪音。如果一個(gè)趨勢(shì)是由一個(gè)不大于市場(chǎng)內(nèi)在噪音水平移動(dòng)所引起的,那么這個(gè)趨勢(shì)就是不可靠的。
    自適應(yīng)


    當(dāng)市場(chǎng)沿著一個(gè)方向快速移動(dòng)時(shí),快得移動(dòng)平均值是最好的。


    當(dāng)市場(chǎng)在橫盤的市場(chǎng)中立拉鋸時(shí),慢的移動(dòng)平均值是最好的。


    三種價(jià)格波動(dòng)性測(cè)量


    a. 簡(jiǎn)單地計(jì)算價(jià)格的凈變化,從開始點(diǎn)到結(jié)束點(diǎn)。這傾向于最保守的測(cè)量,因?yàn)樗交藦拈_始到結(jié)尾之間發(fā)生的任何價(jià)格移動(dòng)。


    b. 高-低范圍更好地描述了在周期內(nèi)可能產(chǎn)生的任意極端值。


    c. 所有變化總和,它是最概括的測(cè)量,因?yàn)槟茏R(shí)別一個(gè)價(jià)格移動(dòng)從高到低的次數(shù)。


    自適應(yīng)移動(dòng)平均值


    步驟1:價(jià)格方向


    價(jià)格方向被表示為整個(gè)時(shí)間段中的凈價(jià)格變化。比如,使用n天的間隔(或n小時(shí)):


    步驟2:波動(dòng)性


    波動(dòng)性是市場(chǎng)噪音的總數(shù)量,計(jì)算了時(shí)間段內(nèi)價(jià)格變化的總和


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


    步驟3:效率系數(shù)(ER)


    方向移動(dòng)對(duì)噪音之比,成為效率系數(shù)ER


    Efficiency_Ratio = direction/volatility


    步驟4:變換上述系數(shù)為趨勢(shì)速度


    為了應(yīng)用于一個(gè)指數(shù)式移動(dòng)平均值,比率將被變換為一個(gè)平滑系數(shù)c,依靠使用下面的公式,每天的均線速度可以簡(jiǎn)單地用改變平滑系數(shù)來改變,成為自適應(yīng)性的。公式:


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


    公式表明,EMA以一個(gè)百分比c來接近于今日的收盤價(jià)。系數(shù)c與一個(gè)標(biāo)準(zhǔn)移動(dòng)平均值中天數(shù)密切相關(guān),這關(guān)系是2/(n-1),其中n是天數(shù)。


    在橫盤的市場(chǎng)中這個(gè)過程選擇了非常慢的趨勢(shì),而在高度趨勢(shì)化的周期中加速至非常快的趨勢(shì)(但不是100%)。這個(gè)平滑系數(shù)是:


    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的數(shù)值趨向于0,這意味著較慢的移動(dòng)平均值將比快速的移動(dòng)平均值用得更多。這和在出現(xiàn)不確定狀況時(shí)你就更加保守是一樣的道理。


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

    卡夫曼的原代碼:
    Params
             Numeric        FilterSet(0.1);//過濾器偏移量
             Numeric        lots(1);
             Numeric        terms(10);//自適應(yīng)計(jì)算周期
             Numeric        AMAOffSetPercent(0.55);//前后兩日均線差值觸發(fā)值百分比
    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個(gè)數(shù)小于計(jì)算周期,直接返回
             AMAOffSet=AvgPrice()*AMAOffSetPercent/100;       //取當(dāng)前均價(jià)的0.0055作為均線觸發(fā)值
             filter = StandardDev(AMAValue,20,2)*FilterSet;        //計(jì)算過濾器的值
             if(AMAValue>AMAValue[1]and AMAValue[1]<AMAValue[2])
                     ExtLow = AMAValue[1];        //計(jì)算前低
             if(AMAValue<AMAValue[1]and AMAValue[1]>AMAValue[2])
                     ExtHigh = AMAValue[1];       //計(jì)算前高
          
             if(AMAValue>AMAValue[1])   //如果今天的均線值大于昨天
             {
                     if(ExtLow!=0)    //如果前低不為零
                     {
                                    if((AMAValue - ExtLow)>filter)     //將均線值減去最低值,看是否大于過濾器
                                     LongEntryCon = true;
                     }Else
                     {
                             if((AMAValue-AMAValue[1])>AMAOffSet )   //如果前低為零,即沒有產(chǎn)生前低,則直接比較兩日的均線值是否大于觸發(fā)值
                                             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技術(shù)人員: 謝謝分享!
    但這是多久前編寫的啊,居然還有nextopen的?

 

有思路,想編寫各種指標(biāo)公式,程序化交易模型,選股公式,預(yù)警公式的朋友

可聯(lián)系技術(shù)人員 QQ: 1145508240  有需要幫忙請(qǐng)點(diǎn)擊這里留言!??!進(jìn)行 有償 編寫!不貴!點(diǎn)擊查看價(jià)格!


【字體: 】【打印文章】【查看評(píng)論

相關(guān)文章

    沒有相關(guān)內(nèi)容
主站蜘蛛池模板: 国产乱人视频在线播放不卡| 在线视频www| 亚洲国产成a人v在线| 精品深夜av无码一区二区| 国产真实伦视频在线观看| bl道具play珠串震珠强迫| 日本a∨在线观看| 亚洲人成人77777网站| 男女下面无遮挡一进一出| 国产三级在线观看播放| sss欧美一区二区三区| 天天影院良辰美景好时光电视剧| 久久AV无码精品人妻出轨| 校花小雪和门卫老头阅读合集| 亚洲色大成网站www永久男同| 翁与小莹浴室欢爱51章| 国产成人无码精品一区在线观看 | 狠狠色婷婷久久一区二区三区| 国产丰满麻豆videossexhd| 2020年亚洲天天爽天天噜| 天堂va视频一区二区| 中文字幕在线视频第一页| 日韩黄色免费观看| 亚洲日本久久一区二区va| 精品无码一区在线观看| 国产交换配偶在线视频| 亚洲乱码一二三四区乱码| 国产麻豆欧美亚洲综合久久| 一本丁香综合久久久久不卡网站 | 日韩黄色一级大片| 亚洲欧美日韩久久精品第一区| 看免费的黄色片| 向日葵app下载观看免费| 青娱乐手机在线| 国产手机在线αⅴ片无码观看 | 999久久久无码国产精品| 岳一夜被你要了六次| 丰满熟女高潮毛茸茸欧洲| 日韩免费在线观看| 亚洲gv天堂gv无码男同| 欧美日韩国产成人在线观看|