Performing square root of DataSeries
Author: snout_hound
Creation Date: 2/7/2009 11:56 PM
profile picture

snout_hound

#1
I'm trying to do the following sort of calculation in my strategy:

CODE:
Please log in to see this code.


The C# compiler informs me that it does not know how to compute the square root of a DataSeries. Do I need to write a loop for this sort of thing?

I'm not seeing info in the documentation on this.

Thanks,

Dave
profile picture

snout_hound

#2
I think I have resolved my question by doing the square root calculation element by element within a for loop. Like this:

CODE:
Please log in to see this code.


If there is a more elegant approach, I would be happy to learn about it.

Thanks,

Dave
profile picture

Eugene

#3
QUOTE:
The C# compiler informs me that it does not know how to compute the square root of a DataSeries. Do I need to write a loop for this sort of thing?

That would be a bug if this Microsoft's method accepted DataSeries. Since it's not the case, this behavior of the C# compiler is beyond all doubt. ;)

QUOTE:
If there is a more elegant approach, I would be happy to learn about it.

I would create a new DataSeries like "SqrtDataSeries" that contains the logic of applying Math.Sqrt to a data series and put it somewhere to call it later and get rid of that loop. Actually, it looks like a good candidate for Community.Indicators.
profile picture

Eugene

#4
Update: Look for Sqrt.Series in the upcoming build of Community.Indicators (when available).
profile picture

snout_hound

#5
Thanks. I'll look for Sqrt.Series when it is available. How do I learn about when the new build of Community.Indicators happens. Do updates of that sort get posted on this forum in some standard announcement location?
profile picture

Eugene

#6
If you have it installed, the Extension Manager will pop up when you start WLP/WLD next time, notifying about an available update. This applies to every Extension installed on your computer.

If not, the Extension can be downloaded from the Get Extensions page for the EM tool to be able to notify about updates.
profile picture

Eugene

#7
Sqrt.Series added to Community.Indicators v2009.02.
profile picture

snout_hound

#8
It appears to me that I have the extensions manager installed in the WealthLab.net that I am running. When I start it up, I only have extensions for downloading data and for TASC Magazine Indicators. Is Community.Indicators different? I'm not quite sure how to deal with adding new extensions to WL.

Thanks,

Dave
profile picture

snout_hound

#9
OK, never mind. I think I figured this out and installed the extension. I'll go study it now.

Thanks,

Dave
profile picture

Eugene

#10
Good to hear that. For anybody else who could face the same "scenario":

1. Choose "Other Extensions" in the EM tool to see 3rd party extensions.
2. If the Extension you need is not on the list, go to this web site, section "Extensions", and download the extension's *.WLE file.
3. Install it by any means allowed as suggested in the online instruction.
4. Now, the Extension "lives" inside WL5 and the EM tool will notify you when it's updated.
profile picture

ss161

#11
what do you think about also adding

Pow.Series
Exp.Series
and
Log.Series to Community.Indicators

profile picture

Eugene

#12
After giving it a try, I see that data series built with Math.Exp and Math.Log will frequently trigger an exception on higher-priced futures/stocks: "Cannot plot a DataSeries that contain infinity". I imagine that it could confuse a not so exprienced user when he drags and drops such an indicator on the Volume series or on a futures chart and faces an exception.

Math.Pow looks quite safe in this regard.
profile picture

Eugene

#13
Power and Log added to Community.Indicators.
profile picture

quaresma

#14
Hi, I'm use in my strategy the calculation of logarithmic price changes and would like to draw them. Get the error "Cannot plot a DataSeries that contains infinity". How can this problem be solved? Thank you

CODE:
Please log in to see this code.

profile picture

Eugene

#15
Hi,

Aside from badly peeking into the future, this line doesn't make too much sense to me:
CODE:
Please log in to see this code.


One cannot compare the value of an indicator 30 (300, 3000...) bars ago with the value near the right edge of the chart and use that in a DataSeries since it's unknown at that time (a future value). Or maybe what you actually intended to do is divide the SMA by the SMA value 2 bars ago like shown below?
CODE:
Please log in to see this code.


Now on to your question. As the resulting DataSeries contains values like NaN or Infinity which cannot be plotted you can handle it manually. Just test for an unsuitable value and replace it with 0, -1, for example:
CODE:
Please log in to see this code.
profile picture

quaresma

#16
Thank you, I didn't somehow think of that.
I wanted to get a series of data by dividing the last value by the penultimate value. Is that what you mean about looking into the future? I. e. I cannot take the extreme right value, namely for example the current Close and divide it by the previous Close[-1]. To put it simply, I wanted to count the daily changes for the last day.
In this case I tried to implement it with this line in the code
CODE:
Please log in to see this code.

Do I understand correctly that in order to count the past day changes without looking into the future I can write like this:
CODE:
Please log in to see this code.
profile picture

Eugene

#17
Forget about using Bars.Count (with its derivatives) in indicators, this is incorrect. I've shown you the approach using the right shift operator:
CODE:
Please log in to see this code.


But I was confused by your usage of -2. Your reply suggests that in fact you're after this:
CODE:
Please log in to see this code.


Please find more details about the shift operator in the QuickRef > DataSeries.

And since the daily change for the last (or any given) day is known as Momentum indicator, you could simply use that:

CODE:
Please log in to see this code.
profile picture

quaresma

#18
Thanks for the explanation, this is important for my understanding
profile picture

Eugene

#19
You're welcome. It's been my pleasure to help you.
This website uses cookies to improve your experience. We'll assume you're ok with that, but you can opt-out if you wish (Read more).