在此將下單機中計算結算日日期分享給大家
已經將檔案轉成HTS與TS檔
懶的看的人可以匯入使用
使用方法:
假設今天是 2009/03/13(近月為200903)
BalanceDay(1) = 1090218 (上個月結算日)
BalanceDay(0) = 1090318 (近月結算日)
BalanceDay(-1) = 1090415 (次月結算日)
假設今天是 2009/03/19(近月為200904)
BalanceDay(1) = 1090318 (上個月結算日)
BalanceDay(0) = 1090415 (近月結算日)
BalanceDay(-1) = 1090520 (次月結算日)
TS新增自訂函數
HTS 版本(本地下載)
BalanceDay
/* Mail: ChunI.Kuo@Gmail.com Blog: http://chunikuo.blogspot.com/ Designed by Chun-I Kuo */ parameters: Length(Numeric); vars: ShortDate(0), TM(0), MBD(0), Q(0), M(0), Y(0); ShortDate = floor((date/100))*100; MBD = BalanceDayOfMonth(ShortDate); if date > MBD then // The balance day of this month has passed TM = floor(date / 10000) * 12 + month(date) - Length + 1 else // The balance day of this month doesn't arrival TM = floor(date / 10000) * 12 + month(date) - Length; end if BalanceDay = BalanceDayOfMonth((Floor(TM/12)*100 + Mod(TM, 12))*100);
BalanceDayOfMonth
/* Mail: ChunI.Kuo@Gmail.com Blog: http://chunikuo.blogspot.com/ Designed by Chun-I Kuo */ parameters: M1(Numeric); if dayofweek(M1+01) = 0 then BalanceDayOfMonth = M1+18 else if dayofweek(M1+01) = 1 then BalanceDayOfMonth = M1+17 else if dayofweek(M1+01) = 2 then BalanceDayOfMonth = M1+16 else if dayofweek(M1+01) = 3 then BalanceDayOfMonth = M1+15 else if dayofweek(M1+01) = 4 then BalanceDayOfMonth = M1+21 else if dayofweek(M1+01) = 5 then BalanceDayOfMonth = M1+20 else if dayofweek(M1+01) = 6 then BalanceDayOfMonth = M1+19; end if end if end if end if end if end if end if
TS 版本(本地下載)
BalanceDay
{ Mail: ChunI.Kuo@Gmail.com Blog: http://chunikuo.blogspot.com/ Designed by Chun-I Kuo } Inputs: Length(NumericSimple); vars: ShortDate(0), TM(0), MBD(0), Q(0), M(0), Y(0); ShortDate = floor((date/100))*100; MBD = BalanceDayOfMonth(ShortDate); if date > MBD then {The balance day of this month has passed} TM = floor(date / 10000) * 12 + month(date) - Length + 1 else {The balance day of this month doesn't arrival} TM = floor(date / 10000) * 12 + month(date) - Length; BalanceDay = BalanceDayOfMonth((Floor(TM/12)*100 + Mod(TM, 12))*100);
BalanceDayOfMonth
{ Mail: ChunI.Kuo@Gmail.com Blog: http://chunikuo.blogspot.com/ Designed by Chun-I Kuo } Inputs: M1(NumericSimple); if dayofweek(M1+01) = 0 then BalanceDayOfMonth = M1+18 else begin if dayofweek(M1+01) = 1 then BalanceDayOfMonth = M1+17 else begin if dayofweek(M1+01) = 2 then BalanceDayOfMonth = M1+16 else begin if dayofweek(M1+01) = 3 then BalanceDayOfMonth = M1+15 else begin if dayofweek(M1+01) = 4 then BalanceDayOfMonth = M1+21 else begin if dayofweek(M1+01) = 5 then BalanceDayOfMonth = M1+20 else begin if dayofweek(M1+01) = 6 then BalanceDayOfMonth = M1+19; end; end; end; end; end; end;
達人 請問一下,"parameters: M1(Numeric)"語法中的"Numeric"是什麼意思呢?
回覆刪除在設定Function的時候, 必須指定加載(input)的型態
回覆刪除Numeric是指輸入的型態必須是數字
其他一樣的型態有NumbericSimple跟NumbericSeries
希望有回答道你的問題^^
達人你好,
回覆刪除不大會用吶。可以給個範例嗎?比方在結算日的時候,如果手上還有單,就要出清,那要怎麼套用你這個函數來決定結算日。
謝謝!
誠如你的問題
回覆刪除結算日必須在13:25分出清
(HTS)
if Date = BalanceDay(0) and time = 132500 then
exitlong this bar on close;
exitshort this bar on close;
end if
當然必須注意要確定13:25分後不會有新的買賣訊產生
感謝您的回答. 感恩感恩!
回覆刪除達人 可否分享一下台股結算日在下單機的計算方式呢?
回覆刪除我已經在上一篇回覆你了唷, 不過我還是不是很懂你要問的是什麼東西呢
回覆刪除2007年10月的結算日是17日
回覆刪除假設今天是 2007/10/18
print(date,BalanceDay(0),BalanceDay(1),BalanceDay(-1));
輸出為1071018.001071121.001071017.001080016.00
是次月有問題嗎?
回覆刪除我檢查一下
若該次月有問題,接下來的2個月份結算輸出都是錯誤
回覆刪除看看11跟12月就知道我的意思..
小達人兄:您好
回覆刪除請教問題,此函數在每年的12月時的balanceday(0)及(1)
會出現錯誤的結果日期
例如去年2008/12月的結算週三為17日
print(date,balanceday(0),balanceday(1));
1081217.001090015.001081119
1081218.001090121.001090015
那麼
正確的081217當日的balanceday(0)所print出來的資料
應該是081217,而不是090015
這也導致了081218的balanceday(1)的資料錯誤
能不能賜教,出個修正版本?
謝謝