close

TSTS星人在聚財網曾發佈一篇很不錯的程式教學文.
建議對程式交易有興趣的人一定要去看看.
網址 : EasyLanguage懶人包_CDP當沖實例講解.

我把原程式改為 TS8 的 programming code, 方便我做回測, 程式碼如下 :

input : stoploss(0.01),LengthL(30),LengthS(30);
variables : cdp(0),ah(0),nh(0),nl(0),al(0),longcount(0),shortcount(0);


if d<>d[1] then begin
cdp = (highD(1)+lowD(1)+2*CloseD(1))/4;
ah = cdp+(highD(1)-LowD(1));
//nh = cdp*2-LowD(1); no use this !
//nl = 2*cdp-highD(1); no use this !
al = cdp-(highD(1)-LowD(1));
longcount = 0;
shortcount = 0;
end;


condition1 = time > 0850 and time < 1340 and Close > Highest(high,LengthL)[1] and Longcount = 0;
condition2 = time > 0850 and time < 1340 and Close < Lowest(low,LengthS)[1] and shortcount = 0;

if condition1 then begin
Buy("CDP_B") 1 contracts next bar at ah+1 stop;
end;

if condition2 then begin
Sellshort("CDP_S") 1 contracts next bar at al-1 stop;
end;


if marketposition = 1 then begin
longcount = 1;
end;


if marketposition = -1 then begin
shortcount = -1;
end;


if marketposition = 1 then begin
Sell("S1L") 1 contracts next bar at entryprice*(1-stoploss) stop;
end;

if marketposition = -1 then begin
BuytoCover("S1S") 1 contracts next bar at entryprice*(1+stoploss) stop;
end;


{ ----- TSTS Original code -----}
if time = 1340 then begin
Sell("exitL") 1 contracts this bar at close;
Buytocover("exitS") 1 contracts this bar at close;
cdp = 0;
ah = 0;
nh = 0;
nl = 0;
al = 0;
end;



我將這個策略程式套進這八年的台指期貨指數, Total Net Profit 為 NT956000.
(買賣來回一趟含滑價, 共設 NT2000).
詳細績效如下 :

cdp1_performance 


cdp1_performance_chart 


看過 TSTS星人大大的解說, 瞭解到 CDP 用了滿有力的價格突破作為買賣訊號出手的依據.
因此我在想, 如此強的突破, 不要限制在當沖上, 或許可以得到更好績效.

所以, 我把程式最後一段先 mark 掉(有註明 TSTS Original Code 那一段開始).
再回測到這八年的台指期貨指數.
果然, 績效有再向上增加.
而且交易次數減少不打緊, 每筆交易 Net Profit 也從 1230 增加到 3744.

cdp2_performance


cdp2_performance_chart 


~以上.
掠前人(TSTS星人大大)之美.
將個人想法和回測績效實做出來, 供程式交易同好參考.

arrow
arrow
    全站熱搜

    htnvt241 發表在 痞客邦 留言(0) 人氣()