我之前看到 外資不碰的股票有人在收 這篇文章,該文章的策略有用到選股中心「近1日綜合前十大券商合計買超合計佔成交量 5% 以上」與「成交量大於 500 張」兩個條件,由於這兩項條件要到選股中心用滑鼠點選,我想把這兩個條件改用 XScript 來表達。
於是我把文章提供的程式碼改寫成這樣:
input: period(5,"計算期間");
input: investorLimit(2000,"外資持股上限");
input: ratio(50,"主力買張比重(%)");
input: volLimit(500 , "成交均量下限");
input: top10Buy(5, "近 1 日綜合前十大券商合計買超佔成交量比");
input: volRecent(500, "近 1 日成交量最低張數");
SetTotalBar(3);
// 主力買張比重
value1 = summation(GetField("主力買張","D")[1], period);
value2 = summation(volume[1], period);
value3 = value1 / value2 * 100;
value4 = GetField("綜合前十大券商買賣超張數", "D")[1];
value5 = volume[1];
value6 = value4 / value5 * 100;
print("Date=", Date, "top10=", value4);
if GetField("外資持股","D") [1]< investorLimit and value3 > ratio and value2 > volLimit * period and value6 > top10Buy and value5 > volRecent
then ret=1;
但改出來的程式碼回測報酬率卻和原本的策略差很多:

請問是不是我理解錯了「近1日綜合前十大券商合計買超合計佔成交量 5% 以上」的意思?
我的程式碼「value6 > top10Buy」就是想要用來取代「近1日綜合前十大券商合計買超合計佔成交量 5% 以上」條件的,但無法順利取代,請問我該怎麼改才能讓 XScript 可以直接跑出那篇文章的報酬率呢?

3 評論