2013年5月8日 星期三

MultiCharts程式篇:國外期貨非換日時間的程式處理(包含夏令及冬令時間判斷)

 

MultiCharts程式篇:國外期貨非換日時間的程式處理(包含夏令及冬令時間判斷)

 

 

1-以英鎊BP為例




  • 使用交易所時間


資料時間預設為交易所時間就沒有換日問題,細節可以參考另一篇文章 "MultiCharts基礎篇:國外期貨資料時間的儲存、顯示和輸出的比較"。




  • 使用本機時間


若換成台灣時間,程式要如何處理24小時的商品時間過了凌晨12點,但其實是同一個交易日的問題呢,先將資料日期改成台灣時間。
























這裡提供一個簡單的作法去判斷台灣時間所認定的交易日。


程式碼:


vars:isSummer(true), theLastDate(0), theMins(5)
, summerTimeS(0000), summerTimeE(0500)
, winterTimeS(0000), winterTimeE(0600);




if time - time[1] >= 100 and time = 0600 + theMins then
begin
isSummer = true;
end
else if time - time[1] >= 100 and time = 0700 + theMins then
begin
isSummer = false;
end;

If isSummer and time >= summerTimeS and time <= summerTimeE then
Begin
theLastDate = julianToDate(dateToJulian(date) - 1);
End
else If not isSummer and time >= winterTimeS and time <= winterTimeE then
Begin
theLastDate = julianToDate(dateToJulian(date) - 1);
End
else
Begin
theLastDate = date;
End;


condition1 = date <> theLastDate;


if condition1 then
begin
print("date = " , date, " time = ", time, " isSummer = ", isSummer, " theLastDate= " , theLastDate, " is last day ");
end
else
begin
print("date = " , date, " time = ", time, " isSummer = ", isSummer, " theLastDate= " , theLastDate, " is not last day ");
end;




輸出值:


date = 1130504.00 time =  450.00 isSummer = TRUE theLastDate= 1130503.00 is last day
date = 1130504.00 time =  455.00 isSummer = TRUE theLastDate= 1130503.00 is last day
date = 1130504.00 time =  500.00 isSummer = TRUE theLastDate= 1130503.00 is last day
date = 1130506.00 time =  605.00 isSummer = TRUE theLastDate= 1130506.00 is not last day
date = 1130506.00 time =  610.00 isSummer = TRUE theLastDate= 1130506.00 is not last day
date = 1130506.00 time =  615.00 isSummer = TRUE theLastDate= 1130506.00 is not last day



說明:

1.夏令及冬令時間判斷:簡單的說就是判斷收盤後的第一根K棒時間是6或7點。
2.非換日判斷:簡單的說就是將跨日後到收盤的日期用一個變數設定成前一天。

此範例程式只是提供簡單的想法,還有小細節需要處理,例如:若收盤後第一根時間不是0605或0705(少資料或調整交易時間),或遇到假日等問題就會有狀況,大家可以參考並延伸其它解法方案。




此版本為MultiChart 7.4.20.400。

P.S:本資料僅供參考,使用者依本資料交易發生交易損失需自行負責,本人對資料內容錯誤或更新延誤不負任何責任。

0 意見:

張貼留言