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

RE: ELA help



PureBytes Links

Trading Reference Links

> My first attempt looks like this:
> C/C[CurrentDate-1010322]
> But for somereason this doesn't work.

That's because you're subtracting Date-format numbers.

There are 28 days between 2/22/01 and 3/22/01.  But 1010322 - 1010222 
is 100, not 28.

Dean DiCarlo wrote:
> I believe you need to change your currentdate and 1010322 using
> the "datetojulian" do the subtraction and then use "juliantodate"
> in order to make your code work. 

Close.  Both CurrentDate and 1010322 are in Date format.  So you need 
to do:  C/C[DateToJulian(CurrentDate) - DateToJulian(1010322)].

However:  CurrentDate is TODAY's date, not the current bar on the 
chart.  So you're looking at the difference between today, 5/24/01 at 
the moment, and 3/22/01.  Is that what you want?  Or did you want to 
use Date, which is the date of the current bar?

Also be aware that this code only works on daily bars, since you're 
offsetting the close by the # of days.  

And in fact it doesn't work properly even on daily bars -- because 
you're looking at the close of N **bars** ago when you say C[N], not 
N **days** ago.  But the DateToJulian calculation returns the number 
of calendar DAYS between today and 3/22/01, which is 63.  So since 
there are usually 5 bars per 7-day week, you're going to be looking 
roughly 7/5*63 = 88 days into the past, instead of 63.  63 daily BARS 
before today is actually 2/27, if I counted right.

Add to that the fact that you might get into some long lookback 
periods with this method, and you might decide it's not a good way to 
do it.

How about this instead:

if Date = 1010322 then Date1Close = Close;
Gain = Close / Date1Close

It's simpler, and it works right.

Gary





  • References: