2009年9月14日 星期一

CDP當沖進階程式碼

上一篇的easylanguage的講解,用的是當沖懶人包一文中的程式,再加上高低點的濾網,總獲利增加了約四十萬,而maxdrawdown從15萬大幅下降到6萬9,而所用的參數只有3個。



以下為每年的獲利,心動了嗎?程式真的不難,難的是要持續執行。



附上程式碼,方便大家使用

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

if time = 0850 then
begin
cdp = (highD(1)+LowD(1)+2*CloseD(1))/4;
ah = cdp + (highD(1) - LowD(1));
nh = cdp*2 - LowD(1);
nl = 2*cdp - highD(1);
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 stop; end; if condition2 then begin Sell("CDP_S") 1 contracts next bar at al stop; end; if marketposition = 1 then begin longcount = 1; end; if marketposition = -1 then begin shortcount = -1; end; if marketposition = 1 then begin exitlong("SlL") 1 contracts next bar at entryprice*(1 -stoploss) stop; end; if marketposition = -1 then begin exitshort("SlS") 1 contracts next bar at entryprice*(1 + stoploss) stop; end; if time = 1340 then begin exitlong("exitL") 1 contracts this bar at close; exitshort("exitS") 1 contracts this bar at close; cdp = 0; ah = 0; nh = 0; nl = 0; al = 0; end;

read more...