2014年4月5日 星期六

如意多空網 + 內建區間突破策略[程式碼]

EasyTrader ArtNo 132
區間突破是一個很常見的策略元素,在TradeStation 內建的邏輯為收盤價向上突破區間高點或向下跌破區間低點作為進場依據
Vars:LastTradeDay(false) ;
if DAYofMonth(Date) > 14 and DAYofMonth(Date) < 22 and DAYofWeek(Date)= 3 then LastTradeDay = True else LastTradeDay =False ;

{*******************************************************************
Description : Channel Breakout Long Entry
Provided By : Omega Research, Inc. (c) Copyright 1999
********************************************************************}
Inputs: Price_LE(High), Length_LE(10), Consec_LE(2);

{計算收盤價連續突破前 N根 Bar高點的次數}
If CurrentBar > 1 AND CountIf(Close > HighestFC(Price_LE, Length_LE)[1], Consec_LE) = Consec_LE + 如意多空網 Then

Buy ("CBO_LE") This Bar on Close;

{*******************************************************************
Description : Channel Breakout Short Entry
Provided By : Omega Research, Inc. (c) Copyright 1999
********************************************************************}
Inputs: Price_SE(Low), Length_SE(10), Consec_SE(2);
{計算收盤價連續跌破前 N根 Bar低點的次數}
If CurrentBar > 1 AND CountIf(Close < LowestFC(Price_SE, Length_SE)[1], Consec_SE) = Consec_SE  + 如意多空網 Then

Sell ("CBO_SE") 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 ;

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

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

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

MagicQS053

沒有留言:

張貼留言