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



  • Filter
  • Time
  • Show
Clear All
new posts

    EMA of HMA

    I built this in the Strategy Builder first to make sure I was not doing it wrong, with no luck.

    I am trying to get rid of noise in my HMA. So I set an "EMA(HMA1, 2)" and added the EMA indicator to the chart. This worked as long as the HMA input was set to 14 and no lower, otherwise it will not let me enable the strategy? Likewise, while HMA input is set to 14, I tried to set the EMA to 3 but the strategy will not let me enable it. Instead, I have to change HMA input to 16.

    else if (State == State.DataLoaded)
    HMA1 = HMA(Close, HMAP);
    EMA1 = EMA(HMA1, 3);
    HMA2 = HMA(Close, HMAP/2);
    EMA1.Plots[0].Brush = Brushes.Blue;
    HMA2.Plots[0].Brush = Brushes.Yellow;
    So if the above is activated with the HMAP input set to 14, it immediately does not work. If I change the HMAP input to 15, I can enable the strategy.

    Is there any reason that I would be prevented from enabling a strategy with EMA indicator over an HMA indicator?
    Last edited by smcllr; 10-01-2022, 02:45 PM.

    Check the Log Tab of the NinjaTrader control center for any error messages related to the strategy and if the error message is not clear to you, post it here.


      Ah. Thank you.

      The Message

      Strategy 'IndexingTest': Error on calling 'OnBarUpdate' method on bar 695: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
      I am not sure what it means since there are 695 bars on the chart and the only index I would be trying to access is calculate off a bar that is on the chart. Again, it works when the HMA Period is one int higher.

      Last edited by smcllr; 10-01-2022, 03:39 PM.


        Hello smcllr,

        As this is made with the Strategy Builder, I may need to report this behavior.

        May I confirm you are using (Help -> About)

        May I have you provide an export of the script to test on my end?

        To export a NinjaTrader 8 NinjaScript so this can be shared and imported by the recipient do the following:
        1. Click Tools -> Export -> NinjaScript...
        2. Click the 'add' link -> check the box(es) for the script(s) and reference(s) you want to include
        3. Click the 'Export' button
        4. Enter a unique name for the file in the value for 'File name:'
        5. Choose a save location -> click Save
        6. Click OK to clear the export location message
        By default your exported file will be in the following location:
        • (My) Documents/NinjaTrader 8/bin/Custom/ExportNinjaScript/<>
        Below is a link to the help guide on Exporting NinjaScripts.

        Once exported, please attach the file as an attachment to your reply.​
        Chelsea B.NinjaTrader Customer Service


          Sorry. In some last few attempts to figure out what the problem was before sending it, I disabled line by line and found the line that was causing the issue. I used the print to output function and discovered the indexing error. I had no idea a negative one would throw an indexing error.

          It had nothing to do with the EMA.

          Thank you anyway,


            Hello smcllr,

            A negative index for a bars ago value should not be possible in the Strategy Builder.

            May I confirm this is created with the Strategy Builder?
            Chelsea B.NinjaTrader Customer Service


              Oh. Sorry. I should have included that.

              I did not use the Strategy Builder for the whole script. I was trying to get ahead of anyone saying that there might have been errors in the adding of the EMA, which I had already ruled out by using the Strategy Builder to build out an identical Custom Strategy to verify (ie copy and paste) the proper configuration (the portion that I quoted). I included that to eliminate having to further convince others here that my recent change was not to blame. I was not yet convinced that the addition of the EMA did not have some strange, negative affect further down the script though. Now I know it was unrelated.

              TLDR: Strategy Builder was only used to write the portion I quoted in a separate custom strategy; to rule out for anyone who might help me, what I had ruled out for myself.


                Hello smcllr,

                Thank you for letting us know this is not created with the Strategy Builder.

                For an unlocked script, see the following post about indexing errors.
                Chelsea B.NinjaTrader Customer Service


                Latest Posts


                Topics Statistics Last Post
                Started by LavniaCardos, Today, 02:32 AM
                0 responses
                1 view
                Last Post LavniaCardos  
                Started by pstrusi, 11-13-2022, 05:23 PM
                23 responses
                Last Post pstrusi
                by pstrusi
                Started by Murphy67, Today, 01:10 AM
                2 responses
                Last Post DiverG20  
                Started by DiverG20, Today, 02:01 AM
                0 responses
                Last Post DiverG20  
                Started by AlexEro, Today, 12:29 AM
                0 responses
                Last Post AlexEro
                by AlexEro