Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Odd result with an Indicator

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

    Odd result with an Indicator

    I have an indicator that I wrote some time ago and I am getting odd behavior.

    This indicator plots three values that I calculate and when doing a Print (Values[0][0] + Values[1][0] + Value[2][0]); I get the correct values
    that match where the Indicator is platting the values.

    When I use the Indicator in a Strategy and I reference those values (MyIndicator.Values[0][0] + MyIndicator.Values[1][0] + MyIndicator.Value[2][0]) I am getting
    a completely different value for MyInidicator.Values[0][0] and the debug from the Indicator.

    Without posting my full code, it may be difficult to give an answer, but I can't figure out why it is doing this.

    Thanks

    #2
    Hello ATMtrader0001,

    To confirm, the indicator is being added to the chart by the strategy with AddChartIndicator() and you are not manually adding this indicator to the chart, is this correct?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Yes, I am adding it via code in my Strategy.

      Comment


        #4
        Hello ATMtrader0001,

        Does the strategy call AddDataSeries()?

        Is BarsArray[1] being supplied to the indicator as the input series?

        Can you reduce the code to just the lines where the indicator is instantiated, added with AddChartIndicator(), and the plot value printed in OnBarUpdate(), then provide an export for me to test?

        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/<export_file_name.zip>
        Below is a link to the help guide on Exporting NinjaScripts.
        http://ninjatrader.com/support/helpG...-us/export.htm

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

        Comment


          #5
          The odd thing is that the Value[0][0] in the Indicator is a completely different value than is displayed on the chart.
          I have done a Print of every variable in the Indicator and the value displayed on the chart does not reflect any value
          of any variable in the Indicator.

          The problem is that this value is a better indicator of when to enter a trade. I do not get this.

          Comment


            #6
            Hello ATMtrader0001,

            If the indicator is the same, the parameters are the same, and the data is the same, the calculated values will be the same.

            This means that something is not the same.

            If the indicator is being added to the chart with AddChartIndicator() and is not being added to the chart manually, this would be the same instance on the chart that the strategy is using for values. I would not expect the values to be different.

            Are you able to reproduce this with a new test script that calls the SMA indicator?

            Is the custom indicator doing something unsupported?

            Also, please answer the questions from post# 4.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              So what I noticed is that the indicator is changing the value a few bars back.
              So the value is e.g. 33.546 at 9:33 and then at 9:38 the value changes to 31.752 for the 9:33 bar.

              I based this off the BollingerBand Indicator, but don't understand why it would change the value going
              back a few bars, which explains why I am missing the signal.

              Comment


                #8
                Sorry, no I am not using AddDataSeries.
                I am using AddPlot and ploting my calculated vaules that way.
                Values are calculated OnBarClose.

                Here's an output that shows that it changed the value for Values[0][X]

                Values[0][0]: -0.0114324852257772 Values[1][0]: 0.0186341075309713 Values[2][0]: 0.0487007002877197 11:21:00
                Values[0][1]: -0.0155822946976553 Values[1][1]: 0.0161194402706428 Values[2][1]: 0.047821175238941 11:21:00
                Values[0][2]: -0.0335042432095778 Values[1][2]: 0.0157298912907891 Values[2][2]: 0.064964025791156 11:21:00
                Values[0][3]: -0.0295135084607443 Values[1][3]: 0.0190766139922829 Values[2][3]: 0.0676667364453101 11:21:00
                Values[0][4]: 0.0186341075309713 Values[1][4]: 0.0230707711277631 Values[2][4]: 0.06950351819274 11:21:00
                Values[0][5]: 0.0161194402706428 Values[1][5]: 0.0298695568369993 Values[2][5]: 0.0704158267024267 11:21:00

                Values[0][0]: -0.0100282456605586 Values[1][0]: 0.0219873755266065 Values[2][0]: 0.0540029967137715 11:22:00
                Values[0][1]: -0.0114324852257772 Values[1][1]: 0.0186341075309713 Values[2][1]: 0.0487007002877197 11:22:00
                Values[0][2]: -0.0155822946976553 Values[1][2]: 0.0161194402706428 Values[2][2]: 0.047821175238941 11:22:00
                Values[0][3]: -0.0335042432095778 Values[1][3]: 0.0157298912907891 Values[2][3]: 0.064964025791156 11:22:00
                Values[0][4]: 0.0219873755266065 Values[1][4]: 0.0190766139922829 Values[2][4]: 0.0676667364453101 11:22:00
                Values[0][5]: 0.0186341075309713 Values[1][5]: 0.0230707711277631 Values[2][5]: 0.06950351819274 11:22:00​

                It is consistently changing that value Values[0][4] of the current bar, but none of the others.

                Comment


                  #9
                  Hello ATMtrader0001,

                  Just to re-iterate..

                  Post # 6:

                  Are you able to reproduce this with a new test script that calls the SMA indicator?

                  Can you reduce the code to just the lines where the indicator is instantiated, added with AddChartIndicator(), and the plot value printed in OnBarUpdate(), then provide an export for me to test?

                  Post # 4:

                  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/<export_file_name.zip>
                  Below is a link to the help guide on Exporting NinjaScripts.
                  http://ninjatrader.com/support/helpG...-us/export.htm

                  Once exported, please attach the file as an attachment to your reply.​​
                  Last edited by NinjaTrader_ChelseaB; 11-03-2022, 10:08 AM.
                  Chelsea B.NinjaTrader Customer Service

                  Comment


                    #10
                    Let's close this out. I found the error. A reference to Value[4] that was mistakenly in the code.

                    Thanks for the support.

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                    0 responses
                    630 views
                    0 likes
                    Last Post Geovanny Suaza  
                    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                    0 responses
                    364 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by Mindset, 02-09-2026, 11:44 AM
                    0 responses
                    105 views
                    0 likes
                    Last Post Mindset
                    by Mindset
                     
                    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                    0 responses
                    566 views
                    1 like
                    Last Post Geovanny Suaza  
                    Started by RFrosty, 01-28-2026, 06:49 PM
                    0 responses
                    568 views
                    1 like
                    Last Post RFrosty
                    by RFrosty
                     
                    Working...
                    X