Options Expiration (OPEX) (Amibroker And Tradestation Code)
Below is the most simple code to code the OPEX week and days:
Amibroker code:
Trade on the first day of OPEX week:
Buy= DayOfWeek()==1 AND Day()>10 AND Day()<18 ;
buyPrice=Open;
Sell= 0 ; //never sell
sellPrice=Close ;
Trade on the last day of OPEX week (OPEX day):
Buy= DayOfWeek()==5 AND Day()>14 AND Day()<22 ;
buyPrice=Close;
Sell= 0; //we never sell
sellPrice=Close ;
Additional OPEX code for Amibroker:
function DaysInMonth(MonthNum,YearNum)
{
_Daysinmonth=IIf(MonthNum==1 OR MonthNum==3 OR MonthNum==5 OR MonthNum==7 OR
MonthNum==8 OR MonthNum==10 OR MonthNum==12,31,30);
Daysinmonthfeb=IIf(YearNum%4 == 0 AND YearNum%100!=0,29,28);
_Daysinmonth=IIf(MonthNum==2,Daysinmonthfeb,_Daysinmonth);
return _Daysinmonth;
}
function DaysToThirdFriday()
{
d = Day();
wd = DayOfWeek();
DaysToFriday = IIf(5-wd<0, (12-wd) % 7, (5 - wd) % 7);
ThirdFriday = ((d + DaysToFriday) % 7)+14;
ThirdFriday = IIf(ThirdFriday==14, 21, ThirdFriday);
_DaysToThirdFriday = ThirdFriday - d;
_DaysToThirdFriday = IIf(_DaysToThirdFriday >= 0, _DaysToThirdFriday,
ThirdFriday+IIf(ThirdFriday+14>DaysInMonth(Month(),Year()),28,35)-d);
return _DaysToThirdFriday;
}
Buy= daystothirdfriday()==4 AND DayOfWeek()==1 ; // buy opex week Monday open
buyPrice=Open;
Sell= daystothirdfriday()==0 OR DayOfWeek()==5 ;
sellPrice=Close ;
Tradestation code:
Trade on the first day of OPEX week (example):
If dayofweek(date)=5 and dayofmonth(date)>7 and dayofmonth(date)<15 // opex friday
then buy next bar at open;
If barssinceentry=1 then Sell this bar at close;
Trade on the last day of OPEX week (OPEX day example):
If dayofweek(date)=4 and dayofmonth(date)>13 and dayofmonth(date)<22 // opex friday
then buy next bar at open;
If barssinceentry=1 then Sell this bar at close;
