電子信箱 service [at] bituzi.com
幣圖誌首頁 facebook粉絲團 google plus google plus


開發商品的交易系統 - 基礎篇 [9]



在交易系統設計的領域中,通道是常常被拿來使用的觀念之一。好幾篇舊文也是採用很有名的Bollinger Band 通道的觀念所設計出來的系統。本文介紹的肯特納通道(KC)是Chester Keltner在1960年提出的觀念,是在移動平均線上加減Average True Range,形成上下通道。一般情況下是以上通道線及下通道線的分界作為買賣的最大可能性。若股價於邊界出現不尋常的波動,即表示買賣機會,也就是要在價格突破上通道的時候做多,跌破下通道的時候做空。

肯特納通道是基於平均真實波幅原理而形成的指標,對價格波動反應靈敏,它可以取代布林線或百分比通道作為判斷的工具。肯特納通道是由兩根圍繞線性加權移動平均線波動的環帶組成的,其中線性加權均線的參數通道是20。

肯特納通道說明

如同於所有的包絡線或環帶狀系統,價格傾向於在環帶內運動,當價格突破環帶時,通常意味著會產生做多或做空的機會。當價格報收在頂部環帶之上時,通常意味著向上動能的突破,其後價格會繼續走高。當價格報收在底部環帶之下時,則預期價格會走低。

基於平均真實波幅的肯特納通道運算公式如下:
UpKC = Average(Close, 20) + AvgTrueRange(20) * 2;
DnKC = Average(Close, 20) - AvgTrueRange(20) * 2;

在一個上漲的趨勢裡,中線或20週期移動平均線,對價格能夠產生支撐作用,相反,下跌的趨勢裡,中線會壓制價格上行。和所有的趨勢追隨系統一樣,肯特納通道在上漲和下跌趨勢裏表現出色,在盤整市內則有所遜色。



在[Building Winning Trading Systems with TradeStation]這本書裡介紹了這個系統
原始程式碼及商品測試報告如下

{King Keltner by George Pruitt—based on trading system presented by Chester Keltner}
Inputs: avgLength(40), atrLength(40);
Vars: upBand(0),dnBand(0),liquidPoint(0),movAvgVal(0);
movAvgVal = Average((High + Low + Close)/3,avgLength);
upBand = movAvgVal + AvgTrueRange(atrLength);
dnBand = movAvgVal - AvgTrueRange(atrLength);

if(movAvgVal > movAvgVal[1]) then Buy ("KKBuy") tomorrow at upBand stop;
if(movAvgVal < movAvgVal[1]) then Sell Short("KKSell") tomorrow at dnBand stop;
liquidPoint = movAvgVal;

If(MarketPosition = 1) then Sell tomorrow at liquidPoint stop;
If(MarketPosition = -1) then Buy To Cover tomorrow at liquidPoint stop;

而這個系統在 1982-2002年這20年的績效表現列出在下面這個表。



在書中內容最後也提到了可以嘗試將多空方向的參數分開測試,
因此我應用隨機參數的方法來達到此一目的


系統參數與變數宣告 input:ExitType(6) ,NBarL(2),NBarS(2),TradeProfit(0.045), TradeStopLoss(0.039),ATRs_L(5.4),ATRs_S(10.9); inputs: AvgL(40),AvgS(40),ATRBarL(40),ATRBarS(40),ATRFracL(2),ATRFracS(2);
Vars: upBand(0),dnBand(0),movAvgL(0),movAvgS(0);
vars: IsBalanceDay(False),MP(0),PF(0),PL(0);

MP = MarketPosition ;

if DAYofMonth(Date) > 14 and DAYofMonth(Date) < 22 and DAYofWeek(Date)= 3 then isBalanceDay = True else isBalanceDay =False ;

PF = AvgPrice*TradeProfit ;
PL = AvgPrice*TradeStopLoss ;

進場準備 多空均線計算
movAvgL = Average(TypicalPrice,AvgL);
movAvgS = Average(TypicalPrice,AvgS);

上通道使用多方均線當基準
upBand = movAvgL + ATRFracL * AvgTrueRange(ATRBarL);
下通道使用空方均線當基準
dnBand = movAvgS + ATRFracS * AvgTrueRange(ATRBarS);

if BarNumber > 1 then Begin
當前一根K棒均值 < 通道上緣,則在下一根K棒突破上緣時作多
if TypicalPrice[1] < UpBand then Buy ("KKBuy") next bar at upBand Stop;
當前一根K棒均值 > 通道上緣,則在下一根K棒跌破下緣時作空
if TypicalPrice[1] > DnBand then Sell ("KKSell") next bar at DnBand Stop;
end ;

{不同的出場方式 }
if ExitType = 6 then Begin
If MP > 0 then ExitLong next bar at DnBand-1 Stop ;
If MP < 0 then ExitShort next bar at UpBand+1 Stop ;
end;

if ExitType = 1 then SetStopLoss(PL * BigPointValue) ;
if ExitType = 2 then Begin SetStopLoss(PL * BigPointValue) ;
setProfitTarget(PF * BigPointValue) ; end;

if ExitType = 3 then Begin if MP > 0 and BarsSinceEntry = NBarL then ExitLong next bar at Market ;
if MP < 0 and BarsSinceEntry = NBarS then ExitShort next bar at Market ;
end;

if ExitType = 4 then Begin SetStopLoss(PL * BigPointValue) ; setProfitTarget(PF * BigPointValue) ;
if MP > 0 and BarsSinceEntry = NBarL then {Sell } ExitLong next bar at Market ;
if MP < 0 and BarsSinceEntry = NBarS then {Buy} ExitShort next bar at Market ;
end;

if ExitType = 5 then Begin

{*******************************************************************
Description : ATR Trailing Stop Long Exit
Provided By : Omega Research, Inc. (c) Copyright 1999 ********************************************************************}


{Inputs: ATRs_L(3);}
Variables: PosHigh(0), ATRVal_L(0);
ATRVal_L = AvgTrueRange(10) * ATRs_L;

If BarsSinceEntry = 0 Then PosHigh = High;
If MarketPosition = 1 Then Begin If High > PosHigh Then PosHigh = High;
ExitLong ("ATR") Next Bar at PosHigh - ATRVal_L Stop;
End else ExitLong ("ATR eb") Next bar at High - ATRVal_L Stop;

{*******************************************************************
Description : ATR Trailing Stop Short Exit
Provided By : Omega Research, Inc. (c) Copyright 1999
********************************************************************}
{Inputs: ATRs_S(3);}
Variables: PosLow(0), ATRVal_S(0);
ATRVal_S = AvgTrueRange(10) * ATRs_S;
If BarsSinceEntry = 0 Then PosLow = Low;

If MarketPosition = -1 Then Begin
If Low < PosLow Then PosLow = Low;
ExitShort ("ATR_1") Next Bar at PosLow + ATRVal_S Stop;
End else ExitShort ("ATR_1 eb") Next bar at Low + ATRVal_S Stop;
end;

if IsBalanceDay then setExitonClose ;
台指期 日K 多空留倉 交易週期 2004/8/31~ 2014/8/29 交易成本 1200


台指期 60 min K 多空留倉 交易週期 2004/8/31~ 2014/8/29 交易成本 1200


國外知名的簡單策略仍舊有一定的獲利能力,肯特納通道也可以和其他指標混合應用,比如說相對強弱指標(RSI)和平滑異同移動平均線(MACD),這樣可以對市場的強度進行雙重確認。

0 意見: