2016年2月29日 星期一

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

EasyTrader ArtNo 286
跳空在日語中叫“視窗”,英語是“gap”,又稱為價格跳空,是指價格在快速波動時產生的曲線的最低價與曲線的最高價之間有斷層。有人說“跳空”遲早會填補的,這並非是絕對的,需要從圖形上區別對待:有的跳空具有技術意義,有的則很一般,這要從跳空的部位、大小來判斷市場趨勢之強弱和真假之突破。

在股票市場上,跳空指受強烈利多或利空消息刺激,股價開始大幅度跳動。跳空通常在股價大變動的開始或結束前出現,向上跳空表明漲勢強勁,向下跳空表明跌勢驚人。跳空是明確趨勢開始的重要標誌,跳空缺口越大表明趨勢越明朗。
跳空的形態
1、普通性跳空 - 對預測趨勢無太大幫助,可以忽略它。因它是在交易量極少的情況下或是在波幅窄時所產生的。
2、突破性跳空 - 一般發生在交易量大時或重要價位被突破後或新的大波動之初。當匯率跳空口大並遠離原價位時,則顯示其真正的突破開始了,所以跳空口越大將來的波動越激烈。
3、持續性跳空 - 連續發生2次以上的反映市場以中等交易量在順利的發展。在上升(或下降)趨勢中,這些跳空在今後市場的調整時將成為支持(抵抗)區。因為此跳空群一般出現在整個趨勢的中間,所以可利用沿著該漲(或跌)的方向在未來上升(或下降)的幅度中將翻一番的規律來進行交易。
4、消耗性跳空 - 消耗性跳空也叫衰歇跳空,一般出現在趨勢的尾聲,是急速上升(或下降)的迴光返照,所以在隨後的市場將出現轉折。該跳空往往是在普通性跳空、突破性跳空出現之後,並且當被填補之時,就是趨勢將衰歇之日,這時應積極採取措施避免損失。


{系統參數與變數} 
input:EntryType(4),ExitType(2);
input:NBarL(10),NBarS(5),TradeProfit(0.045),TradeStopLoss(0.05),ATRs_L(5.7),ATRs_S(6.9);
vars:IsBalanceDay(False),MP(0),PF(0),PL(0);
input:HLen(10),LLen(10),LBar1(2),LBar2(1),SBar1(2),SBar2(1),HighBar(5),LowBar(5) ;
Vars:LongCond1(false),LongCond2(false),LongFilter(false),ShortCond1(false),ShortCond2(false),ShortFilter(false);
vars:BuySetUp1(false),BuySetUp2(false),SellSetUp1(false),SellSetUp2(false) ;
Vars:LongCond3(false),LongCond4(false),ShortCond3(false),ShortCond4(false) ;
vars:BuySetUp3(false),BuySetUp4(false),SellSetUp3(false),SellSetUp4(false) ;

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 ;

{多方不同跳空模式}
LongCond1 = Low >= Close[1] ;
LongCond2 = Low >= High[1] ;
LongCond3 = Low >= MaxList(Close[1],Open[1]) ;
LongCond4 = Low >= MinList(Close[1],Open[1]) ;

{用來確認趨勢方向的濾網}
LongFilter = High > Highest(High,HLen)[1] ;

{空方不同跳空模式}
ShortCond1 = High <= Close[1] ;
ShortCond2 = High <= Low[1] ;
ShortCond3 = High <= MaxList(Close[1],Open[1]) ;
ShortCond4 = High <= MinList(Close[1],Open[1]) ;

{用來確認趨勢方向的濾網}
ShortFilter = Low < Lowest(Low,LLen)[1] ;

{當 N根K棒內發生同類型跳空模式 N次 ,買方條件成立 }
BuySetUp1 = Countif(LongCond1,LBar1) = LBar1 ;
BuySetUp2 = Countif(LongCond2,LBar2) = LBar2 ;
BuySetUp3 = Countif(LongCond3,LBar1) = LBar1 ;
BuySetUp4 = Countif(LongCond4,LBar2) = LBar2 ;

{當 M 根K棒內發生同類型跳空模式 M次 ,賣方條件成立 }
SellSetUp1 = Countif(ShortCond1,SBar1) = SBar1 ;
SellSetUp2 = Countif(ShortCond2,SBar2) = SBar2 ;
SellSetUp3 = Countif(ShortCond3,SBar1) = SBar1 ;
SellSetUp4 = Countif(ShortCond4,SBar2) = SBar2 ;


if EntryType = 1 then begin
{ 當買方條件成立與趨勢濾網確認後進場作多 }
if MP <> 1 and BuySetUp1 and Longfilter then Buy next bar at Highest(High,HighBar) stop ;
{ 當賣方條件成立與趨勢濾網確認後進場作空 }
if MP <> -1 and SellSetUp1 and Shortfilter then Sell next bar at Lowest(Low,LowBar) stop ;
end;

if EntryType = 2 then begin
{ 當買方條件成立與趨勢濾網確認後進場作多 }
if MP <> 1 and BuySetUp2and Longfilter then Buy next bar at Highest(High,HighBar) stop ;
{ 當賣方條件成立與趨勢濾網確認後進場作空 }
if MP <> -1 and SellSetUp2 and Shortfilter then Sell next bar at Lowest(Low,LowBar) stop ;
end;

if EntryType = 3 then begin
{ 當買方條件成立與趨勢濾網確認後進場作多 }
if MP <> 1 and BuySetUp3 and Longfilter then Buy next bar at Highest(High,HighBar) stop ;
{ 當賣方條件成立與趨勢濾網確認後進場作空 }
if MP <> -1 and SellSetUp3 and Shortfilter then Sell next bar at Lowest(Low,LowBar) stop ;
end;
if EntryType = 4  then begin
{ 當買方條件成立與趨勢濾網確認後進場作多 }
if MP <> 1 and BuySetUp4 and Longfilter then Buy next bar at Highest(High,HighBar) stop ;
{ 當賣方條件成立與趨勢濾網確認後進場作空 }
if MP <> -1 and SellSetUp4 and Shortfilter then Sell next bar at Lowest(Low,LowBar) stop ;
end;

{ 出場平倉 }
if ExitType = 0 then SetProfitTarget(PF * BigPointValue) ;

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 IsBalanceDay or date = 1150224 then setExitonClose ;
台指期 30 min K 多空留倉 交易週期 2005/8/31~ 2015/8/31 交易成本 1200


結論:缺口理論常被作為趨勢開始與結束判斷的依據,本篇文章透過簡單的策略元素設計作歷史資料回測,以第四組的條件表現最好。讀者亦可以規劃不同想法測試 !
MagicQS194

2 則留言: