Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Interesting line of code

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

    Interesting line of code

    I found the the following line of code in your TRIX indicator very interesting:

    EMA tripleEma = EMA(EMA(EMA(Input, period), period), period);

    Could you explain why it is coded like this and what it does. Specifically I am interested in the left hand side of the equation - EMA tripleEma =.

    thanks

    #2
    This is just an EMA on an EMA on an EMA which is then assigned to the variable (tripleEma).

    Comment


      #3
      The reason this was done was to optimize performance of the indicator. Internally NT holds all called indicators in a cache. Since tripleEma is called multiple times in the code, it just saved unnecessary cache look ups.
      RayNinjaTrader Customer Service

      Comment


        #4
        So that's why you coded it as EMA tripleEma = instead of just tripleEma =?

        Any rules as to when one should use what is shown? I assume that this type of code code be done on any indicator?

        thanks,

        Comment


          #5
          When you declare a variable, you need to decalare its type.

          For example:

          double myDouble = 5.1;

          EMA myEma = EMA(20);

          myEma is the variable name and its of type EMA
          RayNinjaTrader Customer Service

          Comment


            #6
            scJohn,

            fwiw, this is a great technique for indicator calls with lengthy parameter lists as it eliminates the need to restate the list of parameters with each call.

            You might find this thread helpful starting with post #8.



            Regards,

            Whitmark
            whitmark
            NinjaTrader Ecosystem Vendor - Whitmark Development

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by judysamnt7, 03-13-2023, 09:11 AM
            4 responses
            59 views
            0 likes
            Last Post DynamicTest  
            Started by ScottWalsh, Today, 06:52 PM
            4 responses
            36 views
            0 likes
            Last Post ScottWalsh  
            Started by olisav57, Today, 07:39 PM
            0 responses
            7 views
            0 likes
            Last Post olisav57  
            Started by trilliantrader, Today, 03:01 PM
            2 responses
            22 views
            0 likes
            Last Post helpwanted  
            Started by cre8able, Today, 07:24 PM
            0 responses
            10 views
            0 likes
            Last Post cre8able  
            Working...
            X