mjj38
- ago
Is there anyway to get the cache key for an indicator that was created using [Indicator].Series()?

The reason I ask is instead of having a local variable in the strategy for the indicator, I just wanted to grab the indicator reference from the BarHistory.Cache.
0
341
Solved
11 Replies

Reply

Bookmark

Sort
Glitch8
 ( 12.28% )
- ago
#1
You could examine the Cache property of the source BarHistory, get all the KeyValuePairs.
0
- ago
#2
If you want the "indicator name" used on the Chart, you can use the Description property.
CODE:
      SMA sma = new SMA(bars.Close, 10);       WriteToDebugLog(sma.Description);
0
mjj38
- ago
#3
Thank you but I'm not sure examining the Cache keys helps as I would need some logic to identify which key goes with which indicator unless there is a standard approach to parse out the cache key or the key is exposed as a property.
0
Cone8
 ( 23.19% )
- ago
#4
There is no standard requirement, but indicators that use IndicatorBase.CacheKey() just concatenate the indicator name (e.g., "ATR") with a string conversion of its paramenters, separated by the pipe character "|".

Anyway, you can inspect the ones you're interested in to determine how they're formed... if you really think it's easier than creating a local variable.
0
- ago
#5
QUOTE:
... examining the Cache keys helps as I would need some logic to identify which key goes with which indicator ...

Understood. Whether you use the Cache or Description property, you're going to need to do some kind of string search. At least with using the Description property, the indicator is already known. But you'll need a regexp (i.e. regular expression) to pick out the part of the description string that's just the key part, which is no big deal.

Using the Cache property, you'll need a string search to pick out the right indicator and its key string. Also no big deal.

So how do you want to approach this? Which string search looks like a winner? What's the overall goal here? What's wrong with just declaring a variable and referencing that?
0
Glitch8
 ( 12.28% )
- ago
#6
The Cache property is a Dictionary so it has KeyValuePairs. The Key is the string and the Value is the IndicatorBase instance. I’m not sure if that will help because I’m not really clear on what you’re looking for here.
0
mjj38
- ago
#7
I'm creating an analysis that requires me to generate a lot of indicator values for each trade. Instead of having a local variable within the strategy for each indicator, I was going to just going to call the Series method for each indicator which automatically adds them to the Cache and then within the Execute/BacktestComplete method access them directly from the Cache.
0
Glitch8
 ( 12.28% )
- ago
#8
It's possible, but there are different Caches, there's a Cache in the BarHistory, and each Open, High, Low, Close, and Volume has its own Cache. So, you'd need some custom methods to enumerate all those Caches and pull out the indicator instances.

I think it would be easier to create a List<IndicatorBase> in your Strategy code and add them to the List as you create them. You can then enumerate them from the List.
1
Best Answer
- ago
#9
Hi mjj3,
your post/question sounds like you try to do something I worked on for quite some time.
If you are interested to cooperate please send me an email (rene dot koch at finantic dot de).
Probably we can join forces...
0
- ago
#10
QUOTE:
I think it would be easier to create a List<IndicatorBase> in your Strategy code and add them to the List as you create them. You can then enumerate them from the List.

This is simple to do. You're simply placing all your indicators in a "private list" cache, then circulating through that List<IndicatorBase> with a ForEach statement. No big deal.

But I'm wondering if you're trying to create an indicator profiler? If so, what makes sense is to post (new topic) a feature request to add an API to WL's existing indicator profiler so a strategy can call the profiler from a loop and the profiler will serve up the next indicator it has in its list. The goal would be to compare different indicator performances for a given strategy.

The converse would be for the WL indicator profiler to call the strategy instead. Which approach is used depends on whether you want the profiler or the strategy under test to compile all the comparison results.
0
mjj38
- ago
#11
Thanks for your responses guys.

With regards to the cache, I just didn't want to recreate the wheel if there was an easy way to leverage the existing cache. I'll just create my own for each bar series as you suggested superticker.

DrKoch,
I'm always up for collaborating on projects. What I'm working on is a much faster way to backtest and search for new strategies (be it genetic algorithm or otherwise). The ideas and approaches aren't new but taken from some python approaches that I've seen. The speed improvement is in the 1000x, and if I can vectorize the calculations even more. This would make it viable to search for entire portfolio of strategies which is ultimately my goal.

I'm a lazy man by nature ... anything that makes my life easier ;-)

0

Reply

Bookmark

Sort