我本來是想找出股票期貨在現貨開盤前就大漲或大跌的股票,也就是8:45到9:00之間的漲幅,但好像寫到9:00以前或是13:30以後就無法運作了,交易資料完全是0,同時還有一些奇怪的問題:
1. 由於沒有任何交易,所以我嘗試把condition1拿掉,變成:
if position = 0 and filled = 0 and currenttime >= 090100 and currenttime <= 090500 then begin
但很奇怪的是,這樣還是無法運作,明明這一行沒有用到上面任何數據或變數,為什麼還是無法運作? 我把上面那一大坨刪除後卻又正常了(但只有回測現貨可以,連續月份股票期貨不行),為甚麼上面的程式碼會引響我進場? 我又沒有用到上面的任何資料
2. 為何無法計算8:45到9:00之間的漲幅? 我回測的商品是連續月份股票期貨(一般) ,我該如何計算這段時間的漲幅?
var: intrabarpersist firstbar(0);
var: intrabarpersist openbar(0);
var: intrabarpersist nearclose(0);
var: intrabarpersist closebar(0);
//8:45
if currenttime >= 084500 and currenttime < 084600 then begin
firstbar = close;
end;
//9:00
if currenttime >= 090000 and currenttime < 090100 then begin
openbar = close;
end;
//13:25
if currenttime >= 132500 and currenttime < 132600 then begin
nearclose = close;
end;
//13:30
if currenttime >= 133000 and currenttime < 133100 then begin
closebar = close;
end;
value1 = (openbar - firstbar)/firstbar*100; //計算現貨開盤前漲幅
value2 = (closebar - nearclose)/nearclose*100; //計算現貨收盤前漲幅
condition1 = value1 >= 3;
if position = 0 and filled = 0 and currenttime >= 090100 and currenttime <= 090500 then begin
setposition(-1,market);
end;
if position > 0 and filled > 0 and condition1 and currenttime >= 091000 and currenttime < 091100 then begin
setposition(0,market);
end;
2 評論