PureBytes Links
Trading Reference Links
|
Try this out and see if it does what you want. The premise is this;
Datenum is just a weighted count, so subtract 10000 (equals 1 year)
to get one year ago. Then take the last BarIndex where Datenum is not
any more recent than that.
This 1 bar exploration illustrates my earlier comment in that you
will see that there is a difference of 253 bars in the last year (as
of Jul 18 2008).
Note this will only work when running against the most recent trade
date since it is using LastValue. To illustrate this, run the
Exploration over last 5 bars. You will note that the "Today ..."
values increment, but the year ago values are fixed.
Buy = Sell = Short = Cover = 0;
yearAgoDate = LastValue(Datenum() - 10000);
yearAgoBar = LastValue(ValueWhen(Datenum() <= yearAgoDate, BarIndex
()));
Filter = 1;
AddColumn(yearAgoDate, "Year Ago Date");
AddColumn(yearAgoBar, "Year Ago BarIndex");
AddColumn(Datenum(), "Today Date");
AddColumn(BarIndex(), "Today BarIndex");
Mike
--- In amibroker@xxxxxxxxxxxxxxx, "Mike" <sfclimbers@xxx> wrote:
>
> Hi,
>
> Just a quick note; BarIndex only counts *trading* days. Not
calendar
> days. Whereas DaysSince1900 is calendar days. So, you may be
> comparing apples to oranges. For example; in the US markets, there
> are about 252 trading days a year. That is the count reflected in
> BarIndex.
>
> Mike
>
> --- In amibroker@xxxxxxxxxxxxxxx, "tipequity" <l3456@> wrote:
> >
> > I am having a hard time relating dates to bar indecies. In code
> > provided below I am trying to calculate the bar index of a year
ago
> > date with little success. I appreciate any help and explanation.
> >
> > SetBarsRequired(10000);
> >
> > function RefDays( Array, Days )
> > {
> > td = DaysSince1900();
> > result = Null;
> >
> > if( Days < 0 )
> > {
> > for( i = BarCount -1; i >= -Days; i = i - 1 )
> > {
> > backday = td[ i ] + Days; // Days is negative
> > for( j = -Days/2; j < i; j++ )
> > {
> > if( td[ i - j ] <= backday )
> > {
> > result[ i ] = Array[ i - j ];
> > break;
> > }
> > }
> > }
> > }
> > return result;
> > }
> >
> > yy = Year();
> > dy = DayOfYear();
> > leapyear = ( yy % 4 ) == 0 AND yy != 2000;
> > yearlen = IIf( leapyear, -366, -365 );
> >
> > aYearAgoDate = RefDays(DateTime(), LastValue(yearlen));
> > dn = DateNum();
> > BarIndx = BarIndex();
> >
> > StartDateBar = LastValue( ValueWhen ( dn ==
StartDate ,BarIndx ) );
> >
>
------------------------------------
Please note that this group is for discussion between users only.
To get support from AmiBroker please send an e-mail directly to
SUPPORT {at} amibroker.com
For NEW RELEASE ANNOUNCEMENTS and other news always check DEVLOG:
http://www.amibroker.com/devlog/
For other support material please check also:
http://www.amibroker.com/support.html
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/amibroker/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/amibroker/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:amibroker-digest@xxxxxxxxxxxxxxx
mailto:amibroker-fullfeatured@xxxxxxxxxxxxxxx
<*> To unsubscribe from this group, send an email to:
amibroker-unsubscribe@xxxxxxxxxxxxxxx
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|