《Wen外期策略團隊》
旗型(Flag)與三角旗型(Pennant)一直以來都是可靠的中繼型態,代表的是是主要上漲或下跌趨勢的短暫停頓。旗形走勢的型態就像一面掛在旗桿頂上的旗幟,這型態通常在急速而又大幅的市場波動中出現,股價經過一連串緊密的短期波動後,形成一個稍徽與原來趨勢呈相反方向傾斜的長方形,這就是旗形走勢。
以下提供一個國外論壇關於旗型(Flag)的策略,可以看一下外國人如何描述旗型以及利用旗型發展交易策略
以下為台指期(TXF1-15K)回測
以下為德國DAX指數(DAX-15K)回測
以下提供一個國外論壇關於旗型(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<flagmin*AvgTrueRange(40),X1+1,100);
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<flagmin*AvgTrueRange(40) AND (LRSX1<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<HIGHEST(C,TRAILBARS)-ATRTRAIL*AvgTrueRange(40)
THEN SELL("TRAIL") NEXT BAR AT MARKET;
// INACTIVITY EXIT
IF BSE>BSEINACT AND C<ENTRYPRICE+ATRINACT*AvgTrueRange(40)THEN SELL("INACTIVITY") NEXT BAR AT MARKET;
// TIME EXIT
If BSE>timeexit
then SELL("TIME") next bar at open;
END;
以下為台指期(TXF1-15K)回測
以下為德國DAX指數(DAX-15K)回測
後記:
型態似乎很難用簡單的方式完整描述。例如常見的M頭及W底,到底要往前追溯幾根K線才比較好呢? 參數要設定多少較佳?程式碼寫得長,島狀過度最佳化的疑慮就會出現。
1 留言:
多謝
張貼留言
如果有私人問題想請教,請透過網站右方『與站長聯絡』之表單,謝謝!