AMA策略
作者:開(kāi)拓者 TB 來(lái)源:cxh99.com 發(fā)布時(shí)間:2014年02月15日
- 咨詢內(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è)過(guò)去幾天的平均值,減少了人為的由消息引起的過(guò)激反應(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ù)橫盤(pán)的期的波動(dòng)水平,可以很方便的用來(lái)測(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)在橫盤(pán)的市場(chǎng)中立拉鋸時(shí),慢的移動(dòng)平均值是最好的。
三種價(jià)格波動(dòng)性測(cè)量
a. 簡(jiǎn)單地計(jì)算價(jià)格的凈變化,從開(kāi)始點(diǎn)到結(jié)束點(diǎn)。這傾向于最保守的測(cè)量,因?yàn)樗交藦拈_(kāi)始到結(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ù)來(lái)改變,成為自適應(yīng)性的。公式:
@exp_ma=@exp_ma[1]+c*(price- @ exp_ma[1])
公式表明,EMA以一個(gè)百分比c來(lái)接近于今日的收盤(pán)價(jià)。系數(shù)c與一個(gè)標(biāo)準(zhǔn)移動(dòng)平均值中天數(shù)密切相關(guān),這關(guān)系是2/(n-1),其中n是天數(shù)。
在橫盤(pán)的市場(chǎng)中這個(gè)過(guò)程選擇了非常慢的趨勢(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);//過(guò)濾器偏移量
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ì)算過(guò)濾器的值
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) //將均線值減去最低值,看是否大于過(guò)濾器
LongEntryCon = true;
}Else
{
if((AMAValue-AMAValue[1])>AMAOffSet ) //如果前低為零,即沒(méi)有產(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ù)人員:
謝謝分享!
但這是多久前編寫(xiě)的啊,居然還有nextopen的?