181228.jpg

國外期貨商品,每個交易所的結算日不同,詳情請查詢這裡連結。 港交所的恆生、H股指數,新加坡交易所A50、摩根,會用最後一天或是倒數第二個交易日當結算日

倒數第二個交易日在Multicharts用法應該如何表示呢? (倒數第二個工作天不等於每個月倒數第二天)

我的功力不強,只好用土法煉鋼的方式把每個月倒數第二天可能會落在星期幾寫下來,用函數來記錄辨別

1,3,5,7,8,10,12月 每個月有31天;4,6,9,11月 每個月有30天,2月份有28天(閏年就不管了 4年才遇到一次)

如果有更好的寫法,也請高手們不吝分享
 
程式碼如下
vars:th(0);
if month(date)=1 or month(date)=3 or month(date)=5 or month(date)=5 or month(date)=7 or month(date)=8 or month(date)=10 or month(date)=12 then begin
th=0;
if dayofmonth(date)=28 and dayofweek(date)=1 then th=30 ;
if dayofmonth(date)=28 and dayofweek(date)=2 then th=30 ;
if dayofmonth(date)=28 and dayofweek(date)=3 then th=29 ;
if dayofmonth(date)=28 and dayofweek(date)=4 then th=28 ;
if dayofmonth(date)=28 and dayofweek(date)=5 then th=30 ;
if dayofmonth(date)=30 and dayofweek(date)=1 then th=30 ;
if dayofmonth(date)=30 and dayofweek(date)=2 then th=30 ;
 
end;
 
if month(date)=4 or month(date)=6 or month(date)=9 or month(date)=11 then begin
th=0;
if dayofmonth(date)=27 and dayofweek(date)=1 then th=29 ;
if dayofmonth(date)=27 and dayofweek(date)=2 then th=29 ;
if dayofmonth(date)=27 and dayofweek(date)=3 then th=28 ;
if dayofmonth(date)=27 and dayofweek(date)=4 then th=27 ;
if dayofmonth(date)=27 and dayofweek(date)=5 then th=27 ;
if dayofmonth(date)=29 and dayofweek(date)=1 then th=29 ;
if dayofmonth(date)=29 and dayofweek(date)=2 then th=29 ;
end;
 
if month(date)=2 then begin
th=0;
if dayofmonth(date)=26 and dayofweek(date)=1 then th=26 ;
if dayofmonth(date)=26 and dayofweek(date)=2 then th=26 ;
if dayofmonth(date)=26 and dayofweek(date)=3 then th=26 ;
if dayofmonth(date)=26 and dayofweek(date)=4 then th=26 ;
if dayofmonth(date)=25 and dayofweek(date)=4 then th=25 ;
if dayofmonth(date)=24 and dayofweek(date)=4 then th=24 ;
end;
 
以上報告  dora%20(21).gif
arrow
arrow
    全站熱搜

    元大期貨楊宗儒 發表在 痞客邦 留言(0) 人氣()