[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: function



PureBytes Links

Trading Reference Links

> I don't think it has to be this complicated.  Each trading day is
> a bar - holidays and weekends are irrelevant.  Simply save the bar
> number of the first trading day of the year and SUBTRACT from the
> current bar. 

That's essentially an alternate way to compute the TradeDate value in 
my first suggestion:

   if Year(Date) <> Year(Date[1]) then TradeDate = 0;
   if Date <> Date[1] then TradeDate = TradeDate + 1;

Instead of setting TradeDate to 0 at the start of the year, you set a 
StartOfYear variable to CurrentBar at the start of the year.  Same 
concept -- the only difference is whether you subtract the 
StartOfYear value from CurrentBar (your approach) or increment a 
counter on new day (mine).  My solution has the advantage that it 
also works with intraday data.

Alain wasn't specific about exactly how he wanted to refer to the Nth 
trading day.  If he wants to know the ordinal value of today, i.e. 
that today is the 153rd trading day in the year, either your solution 
or mine will work.  If he wants to know the Date for the Nth trading 
day, you could do it with either solution **IF** it's on daily data, 
it's within the current year, AND it's within MaxBarsBack:

  NthDate = Date[TradeDate-N];

However, if he wants to know the Date of the Nth trading day, and he 
wants to be able to do that for ANY day in the year (even beyond 
MaxBarsBack, or in previous years), then he'd have to use my 
complicated solution #2.

Gary