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

Re: Weekly Indicators based on Daily data



PureBytes Links

Trading Reference Links

> >Can someone tell me if its possible to create an indicator
> >that is based on daily data but is effectively plotting 
> >a weekly indicator?  Such as plotting a 10 period RSI for example 
> >but using today, 5 days ago, 10 days ago..etc...
> 
> What you describe is easy.  You just load up the built in function,
> modify it so that every occurence of Length is 5*Length, and save
> it under another name.  In any loop, the step increment should be
> multiplied by 5 also.

That will produce a similar result, and possibly close enough for 
what you need, but it's *NOT* going to produce the same results.

RSI is a little complicated, so let's look at a simpler function, 
like xaverage.  If you run xaverage on Length weekly bars, you'll 
sample Length close values, one every 5 days.  The closes on Monday 
through Thursday have ABSOLUTELY NO EFFECT on the resulting xaverage 
value.  ONLY the Friday close is used in the calculation.

Now if you use daily data and calculate a 5*Length-long xaverage, 
you're including Mon-Thur closes in your calculation.  You can see 
that this is not going to produce the same results.  Similar, maybe, 
but not the same.  The most obvious difference is that the 5*Length 
xaverage changes gradually on every bar, whereas the weekly xaverage 
makes bigger jumps on every weekly bar.

> What you probably WANT is harder, if you want the weekly bars to
> correspond to the range monday-friday all the time.  In that case
> you would have to maintain your own array of weekly bars, and have
> your various functions written especially for them. 

It's actually possible to do it much simpler than that, at least for 
some functions.  If you can call the function only on Friday closes, 
you'll get the same results as you'd get on a weekly chart.  The 
trick is to use a **Simple** function instead of a **Series** 
function.

Series functions are implicitly called on EVERY bar, whether you call 
them explicitly or not.  It's strange, but it's part of the 
definition of Easy Language.  Simple functions, however, are called 
only when you actually explicitly call them.

If you do something like this:

if DayOfWeek(Date) = 5 then RSIval = RSI(Close, Length);

...then it's NOT just calling RSI on Fridays, but on every bar -- 
because RSI is defined as a Series function.

If you write your own function that doesn't require access to 
previous bar values -- which requires a Series function -- then you 
can declare it to be a Simple function.  Then, when you call it on 
Fridays, it is really only called on Fridays, and you'll get exactly 
the same results as if you called it on every bar of a weekly chart.

Unfortunately RSI *does* require access into past history.  
Fortunately it really only needs that for its initialization.  If you 
look at the definition of RSI, you'll see that after CurrentBar = 1 
it only refers to the previous bar's value of Price, UpAvg, and 
DownAvg.  That's easily handled just by using the value that's 
carried forward into each new bar; at the start of the bar, the 
variables all hold the value they had in the previous bar, and you 
don't need to access the historic values (e.g. UpAvg[1]) at all.

So it would be a matter of rewriting RSI to initialize itself without 
historic values, and then don't use the [BarsBack] history access in 
the function.  Declare the function to be Simple, call it only on 
Friday closes, and you'll get the identical results that you would 
have gotten in a weekly chart.

Or maybe using 5*Length is "close enough" for your needs, and simpler.
:-)

Gary