EasyTrader ArtNo 154
介紹一個LUXOR外匯交易系統,在《Trading Systems - A new approach to system development and portfolio optimisation》一書中 ,作者用一個英磅/美元的交易作例子,說明從概念到策略開發以及修正的過程,內容也介紹了一些報表的分析方式及附上作者的原始程式。
原始程式碼inputs:FastLength(5), SlowLength(30);
Vars: MP(0),Fast(0), Slow(0), GoLong(False), GoShort(False), BuyStop(0), SellStop(0),BuyLimit(0),SellLimit(0) ;
MP = MarketPosition;
Fast = Average(Close, FastLength);
Slow = Average(Close, SlowLength);
{ 定義作多/作空時機 }
GoLong = Fast > Slow;
GoShort = Fast < Slow;
{ 定義進場點位 }
If Fast crosses above Slow Then Begin
BuyStop = High + 1 point;
BuyLimit = High + 5 point ;
end ;
If Fast crosses below Slow Then Begin
SellStop = Low - 1 point;
SellLimit = Low - 5 point ;
end;
if GoLong and Close < BuyLimt then
Buy ("Long") next bar at BuyStop Stop;
If GoShort AND Close > SellLimit then
Sell ("Short") next bar at SellStop Stop;
If MP = 1 Then Begin
ExitLong next bar at Slow - 1 point Stop;
End;
If MP = -1 Then Begin
ExitShort next bar at Slow + 1 point Stop;
End;
這是一個常用的雙均線交易的系統
加滑價及手續費的前後比較
經過加濾網以及資金管理的結果[ 這個部份原文沒提供程式碼 ]
交易策略的構想到成型的結構
我在 TS論壇中看到一篇修改的版本,增加了趨勢判斷與加碼 - 分享如下
TS 內建函數 TriAverage - 以引用 K Bar數的中值作均線的平滑化
{*******************************************************************
Description : This Function returns Triangular Average
Provided By : Omega Research, Inc. (c) Copyright 1999
********************************************************************}
Inputs: Price(NumericSeries), Length(NumericSimple);
Variables: TLen(0);
TLen = Ceiling((Length + 1) * .5);
TRIAverage = Average(Average(Price, TLen), TLen);
*****************************************************************************************
程式碼 [ 黑色字是我加上的 ,藍色字是原作]
input:EntryType(1),ExitType(1), TradeProfit(0.05),TradeStopLoss(0.025),NBarL(2),NBarS(2), ATRs_L(3), ATRs_S(3),TimeEntry(1145),SecondTime(845);
vars: IsBalanceDay(False),MP(0),PF(0),PL(0);
if DAYofMonth(Date) > 14 and DAYofMonth(Date) < 22 and DAYofWeek(Date)= 3 then isBalanceDay = True else isBalanceDay =False ;
PF = AvgPrice*TradeProfit ;
PL = AvgPrice*TradeStopLoss ;
[ 原始策略碼 ]
Inputs:FastLength(5), SlowLength(30), ADXLength(12);
Vars: Fast(0), Slow(0), GoLong(False), GoShort(False), BuyStop(0), SellStop(0),
ADXValue(0), Trending(False);
MP = MarketPosition;
Fast = TriAverage(Close, FastLength);
Slow = TriAverage(Close, SlowLength);
ADXValue = ADX(ADXLength);
Trending = ADXValue > ADXValue[FastLength];
{ 定義作多/作空時機 }
GoLong = Fast > Slow;
GoShort = Fast < Slow;
{ 定義進場點位 }
If Fast crosses above Slow Then
BuyStop = High + 1 point;
If Fast crosses below Slow Then
SellStop = Low - 1 point;
{ 多單進場 }
If GoLong AND MP = 0 {and time > TimeEntry} Then
Buy ("Long") next bar at BuyStop Stop;
{ 空單進場 }
If GoShort AND MP = 0 {and time > TimeEntry}Then
Sell ("Short") next bar at SellStop Stop;
{ 定義多單平倉及加碼方式}
If MP = 1 Then Begin
ExitLong next bar at Slow - 1 point Stop;
If High < Fast AND Trending {and time > SecondTime} Then
Buy ("Longer") next bar at Fast + 1 point Stop;
End;
{ 定義空單平倉及加碼方式}
If MP = -1 Then Begin
ExitShort next bar at Slow + 1 point Stop;
If Low > Fast AND Trending {and time > SecondTime} Then
Sell ("Shorter") next bar at Fast - 1 point Stop;
End;
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 then setExitonClose ;
台指期 60分K 留倉 最近 3000個交易日 交易成本 1200
還有很多調整空間,就看自己的喜好囉 !
0 留言:
張貼留言
如果有私人問題想請教,請透過網站右方『與站長聯絡』之表單,謝謝!