Let's look at my example:
In the files included, an indicator MyTest looks whether Close price is higher than the upper Bollinger band or is lower than the lower Bollinger band. It paints my form accordingly using BackColorAll (green or red).
But in addition I wanted to cause other indicators (2 instances of MyBackColorAll in my example) to paint BackColorAll in their forms.
Look at attached screen2.jpg – it shows the results. The 2 min and 3min series were painted, when Bollinger conditions on 1min series occured.
Now let's call the indicator MyTest a master indicator and instances of MyBackColorAll slave indicators.
Look at the the code in SpecialAction.cs file. It implements a singleton class SpecialAction. The singleton object contains a dictionary :
private Dictionary<string,object> actionDict ;
This dictionary is global and accessible by any indicator/strategy everywhere. You may pass any data in it, boxing the object in a master indicator and unboxing it in slave indicators instances. Every slave instance would look for its matching key.
When a condition occurs in a master indication, the dictionary item is either added or updated accordingly. When a condition does not appear anymore, the item is removed.
In my particular example I passed an integer value, expressing a condition which occurred in MyTest indicator.
MyBackColorAll indicator unboxed this value and painted BackColorAll accordingly.
Look at a key of the item in the master indicator. In this particular code it consists of a name of the slave indicator and its instrument name. the key is “MyBackColorAll|$EURUSD” .
The slave indicator looks for a matching key, gets a value and performs painting if the key is found.
Of course the master can add more than one item and direct them to more than one slave indicator type.
I can be more restrictive. For example, if I would be interested to do my painting only on 5min data series, I would build my key as “MyBackColorAll|$EURUSD|5min”
Current example checks for conditions in the master indicator once for a bar. The slave indicator checks for them only at the first tick on bar. It may delay an action performed by a slave. An alternative is to use OnMarketData, but I'm afraid it may be too heavy CPU load in case of a lot of slave instances. Of course it could work well in my example of 2 slave instances.
Last, but not least – for Ninja people. Please pass this post to developers. I'm sure they can implement such mechanism in more elegant and optimal way than me. I have no access to Ninja intenals.
Comment