- ago
I want to create an AddParameter() entry in GenerateParameters such that AAPL appears in the description of the RSDif indicator I'm defining. From the screenshot, you can see "symName" appears instead, which is the default value set in the field variables of this indicator. Trying to insert bars.Symbol into the AddParameter line fails because the constructor of the indicator is never called in a Drag-and-Drop operation. So how should the AddParameter() description line be crafted so AAPL appears in there?


CODE:
namespace WealthLab.Indicators {    public class RSDif : IndicatorBase //Relative Strength Difference; RSDif indicator    { protected static readonly string indexSymbolDirectory = "Indices IQFeed";       string symbolName = "symName";       public RSDif() : base() { }       public RSDif(BarHistory bars, string indexSymbol, string description = null) : base()       {          symbolName = bars.Symbol;          Parameters[0].Value = bars;          Parameters[1].Value = indexSymbol;          Parameters[2].Value = description;          Populate();       }       //generate parameters       protected override void GenerateParameters()       {          AddParameter("Bars", ParameterTypes.BarHistory, null);          AddParameter("Index", ParameterTypes.String, "SPX.XO");          AddParameter("Description", ParameterTypes.String, "RSDif(%deviation of " + symbolName + " from index)");          //AddParameter("Description", ParameterTypes.String, "RSDif(%deviation of " + bars.Symbol + " from index)");       }
0
367
Solved
8 Replies

Reply

Bookmark

Sort
- ago
#1
AAPL cannot appear there. GenerateParameters has no knowledge of your Bars object. It's separate from the constructor.
0
- ago
#2
QUOTE:
GenerateParameters has no knowledge of your Bars object.

That's because "null" is being passed as a parameter in the line ...
CODE:
AddParameter("Bars", ParameterTypes.BarHistory, null);

What can we do to pass something besides "null" in this AddParameter line? I cannot use "bars" because that variable isn't visible in this context. Please tell me what bars object is visible? I think we have a scoping problem with the current design.

---
This isn't a problem in strategy code because a Bars object is passed into the constructor of the indicator, so bars.Symbol is defined and visible there.
0
- ago
#3
There is no probem, I was telling that you cannot accomplish this because the GUI is purposefully detached from these variables.
0
- ago
#4
QUOTE:
the GUI is purposefully detached from these variables.
If I'm reading this correctly, you're saying this is a WPF limitation imposed by Microsoft that you have no control over.

I appreciate the advantage of having WPF run as an asynchronous process over the main application, but I don't like the limitations this imposes. So you're suggesting there's no "simple" workaround?
0
Glitch8
 ( 12.10% )
- ago
#5
Hi Superticker, this has nothing to do with WPF.

The Indicator constructor and the GenerateParameters and AddParameters calls are meta methods, they operate and execute before WL7 has information about the actual values of the parameters. Their purpose is to define what the parameters are. So, they cannot know what TimeSeries or BarHistory instance you'll eventually pass. This is only known in the Populate method.

This is just the design, and it's working correctly so there's no issue or workaround.
0
Best Answer
- ago
#6
QUOTE:
The Indicator constructor and the GenerateParameters and AddParameters calls are meta methods, they operate and execute before WL7 has information about the actual values of the parameters.

This design creates a caching problem for another indicator, EWEMA, when Dragging-and-Dropping. From the CacheKey code below:
CODE:
public static EWEMA Series(TimeSeries source, TimeSeries weights, int period) { string description = "EWEMA(" + source.Description + "," + weights.Description + "," + period + ")"; string key = CacheKey("EWEMA", source.Description, weights.Description, period); if (source.Cache.ContainsKey(key)) //Is this TimeSeries in cache? return (EWEMA)source.Cache[key]; //No, so create, cache, & return Volume-Weighted EMA EWEMA EWEMA = new EWEMA(source, weights, period, description); source.Cache[key] = EWEMA; return EWEMA; }
The problem with the CacheKey code is that source.Description and weights.Description are unknown on a Drag-and-Drop operation because that description depends on bars.Symbol, which is unknown when Dragging-and-Dropping. How do you resolve this? Or should a Drag-and-Drop operation avoid caching altogether since a unique CacheKey cannot be formulated then (from bars.Symbol, which is unknown at this time)?
0
Glitch8
 ( 12.10% )
- ago
#7
You do not have to pass the TimeSeries or BarHistory instance to CacheKey. That's because the key is ultimately used in the TimeSeries/BarHistory instance Cache property itself. So the source does not need to be passed as a parameter.

Also, the drag and drop system does not ever even call Series, Series is strictly for code-based Strategies to use.

So, there's really no problem.

Look at the implementation for ATR Series for example:

CODE:
//static Series method public static ATR Series(BarHistory source, int period) { string key = CacheKey("ATR", period); if (source.Cache.ContainsKey(key)) return (ATR)source.Cache[key]; ATR atr = new ATR(source, period); source.Cache[key] = atr; return atr; }
0
- ago
#8
QUOTE:
You do not have to pass the TimeSeries (or BarHistory) instance to CacheKey ... because the key is ultimately used in the TimeSeries (or BarHistory) instance Cache property itself.
The second TimeSeries parameter, Weights, can be based on anything, so its description does need to be included in the CacheKey. However, that's only an option if it's called from strategy code. For a Drag-and-Drop operation, the Weights parameter is forced to be Volume for the Bars object in question, bars.Symbol. So you're right for the Drag-and-Drop case.

QUOTE:
Also, the drag and drop system does not ever even call Series, Series is strictly for code-based Strategies to use.
And that makes CacheKeying the Drag-and-Drop case a non-issue. So what's put into the Description parameter for Drag-and-Drop won't matter.

I guess I would like to put something uniquely descriptive in the Description field for Drag-and-Drop, but perhaps that's not going to be possible here.

And thank you very much for all the clarification. It's greatly appreciated.
1

Reply

Bookmark

Sort