I am having quite a bit of confusion trying to use my custom multi-instrument indicator with a strategy.
Basically I have a multi-instrument indicator that looks at a watch list and is able to select which instrument(s) is most interesting to look at of a group. It displays fine as an indicator and I've been using it for several weeks. When used for display only on the charts it does not create any undue load.
Now I want to use it in a strategy. I created a do-nothing strategy to first see how this would basically work. I tried three approaches - all of them failed.
- I added the indicator in the Initialize() method using the Add() method, which kept a reference to the indicator in a private class variable. This failed because it seems that all historical bars were first "pumped" to the strategy, with nothing in the indicators, and only then were the bars "pumped" to the indicator. So whenever OnBarUpdate() was called in the strategy there was nothing in the indicator yet. First I saw all the OnBarUpdate() calls on the strategy, and only after they were done did I see all the OnBarUpdate() calls on the indicator. The indicator, however displayed correctly in the chart. No undue load was generated.
- So I tried basically the same thing, but tried to call the indicator's Update() method from within the strategy before attempting to get information from the indicator. This caused NT to basically hang, using all the CPU of one core (i.e. one thread going on some infinite busy loop). Bummer.
- Tried to create a new instance of the indicator in each OnBarUpdate() of the strategy. Again, NT got into a tizzy, spinning one thread and hanging.
If I try approach 2 with MACD as an alternative then I have no problem. Now, MACD would be using the same instrument as the strategy. My indicator adds a bunch of instruments of its own. Now that does not seem to be a problem for display (which does not have to be coordinated with the strategy per-se), however, I suspect that this is probably the core reason behind the problem here.
Any ideas what might be going wrong here?
(BTW please don't ask for the code of the indicator. It's quite complex and I do not have a "Toy example". In fact I don't thing there is such a thing as a reliable toy example for a multi-instrument indicator as any functioning indicator has to deal with the fundamental problem of bar synchronization, as NT provides no help on the issue and everybody ends up with their own solution (or a very buggy indicator))

Comment