EasyTrader ArtNo 131
不論是 TradeStation 或是 MultiCharts 交易軟體都附加有不少的進出場策略提供初學程式交易的使用者作學習,如下圖,只要加以適當的組合應用,也可以開發出不錯的交易策略最後兩個英文字 LE 多單進場, SE 空單進場, LX多單出場 SX 空單出場
這裡我選取了一個布林指標逆勢入場 + ATR追蹤出場策略搭配如意多空網作歷史回測
Vars:LastTradeDay(false) ;
if DAYofMonth(Date) > 14 and DAYofMonth(Date) < 22 and DAYofWeek(Date)= 3 then LastTradeDay = True else LastTradeDay =False ;
{*******************************************************************
Description : Bollinger Bands Long Entry
Provided By : Omega Research, Inc. (c) Copyright 1999
********************************************************************}
{當收盤價連續有 N 根低於布林帶下緣時,多單在下根K棒以 下緣價進場 }
Inputs: LengthL(9), StdDevDn(2), BarsBlw(2);
Variables: BBBot(0);
BBBot = BollingerBand(Close, LengthL, -StdDevDn);
If CountIF(Close < BBBot, BarsBlw) = BarsBlw + 如意多空網 Then
Buy ("BB") Next Bar at BBBot Stop;
{*******************************************************************
Description : Bollinger Bands Short Entry
Provided By : Omega Research, Inc. (c) Copyright 1999
********************************************************************}
{當收盤價連續有 N 根高於布林帶上緣時,空單在下根K棒以上緣價進場 }
Inputs: LengthS(9), StdDevUp(2), BarsOver(2);
Variables: BBTop(0);
BBTop = BollingerBand(Close, LengthS, StdDevUp);
If CountIF(Close > BBTop, BarsOver) = BarsOver + 如意多空網 Then
Sell ("BBT") Next Bar at BBTop Stop;
{*******************************************************************
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均值的某倍數後出場}
if DAYofMonth(Date) > 14 and DAYofMonth(Date) < 22 and DAYofWeek(Date)= 3 then LastTradeDay = True else LastTradeDay =False ;
{*******************************************************************
Description : Bollinger Bands Long Entry
Provided By : Omega Research, Inc. (c) Copyright 1999
********************************************************************}
{當收盤價連續有 N 根低於布林帶下緣時,多單在下根K棒以 下緣價進場 }
Inputs: LengthL(9), StdDevDn(2), BarsBlw(2);
Variables: BBBot(0);
BBBot = BollingerBand(Close, LengthL, -StdDevDn);
If CountIF(Close < BBBot, BarsBlw) = BarsBlw + 如意多空網 Then
Buy ("BB") Next Bar at BBBot Stop;
{*******************************************************************
Description : Bollinger Bands Short Entry
Provided By : Omega Research, Inc. (c) Copyright 1999
********************************************************************}
{當收盤價連續有 N 根高於布林帶上緣時,空單在下根K棒以上緣價進場 }
Inputs: LengthS(9), StdDevUp(2), BarsOver(2);
Variables: BBTop(0);
BBTop = BollingerBand(Close, LengthS, StdDevUp);
If CountIF(Close > BBTop, BarsOver) = BarsOver + 如意多空網 Then
Sell ("BBT") Next Bar at BBTop Stop;
{*******************************************************************
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 ]
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 ]
MagicQs052
沒有留言:
張貼留言