Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Code reusability

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

    Code reusability

    Hi,
    I'd like to make a suggestion. In indicators such as MACD, the algorithm for EMA is repeated.
    Isn't it more productive to reuse the EMA indicator as has been suggested by ninjatrader specialists? It would be more productive in terms of reusability and make the indicator code more readable..
    I haven't looked at other indicators but I keep getting irritated by the MACD as I use it a lot.LOL
    Thanks,
    iq

    #2
    Hello iq200,

    The general expectation for scripts would be reusability like you are suggesting. I believe in this specific case this is to pin the logic for the MACD to have a specific set calculation in case the EMA indicator is ever changed/updated. That way the MACD continues to have its expected output based on the calculation that has been used for that indicator historically. That additionally removes the dependency on the EMA so this can be a single dependency when referenced in other scripts and exported.




    Comment


      #3
      Originally posted by NinjaTrader_Jesse View Post
      Hello iq200,

      The general expectation for scripts would be reusability like you are suggesting. I believe in this specific case this is to pin the logic for the MACD to have a specific set calculation in case the EMA indicator is ever changed/updated. That way the MACD continues to have its expected output based on the calculation that has been used for that indicator historically. That additionally removes the dependency on the EMA so this can be a single dependency when referenced in other scripts and exported.



      Hi Jesse,
      Thanks for your viewpoint.
      Coming from a financial sw dev background, I don't agree as all the people who exhibit this behaviour come up with the same excuse in pretty much all cases and from my experience I have always seen them being told not to do this in all circumstances, without exceptions.
      We just have to agree to disagree on this :-).
      Best wishes.
      Regards,
      iq

      Comment


        #4
        The EMA code is directly embedded into certain indicators
        for purposes of optimization.

        The point is to avoid the cache overhead of calling EMA.

        Why?
        Because MACD already has its own cache (due to the
        auto generated NinjaScript at the bottom of each indicator),
        so using EMA directly is sub-optimal because you're being
        double cached.

        Besides, the EMA formula is compact and concise, so it easily
        lends itself to being embedded like this. The readability remains
        fairly high (there is little to no extra obfuscation by directly inserting
        the EMA code) but plenty of positive payback by avoiding the double
        cache effect.

        Just my 2˘.

        Comment


          #5
          Originally posted by iq200 View Post
          I haven't looked at other indicators but I keep getting irritated by the MACD as I use it a lot.LOL
          'Irritated' is probably the wrong emotion.

          'Thankful' seems more appropriate.

          IMHO, of course.




          Comment


            #6
            Originally posted by bltdavid View Post

            'Irritated' is probably the wrong emotion.

            'Thankful' seems more appropriate.

            IMHO, of course.



            That's fair enough.
            Everyone has their own way of programming and looking at problems.

            Comment

            Latest Posts

            Collapse

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