2009年6月16日 星期二

以前寫程式的技巧真差

剛剛不小心看到以前的文章

Toby Crabel的當沖交易

裡面的Code,寫法看起來就是很笨拙。

看了非常不舒服...而且停損不太合理。

這邊改寫一下,順便改一下停損訊號,改1%停損

程式碼如下。


vars:count(0);
vars:HL1(0),HL2(0),HL3(0),HL4(0),HL5(0),HL6(0),HL7(0);
vars:st(0),we(0),R7(0);

HL1 = highd(1) - lowd(1);
HL2 = highd(2) - lowd(2);
HL3 = highd(3) - lowd(3);
HL4 = highd(4) - lowd(4);
HL5 = highd(5) - lowd(5);
HL6 = highd(6) - lowd(6);
HL7 = highd(7) - lowd(7);
R7 = ( HL1 + HL2 + HL3 + HL4 + HL5 + HL6 + HL7 ) / 14;
st = opend(0) + R7;
we = opend(0) - R7;

if date[0] < > date[1] then count = 0;
if HL1 > maxlist(HL2,HL3,HL4,HL5,HL6,HL7) then count = 1;

if time > 0845.00 and time < 1345.00 and count = 0 then begin

if H[1] > st and C > st then begin
buy next bar at market;
count = count + 1;
end;

if L[1] < we and C < we then begin
sell next bar at market;
count = count + 1;
end;

end;

if marketposition > 0 then exitlong next bar at 0.99*entryprice(0) Stop;
if marketposition < 0 then exitshort next bar at 1.01*entryprice(0) Stop;

if time = 1340.00 then begin
exitlong next bar at market;
exitshort next bar at market;
end;
HEMiDEMi Technorati Del.icio.us MyShare?犖?貊惜 Yahoo