Jim Dean
 Sage
       Posts: 3433
Joined: 3/13/2006
Location: L'ville, GA
User Profile |
Duxx presented an interesting problem for solution: he wanted to fire an Entry signal on a particular day of the month, for a certain range of months of the year. Sounds relatively simple, if you have the necessary functions to determine things like the Month and Day of a given Bar.
However, there are a few tricks involved ... first, you have to deal with month-ranges that "cross over" to the next year ... for instance, starting in October and ending in January.
Also, you need to deal with the fact that only approx 21 days of the avg 30-day month are "trading days" ... and inevitably whatever calendar-day-of-month you pick as your focus, there will be some months where that date lands on a Sat or Sun. In this case, Duxx wanted the trade to be taken on the following Monday.
The code below solves this problem ... and provides for another very interesting feature. If the EntryDoM date input is ZERO, then the routine automatically identifies the THIRD TRADING-DAY FRIDAY of a given month ... ie, Options-Expiration Friday.
Personally, I believe that month-cyclic behavior tends to reference itself to Expiration Fridays, more than the first of the month. This code provides a framework for applying that logic in a variety of ways.
I've chosen a timeperiod on the chart-example to illustrate how it picks the precise date on months when it can, and how it jumps to the next Monday when necessary. Also, how it bridges over the end of the year.

The second set of charts illustrate how it finds the Expiration Friday. The January case is particularly cool ... it picked the FOURTH Friday of the month, since the FIRST Friday was a holiday (New Years Day).

The RTF file contains the actual code.

[Edited by Jim Dean on 3/28/2015 7:25 AM]
Attached file : aJDysCalendarEntry graphic.png (81KB - 1100 downloads)
Attached file : aJDysCalendarEntry ExpFri graphic.png (43KB - 1136 downloads)
Attached file : aJDysCalendarEntry code.png (30KB - 1072 downloads)
Attached file : aJDysCalendarEntry.rtf (3KB - 873 downloads)
|
Gary Rickle
 Member
 Posts: 40
Joined: 3/7/2006
Location: Cape Canaveral, Fl
User Profile |
Jim,
I keep thinking that there is no way you can continue to "out do" yourself, but you have proved me wrong again.
Neat work, especially the Jan expiration. "Particularly cool" is just an understatement.
Looking at the time stamp on your post confirms to me that you must write some of these things while you sleep or maybe it would be more accurate to say you never sleep.
Thanks again for all your time, attention and help on so many different problems (opportunities)! As usual you have gone above and beyond what most would be able or would consider doing.
G
|