Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Building Composite Indicators Effectively .. Use an Engine?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Building Composite Indicators Effectively .. Use an Engine?

    Dear NT Support Team,
    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.

    Click image for larger version  Name:	0 Logical Structure.png Views:	0 Size:	70.3 KB ID:	1202949

    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);

    }


    Click image for larger version  Name:	A Call from within.png Views:	0 Size:	68.3 KB ID:	1202950

    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

    Click image for larger version  Name:	B Thin Engine.png Views:	0 Size:	66.7 KB ID:	1202951


    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.

    Click image for larger version  Name:	C FatEngine.png Views:	0 Size:	79.7 KB ID:	1202952



    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
    Last edited by SDF02; 05-26-2022, 02:10 AM.

    #2
    Hello SDF02,

    Unfortunately I wouldn't be able to provide a specific suggestion here as this question is highly dependent on the specific indicators you used and how they are used along with your data requirements.

    The indicator cache is very simple, only indicator calls which have the same exact parameters and data would be reused if called again later. You can see the cache that is used in each indicator at the bottom of the file, there is only a very basic cache implemented. If something is different then a new instance is generated.

    Not all indicators can take input in the same way and depending on how you are using all of the indicators that may use cache or not. You could form some samples of the items you pictured to see if you can tell any performance difference when calling them however without doing all of your scripts logic it would be pretty difficult to tell which is more efficient until its all set up.

    If you only use 1 series with all indicators and none of the parameters ever change then the easiest solution would be to just use the indicator directly in the logic without making any kind of additional base classes, those would just be additional OOP objects for your convenience at that point.



    Comment


      #3
      Thank you, NinjaTrader_Jesse for your quick response

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      639 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      366 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      107 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      569 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      572 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X