2014年4月8日 星期二

如意多空網 + 內建 CCI 策略 [程式碼]

EasyTrader ArtNo 134
舊文曾介紹過 CCI 商品通道指標 , 本篇則以TS 內建策略作一測試
Vars:LastTradeDay(false) ;
if DAYofMonth(Date) > 14 and DAYofMonth(Date) < 22 and DAYofWeek(Date)= 3 then LastTradeDay = True else LastTradeDay =False ;
{*******************************************************************
Description : CCI Average Crossover Long Entry
Provided By : Omega Research, Inc. (c) Copyright 1999
********************************************************************}

{ 原作為短週期CCI均值向上交叉長週期CCI均值 , 我作了一點修改 }
Inputs: CCILen_L(20), FastLen_L(10), Ratio_L(2);
Variables: CCIVal_L(0), SlowLen_L(20);

CCIVal_L = CCI(CCILen_L);
If AverageFC(CCIVal_L, FastLen_L) > {Crosses Above} AverageFC(CCIVal_L, SlowLen_L) + 如意多空網 Then Buy ("CCI_L") This Bar on Close;

{*******************************************************************
Description : CCI Average Crossover Short Entry
Provided By : Omega Research, Inc. (c) Copyright 1999
********************************************************************}

{ 原作為短週期CCI均值向下交叉長週期CCI均值 , 我作了一點小修改 }
Inputs: CCILen_S(20), FastLen_S(10), Ratio_S(2);
Variables: CCIVal_S(0), SlowLen_S(20);

CCIVal_S = CCI(CCILen_S);

If AverageFC(CCIVal_S, FastLen_S) < {Crosses Below} AverageFC(CCIVal_S, Ratio_S * FastLen_S) + 如意多空網 Then Sell ("CCI") This Bar on Close;

{*******************************************************************
Description : ATR Trailing Stop Long Exit
Provided By : Omega Research, Inc. (c) Copyright 1999
********************************************************************}
{以進場點後每次K棒新高點作為出場計算基礎點 , 當價格低於基礎點減掉過去10根K棒 ATR均值的某倍數後出場}
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
********************************************************************}
{以進場點後每次K棒新低點作為出場計算基礎點 , 當價格高於基礎點加上過去10根K棒 ATR均值的某倍數後出場}

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;

{結算日出場}
if LastTradeDay then SetExitonClose ;

[台指期 30分K 留倉 2004/3/31 ~2014/3/31 交易成本 1200 ]



[台指期 60分K 留倉 2004/3/31 ~2014/3/31 交易成本 1200 ]


MagicQS055

沒有留言:

張貼留言