PureBytes Links
Trading Reference Links
|
>>I have a function for calculating r-squared which I am unsuccesfully
trying to convert from series to simple.<<
Cab,
The problem lies in an important difference between simple and series
functions. All declared variables in a series function are themselves
series. However, all internally declared variables in a simple function
are simple (they have no history, except they retain their value from the
previous call). When you switched AV_R2 to type simple, the variable X is
not a series anymore.
Another issue: all type series functions and quantities inside AV_R2 are
"pulled out" and get evaluated BEFORE AV_R2 is called. This way, all type
series functions and quantities are guaranteed to be evaluated on every
bar.
The summation function expects a type series input, however, the quantity
"X*close" cannot be treated as a series because it cannot be pulled out of
AV_R2 for pre-evaluation, and that is because X is evaluated *within*
AV_R2.
To get around this, replace X with BarNumber in your code. Since both
Close and Barnumber are known a priori, the value "BarNumber * close" can
be pre-evaluated, qualifying as a legitimate series. This will then satisfy
the input requirement for the summation function and all other functions in
your code requiring a series input.
- Mark Jurik
*********************************
Jurik Research & Consulting
http://www.jurikres.com
*********************************
|