I am looking for best practices to optimize runtime in the following situation
I use a set of indicators (EMA, MACD, … let’s call them BaseIndicators B1, .. Bi, .., Bn) and combine them into more complex indicators (let’s call them CompositeIndicators C1,.., Cj, …, Cm). Each CompositeIndicator Cj uses a different subset of the BaseIndicators Bi.
Now, my question is: what is the most efficient way to calculate and cache the Bi’s used in the Cj’s?
A) “Natively” calculate the Bi’s within the Cj’s by calling the EMA/MACD functions in the DataLoaded state, so this would be
if ( State == State.DataLoaded )
{
B1 = EMA(X1);
B2 = MACD(X2, Y2, Z2);
…
}
B) Set up some type of “ThinEngine” that calculates all of the Bi’s, once and for all. Then call this engine
if ( State == State.DataLoaded )
{
B1 = ThinEngine.B1;
B2 = ThinEngine.B2;
…
}
and subsequently put the complexity of the further calculations and logic into the CompositeIndicators
C) Set up a “FatEngine” that calculates the Bi’s, includes the logic and the complexity. Then call this engine for the BaseIndicators but also for some IntermediateIndicators
if ( State == State.DataLoaded )
{
B1 = FatBaseEngine.B1;
B2 = FatBaseEngine.B2;
Int1 = FatBaseEngine.Intermediate1;
Int2 = FatBaseEngine.Intermediate2;
…
}
That is, use the CompositeIndicators mostly as display lines for stuff that has already been calculated within the FatEngine.
From a programming perspective, version C seems most consistent, elegant and least error-prone. All complexity is dealt with in one central place. However, I am insecure about the caching mechanism of the Bi’s … and whether this would result into multiple calls of the FatEngine whenever when I need nothing but a stupid EMA ;-)
What's the most efficient way to do this?
Finally, do I need to call the Engine from the “top level” Indicator panel to have them cached, or is it sufficient to call them from within any of the CompositeIndicators?
I hope it is possible to understand this request.
Thank you in advance,
SDF02
PS: to prevent the caching of multiple versions, FatEngine does not have input parameters.
PPS. I have checked
https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?ninjascript_best_pra ctices.htm
http://web.archive.org/web/201004282...ds/rwt/rwt004/
.. but this has not been conclusive to me

Comment