小幫手你好:
我寫了一個選股程式,條件是個股收盤價連接20日高點的斜率若是大於大盤的,則幫我挑選出來,但是經由outputfield發現,有些不符條件的標的也被選到,請問這是甚麼原因呢?或是您有更好的寫法可以提供?
程式碼如下:
if date=currentDate then begin
arrays: d_high[20, 2](0),tsed_high[20, 2](0){, m_high[200, 2](0),tsem_high[200, 2](0)} ;
vars:v1(0),v2(0),v3(0),v4(0),v5(0),v6(0),_slopeh(0),_slopehtse(0);
for v1 = 2 to 20 begin
d_high[v1, 1] = getfield("High", "D")[v1-1];
d_high[v1, 2] = getfield("Date", "D")[v1-1];
end;
v2 = d_high[1, 1];
v3 = 1;
for v1 = 2 to 20 begin
if d_high[v1, 1] > v2 then begin
v3 = v1;
v2 = d_high[v1, 1];
end;
for v4 = 2 to 20 begin
tsed_high[v4, 1] = getsymbolField("tse.tw","High", "D")[v4 - 1];
tsed_high[v4, 2] = getsymbolField("tse.tw","Date", "D")[v4 - 1];
end;
v5 = tsed_high[1, 1];
v6 = 1;
for v4 = 2 to 20 begin
if tsed_high[v4, 1] > v5 then begin
v6 = v4;
v5 = tsed_high[v4, 1];
end;
value142 = GetBarOffset(d_high[v3, 2]);
value143 = GetBarOffset(tsed_high[v6, 2]);
if value142 <> 0 and close<>0 then begin
_slopeh =((close - v2)*100/close )/value142; //斜率 = (收盤 - 最高點) / 距離
end ;
{else _slopeh = 0; } //如果最高點 = 現在
if value143<> 0 and GetSymbolField("TSE.TW","收盤價")<>0 then begin
_slopehtse =(( GetSymbolField("TSE.TW","收盤價")-v5)*100/GetSymbolField("TSE.TW","收盤價")) /value143; //斜率 = (收盤 - 最高點) / 距離
end ;
{else _slopehtse = 0;} //如果最高點 = 現在
value20=average(getsymbolField("tse.tw", "收盤價","日"),10);
value21=average(getsymbolField("tse.tw", "收盤價","日")[1],10);
value22=average( getField("Close","日"),20);
value23=average( getField("Close","日")[1],20);
condition19=close>value22 and value22>value23;
condition20=(getsymbolField("tse.tw", "收盤價")>value20 and value20>value21);
{ or (getsymbolField("otc.tw", "收盤價")>value13 and value13 >value33)
or (getsymbolField("TSEE.tw", "收盤價")>value133 and value133 >value233);}
condition21={getField("估計量")>getField("成交量", "D")[1]*1.6
and }getField("成交量", "D")[1]>5000 and close>30;
value150=highest(getField("最高價", "D")[1],150);
condition22=closed(1)<=value150 and closed(1)>=value150*0.9;
condition1=false;
if ( _slopeh[1] < _slopehtse and _slopeh > _slopehtse ) then condition1=true;
if condition1 and condition19 {and condition20} and condition21 and condition22
then ret=1;
outputfield(1,value143,0,"tse距離20H日數");
outputfield(2,value142,0,"個股距離20H日數");
outputfield(3,_slopehtse,2,"tse斜率");
outputfield(4,_slopeh,2,"個股斜率");
end;end;
end;

2 評論