Just getting up to speed with the NS programming model to create an NS version of a successful multi-timeframe MT4 indicator.
In MT4, I essentially created a single Indicator harness that is hosted on a chart that is tied to a timeframe. However, the main processing is delegated to a series of classes that are instantiated in the Indicator harness. The purpose of this is to have a "primary" chart timeframe, say 15 minutes. In the Indicator harness, I keep a reference to instances of my processing class that are timeframe-specific, so, the primary timeframe and, a collection of "other" timeframes. The idea is that when I get a signal from the 15-minute processing class instance, I can then reference the "other" timeframe processing instance(s) and see whether their signals are aligned with the signal from the "primary" timeframe instance. In a nutshell, if I get, say, a long signal from a 15-minute instance, before I send a notification of that signal, I check with a higher timeframe to see whether it too, aligns. Therefore, before I take a 15-minute signal, I might want to check that the 30-minute and 60-minute timeframe are in alignment.
In MT4, I can create multiple non-indicator classes and reference them. In NS, it seems that I cannot do this without creating and referencing external assemblies. However, on reading the NS documentation, it seems that by bringing in multiple Bars objects into a Ninjascript, in my case, just different timeframes of the same instrument, OnBarUpdate will be called for each Bars instance. This sounds very promising indeed but conceptually, I have a couple of "blanks" that I am unable to resolve due to my (current) limited understanding of the NS programming model.
If I have three Bars objects in a single NS, so, fifteen, thirty and sixty minutes and my primary timeframe is fifteen minutes, I get a signal on the fifteen-minute timeframe, the OnBarUpdate is called and running in the context of that timeframe, is it possible to reach into the "other" Bars context to establish whether they are "aligned" based on my alignment criteria? For example, are the private variables and public properties of the indicator isolated by virtue of the Bars context? If so, is it possible to read the values of the same Public properties associated with a different Bars object in the same indicator?
I hope I have made myself clear enough! In MT4, my indicator is hosted on a chart that is tied to a timeframe. That fact cannot be changed. So, when the indicator runs on an M15 chart, I create an instance of the processing class and tell it that it is servicing the M15 timeframe. This is the same for each "other" timeframe. So, in the processing class(es), instead of referencing Series arrays like High[], Low[], Close[], the classes always use the functions, iHigh(timeframe,shift), iLow(timeframe,shift), iClose(timeframe,shift) and so on. Therefore, from a primary indicator chart of M15, I can still "know" exactly what is happening in the "other" instances by referencing the processing object like so:-
PrimaryTracker.TrendDirection();
OtherTracker01.TrendDirection();
OtherTracker02.TrendDirection();
where PrimaryTracker, OtherTracker01 and OtherTracker02 are instances of the same TrendTracker class, that are each constructed with a config object that contains specific values like timeFrame, timeFrameType and noRender, the latter of which ensures that trendlines are drawn on the current host primary chart (M15) but the other Tracker instances don't attempt to render their "other" timeframe-specific trendlines on the primary M15 chart.
I am asking this question because I realise that there will be NS-specific and optimised ways of "skinning the same cat" without trying to do it in exactly the same way as I did when using MT4's C++-like class-based approach. I'd appreciate any help/advice/comments on what I have asked and am perfectly happy to provide any additional information that may be required.
With kindest regards and thanks,
--G
Comment