大家好,

分享如何使用選股腳本撰寫跳空回補與否並輸出股價報表,

 

選股條件大致說明:

十周內跳空 如哪一周有發生跳空的狀態請記錄當下的最低價與上周的最高價。

 

大致撰寫邏輯:

1. 使用 if currentbar <> gettotalbar then return; 表示在最新的K棒跑選股腳本即可,不用每根K棒都跑,以減少耗能。

2. 使用 for 迴圈,並搭配 array 陣列,當跳空時,記錄當下的最低價與上周的最高價;並在For迴圈使用變數 value99,以篩選出有跳空的股票。 

3. 最後使用 outputfield 將有跳空股票當下的最低價與上周的最高價,顯示在選股列表,以利觀察。

 

範例呈現出來的選股中心列表如下圖:

 

選股腳本程式碼範例如下:

Array: NumArray[10,2](0);

if currentbar <> gettotalbar then return;

for value999 = 0 to 9
    if low[value999] > high[value999+1] then begin
        NumArray[value999+1,1] = low[value999];
        NumArray[value999+1,2] = high[value999+1];
        value99 += 1;
    end;

if value99 <> 0 then ret = 1;

outputfield1(NumArray[1,1],"當週Low");
outputfield2(NumArray[1,2],"當週High");
outputfield3(NumArray[2,1],"前1週Low");
outputfield4(NumArray[2,2],"前1週High");
outputfield5(NumArray[3,1],"前2週Low");
outputfield6(NumArray[3,2],"前2週High");
outputfield7(NumArray[4,1],"前3週Low");
outputfield8(NumArray[4,2],"前3週High");
outputfield9(NumArray[5,1],"前4週Low");
outputfield10(NumArray[5,2],"前4週High");
outputfield11(NumArray[6,1],"前5週Low");
outputfield12(NumArray[6,2],"前5週High");
outputfield13(NumArray[7,1],"前6週Low");
outputfield14(NumArray[7,2],"前6週High");
outputfield15(NumArray[8,1],"前7週Low");
outputfield16(NumArray[8,2],"前7週High");
outputfield17(NumArray[9,1],"前8週Low");
outputfield18(NumArray[9,2],"前8週High");
outputfield19(NumArray[10,1],"前9週Low");
outputfield20(NumArray[10,2],"前9週High");

 

以上供參考,有問題歡迎詢問。