淺談程序化交易中的旗型交易策略
旗型交易策略
旗型(Flag)與三角旗型(Pennant)一直以來都是可靠的中繼型態的程序化交易策略,代表的是是主要上漲或下跌趨勢的短暫停頓。旗形走勢的型態就像一面掛在旗杆頂上的旗幟,這型態通常在急速而又大幅的市場波動中出現,股價經過一連串緊密的短期波動後,形成一個稍徽與原來趨勢呈相反方向傾斜的長方形,這就是旗形走勢。
以下提供一個國外論壇關於旗型(Flag)的程序化交易策略,可以看一下外國人如何描述旗型以及利用旗型發展程序化交易策略
INPUT:
MAXFLDUR(15), //Max Flag Duration
FLAGMIN(2.5), // Max Atr in lowest point in flag
PX(23), //Max Pole Duration.
UPT1BARS(70), // Bars for Uptrend leading to flag
POLEMIN(5.5), //Min ATR Height of the pole
LBF(50), // Min distance between flags
ATRmin(5),// Min volatility change
K(1.2), //Profit Target constant
timeexit(100), //Time exit bars
ATRLL(3),BSEMIN(5), // Stop loss below flag
ATRTRAIL(3),TRAILBARS(5), // Trailing stop parameters
BSEINACT(70),ATRINACT(4); // Inactivity exit parameter
vars:X1(0),X2(0),LRSX2(0),LRSX1(0),POLE(0),ptarget(0),BSE(0),TOP(0),BOTTOM(0),X3(0),L3(0),Y23(0),FLAGBOT(0),UPT1(0),LF(0),TARGETPER(0);
// FLAG CALCULATION
X1=HighestBar(C,MAXFLDUR)[2];//FLAG DURATION EX POLETOP
X2=X1 1; // FLAG DURATION INCLUDING POLE TOP
LF=LOWEST(C,X2);
TOP=Highest(C,X2)[2];
X2=IFF(LINEARREGSLOPE(C,X1)[1]<0 AND TOP-LF
IF X2>2 AND X2<=MAXFLDUR THEN begin //LIMITS FLAG DURATION
Y23=LOWestBar(C,PX X2); // POLE BOTTOM BAR
BOTTOM=LOWEST(C,(PX X2));// POLE BOTTOM
POLE=TOP-BOTTOM;
IF TOP-BOTTOM>POLEMIN*AvgTrueRange(40) AND Y23>X2
THEN BEGIN
TOP=Highest(C,X2)[2];
FLAGBOT=LOWEST(C,X2);
UPT1=BOTTOM-LOWEST(L,UPT1BARS); // UPTREND LEADING TO FLAG
LRSX1=LINEARREGSLOPE(C,X1)*100;//SLOPE IN FLAG
LRSX2=LINEARREGSLOPE(C,X1-1)[2]*100; //SLOPE IN FLAG BEFORE BREAKOUT
Condition1 =TOP-LF<0 OR LRSX2<0); // LIMITS FLAG SLOPE BETWEEN 0 AND -3 ATR
Condition2=POLE>POLEMIN*AvgTrueRange(40) ; // LIMITS MINPOLE HEIGHT
Condition3= UPT1>0; // UPTREND LEADING TO FLAG
Condition4=(barssinceexit(1)=0 or barssinceexit(1)>LBF) ; // LIMITS DISTANCE BETWEEN SUCCESIVE FLAGS
Condition5= (AvgTrueRange(40)/AvgTrueRange(40)[Y23]-1)*100>ATRmin; // VOLATILITY
If MARKETPOSITION=0 AND CONDITION1 AND CONDITION2 AND CONDITION3 and condition4 and condition5
THEN BEGIN
Buy("Flag") NEXT BAR AT HIGHEST(C,X1) STOP;
END;END;END;
{EXIT CONDITIONS}
if MARKETPOSITION =1 THEN BEGIN
BSE=BARSSINCEENTRY;
X3=HighestBar(C,MAXFLDUR)[BSE 2]-BSE 1;
TOP=Highest(C,X3)[BSE 1];
BOTTOM=LOWEST(C,(PX X3))[BSE 1];
POLE=(TOP-BOTTOM)/(BOTTOM .0001)*100;
targetPER=K*POLE;
ptarget=(1 TARGETPER/100)*ENTRYPRICE;
L3=LOWEST(L,X3)[BSE];
// PROFIT TARGET
If C>=ptarget then SELL ("pTARGET") THIS bar at CLOSE;
// STOP
IF BSE>BSEMIN THEN SELL ("UNDER FLAG") NEXT bar at L3-ATRLL*AvgTrueRange(40) STOP;
//TRAILING STOP
IF C
THEN SELL("TRAIL") NEXT BAR AT MARKET;
// INACTIVITY EXIT
IF BSE>BSEINACT AND C
// TIME EXIT
If BSE>timeexit
then SELL("TIME") next bar at open;
END;
以下為台指期(TXF1-15K)回測
以下為德國DAX指數(DAX-15K)回測
後記:型態似乎很難用簡單的方式完整描述。例如常見的M頭及W底,到底要往前追溯幾根K線才比較好呢? 參數要設定多少較佳?程序化交易碼寫得長,島狀過度最佳化的疑慮就會出現。
文章來源: 程序化交易者-最專業的量化投資,高頻交易,程序化交易,系統交易網站
推薦閱讀:
※程序化交易的難點在哪裡
※程序化做趨勢跟蹤的成功率會更高嗎?
※暴利回報的商業EA能用嗎?
TAG:程序化交易 |