2013年8月3日 星期六

●一個未完成程式碼 by Eagle

     我曾PO了一個未完成的程式碼,有熱心的讀者幫大家簡單測試及修改,經過同意,特別貼上來與大家分享,可供程式交易初學者學習程式碼使用。
===========原文內容==========

Hi Wen大

     我把 tomorrow 改 Next bar 以100 分線回測3000日 只有 2007/6/1 ~2010/03 表現較好 , 其它績效曲線約是 5~10度向上的普通水平線。接觸程式約一年 , 還是菜鳥 ,Wen大的文章都會拿來練習 , 受用不少 !!
     內文的加碼也可以使用的,獲利會提昇1.7倍,但MDD增一倍,出場方式還需多調整原始程式回測 3000日 --- 日線交易次數過低 < 50 次 , 30分線以下超過 1000 次,從進出點位觀察,此程式應用在趨勢盤是不錯的 ,盤整盤一樣容易被雙巴 !!


Eagle




原文程式碼 100 K線 TS2000i



inputs: Ceil(40),Flr(10),DeltaBar(50),initVarA(90) ;

{Additional input}
inputs:TStop1(0),StopB1(999),StopV1(0),TStop2(0),StopB2(999),StopV2(0),TStop3(0),StopB3(999),TStop4(0),StopV4(0);
inputs:TAdd3(0),AddB3(999),Alpha3(0),Beta3(0),TAdd4(0),AddV4(0),Alpha4(0),Beta4(0) ;


vars: X(0),Y(0),ZDelta(0),VarA(0),VarB(0),OldVarA(0),MP(0),OpLoss(0),OpPro(0),BottDay(0),PeakDay(0);


{Additional Variables}
Vars:Trigger(0),MaxReg(0) ,isBalanceDay(False);

Y=X;
X = Stddev(Close,DeltaBar) ;

if X <> 0 then ZDelta =(X-Y)/X else ZDelta = 0 ;

if CurrentBar = 1 then VarA = initVarA ;


OldVarA = VarA ;

VarA = OldVarA*(1+ZDelta) ;

VarA = MaxList(VarA,Flr) ;

VarA = MinList(VarA,Ceil) ;

VarB = VarA * 0.5 ;



Buy ("Go Long") next bar at Highest(High,VarA) stop ;

Sell ("Go Short") next bar at Lowest(Low,VarA) stop ;



ExitLong ("Exit Long") next bar at Lowest(Low,VarB) stop ;

ExitShort("Exit Short") next bar at Highest(High,VarB) stop ;



{Additional Trading}



{if BigPointValue <> 0 and EntryPrice <> 0 then Begin}

Trigger = iff((BigPointValue = 0 or EntryPrice = 0),0,(PositionProfit/BigPointValue)*100/EntryPrice) ;

MaxReg = iff((BigPointValue = 0 or EntryPrice =0),0,(MaxPositionProfit/BigPointValue)*100/EntryPrice) ;

{end;}



if TStop1 = 1 then Begin

if BarsSinceEntry >= StopB1 and Trigger < StopV1 then Begin

if MarketPosition = 1 then ExitLong ( "Stop Long1") next bar at Open Stop;

if MarketPosition = -1 then ExitShort ( "Stop Short1") next bar at Open Stop;

end;

end;

if TStop2 = 1 then Begin

if BarsSinceEntry >= StopB2 and Trigger < StopV2 then Begin

if MarketPosition = 1 then ExitLong ( "Stop Long2") next bar at Open Stop;

if MarketPosition = -1 then ExitShort ( "Stop Short2") next bar at Open Stop;

end;

end;

if TAdd3 = 1 then Begin

if BarsSinceEntry >= AddB3 and Trigger Cross over (Alpha3 + Beta3*BarsSinceEntry) then Begin

if MarketPosition = 1 then Buy ( "Add Long3") next bar at Open Stop;

if MarketPosition = -1 then Sell ("Add Short3") next bar at Open Stop;

end;

end;



if TStop3 = 1 then Begin

if BarsSinceEntry >= StopB3 and Trigger Cross under (Alpha3 + Beta3*BarsSinceEntry) then Begin

if MarketPosition = 1 then ExitLong ( "Stop Long3") next bar at Open Stop;

if MarketPosition = -1 then ExitShort ( "Stop Short3") next bar at Open Stop;

end;

end;



if TAdd4 = 1 then Begin

if MaxReg >= AddV4 and Trigger Cross over (Alpha4 + Beta4*MaxReg) then Begin

if MarketPosition = 1 then Buy ( "Add Long4") next bar at Open Stop;

if MarketPosition = -1 then Sell ("Add Short4") next bar at Open Stop;

end;

end;



if TStop4 = 1 then Begin

if MaxReg >= StopV4 and Trigger Cross under (Alpha4 + Beta4*MaxReg) then Begin

if MarketPosition = 1 then ExitLong ( "Stop Long4") next bar at Open Stop;

if MarketPosition = -1 then ExitShort ( "Stop Short4") next bar at Open Stop;

end;

end;



{End additional Trading}



MP = MarketPosition ;

OpLoss = MaxPositionLoss ;

OpPro = MaxPositionProfit ;



if OpLoss < OpLoss[1] and MP <> 0 then BottDay = BarsSinceEntry ;

if OpPro > OpPro[1] and MP <> 0 then PeakDay = BarsSinceEntry ;

0 留言:

張貼留言

如果有私人問題想請教,請透過網站右方『與站長聯絡』之表單,謝謝!

----------------------------------------------------------------------------------------------------
網站聲明(Disclaimer)
本教學網站內所提供之程式碼(包括函數、指標、訊號)屬開放程式碼,用意在於讓使用者學習程式語法之撰寫,使用者可以任意修改語法內容並調整參數。本網站所有之內容(包括文章、影片、歷史紀錄、程式碼、教材)限用於個人學習使用,請勿轉寄、濫用,嚴禁私自串接帳戶交易。
-------------------------------------------------------------------------------------------------