Size:
Color:
That's a one-liner, actually we're not including such indicators in Community.Indicators (a minimum of 4 simple math operations):
CODE:
Please log in to see this code.
Size:
Color:
I see your point. That's OK.
May I suggest a couple more of WL4 custom indicators?
- ZScore
- RunsZscore
Really useful.
Size:
Color:
Not sure what RunZscore is, but ZScore is a one-liner again (we already have it inside the MAC-Zscore and AggZ in Community.Indicators):
CODE:
Please log in to see this code.
Size:
Color:
In WL4 there were functions - a block of code with its own variables and result, which was segregated from the main script for purposes of clarity & convenience. The main script then utilized the re-usable code of the function by passing various series or parameters, so the code didn't have to be duplicated each time, just the new series and/or parameters needed to be passed, with resultant new series or values.
How does one create the equivalent of a function in WL5? Using Zscore as an example, can you explain how to do it, and then using the Zscore "function" in the main script to get different values (for Close, Open, etc.)? [Use of the simple Zscore series is for convenience; the method will likely be used for longer code snippets.] Or is there a tutorial or KB article explaining how to do this?
Size:
Color:
QUOTE:
How does one create the equivalent of a function in WL5?
You need to create a library (like Community.Components) which will store your functions and methods, add a reference to it in your Strategy (or place it in Wealth-Lab's main folder), and a "
using" directive on top of the strategy.
QUOTE:
Or is there a tutorial or KB article explaining how to do this?
No, since such a library is just a pretty standard Class Library, nothing WLP-specific in here. General principles apply. Download the Community.Components project from the Wiki to have a working example. But since you're wondering about "blocks of code" (which are called functions and methods), I'd suggest you start right here:
How do I start with C# ?I'm a Wealth-Lab 3/4 user, how to learn C# ?
Size:
Color:
I had something like this in mind:
CODE:
Please log in to see this code.
I need assistance with these issues I ran into:
1. Couldn't create the Value method (the one that returns value of the series at a specific bar)
2. When you create a series using the 'new' argument, do you always have to specify your own description, or can you retrieve the description as coded in the function?
Size:
Color:
CODE:
Please log in to see this code.
Better call .Series[bar] instead of .Value here.
QUOTE:
1. Couldn't create the Value method
Check out the TASCIndicators project's source code in the Wiki for an example how should the .Value method be coded.
QUOTE:
2. When you create a series using the 'new' argument, do you always have to specify your own description, or can you retrieve the description as coded in the function?
Please check out the QuickRef >
DataSeries Object.
Size:
Color:
Called the Series:
CODE:
Please log in to see this code.
Values appear to be the same. Did you advise that for speed, or are the calculations more accurate?
1. Value method created.
2. I have not been able to find a single instance where the 'new' argument was NOT accompanied by specifying a string. So it would appear that you can't get the series' default description using 'new', you have to use
DataSeries (name) = ...
Correct me if I am wrong.
Size:
Color:
QUOTE:
Values appear to be the same. Did you advise that for speed, or are the calculations more accurate?
For speed's sake. The
.Value method is used when you need a one-time calculation that does not look up the value in the cached data series.
QUOTE:
So it would appear that you can't get the series' default description...
Upon calling the static Series method, Wealth-Lab generates a description string based on the input parameters - e.g. "
Z-Score(Close,10)", which is then being used for caching purposes.
When creating a new DataSeries, you're really creating a new, empty DataSeries filled with zeroes, hence the need to specify a unique description.
(
Note: a series' description is available by reading its .Description property.)
Size:
Color:
Most indicators in WL5 are named thus:
Indicator(DataSeries,period).
SO Wealth-Lab caches them when they are first created, and reuses them. But the name is not unique as it doesn't have the symbol name, so all symbols will create indicators with identical names. Wouldn't that create a problem if you are running say a Rotation script and the same indicator series gets used each time as the name is not unique?
Size:
Color:
No, they are unique as it's the Bars.Cache property where they get placed. Simply put, WL actually has a collection of "Indicator(DataSeries,period)" where each entry belongs to a Bars object.
Size:
Color:
Got it.
Thanks for the assistance and all the other useful info.
Size:
Color: