2019年5月26日 星期日

函數(WOptionWeekth):台指週選擇權的第幾週


這個函數將會傳回目前 Bar 所屬時間的週選擇權的第幾週合約,正常來說是 1~5。也就是下圖中圈起來的這個數字。




函數名稱:WOptionWeekth。傳回:數值。程式碼如下:
var: passedWeek(false), theWeek(1),
     passedMonth(false), theMonth(""),
     weekAddable(false);
var: j(0), lastDay(0);     
var: isNight(false);


isNight= time=sess2firstbartime;


if month(D)<>month(D)[1] then
  weekAddable= false;

if weekAddable=false and dayofweek(D)>=3 and dayofweek(D)<5 and isNight then
  theWeek= 0;

if theWeek<=1 then
  weekAddable= true;

if dayofweek(D)<dayofweek(D)[1] then
  passedWeek= false;


if dayofweek(D)>=3 and passedWeek=false and weekAddable=true then begin
  if isNight or (T[1]=sess2endtime and D<>D[1]) then begin
    theWeek= theWeek + iff(datetojulian(D)-datetojulian(lastDay)<9,1,2);
    passedWeek= true;
    lastDay= D;
  end;
end;


if dayofweek(D)>=3 and dayofmonth(D)>=24 and isNight then begin
  if month(D)<>month( JulianToDate(datetojulian(D)+(10-dayofweek(D))) ) then begin
    theMonth= text( (1900+Year(D)+iff(month(D)=12,1,0)):0:0, "/", (month(D)+1):0:0 );
    theWeek= 1;
  end;
end;


WOptionWeekth= theWeek;


我是利用期交所宣傳週選擇權加掛規則的說明去做,規則如下:


你可以建立好上述函數後,使用 指標 或是 訊號去呼叫它。例如 plot1( WOptionWeekth ); 在圖表上顯示出每根 Bar 當時正在交易的週選擇權第 N 週。

熱門文章