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

trouble with indicator error

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

    trouble with indicator error

    log says there is an overflow with the plot method

    Code:
    protected override void Initialize()
            {
                Add(new Plot(Color.FromKnownColor(KnownColor.Orange), PlotStyle.Line, "CIndy1"));
                Add(new Line(Color.FromKnownColor(KnownColor.Lavender), 0.0, "Line"));
                CalculateOnBarClose    = true;
                Overlay                = false;
                PriceTypeSupported    = true;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                if (CurrentBar<(2*periodMax)) return;
                
                double[] AMDMR = new double[periodMax-periodMin+1];
                double sum = 0;
                
                for (int i=1;i<periodMax-PeriodMin+1;i++)
                {
                    AMDMR[i]=Math.Abs(Momentum(Input,i)[0]/(MAX(High,i)[0]-MIN(Low,i)[0]));
                    sum=sum+AMDMR[i]/(periodMax-periodMin);
                    Print("AMDMR["+(i+periodMin)+"]="+AMDMR[i]);
                    Print(sum);
                }
                Print(sum);
                CIndy1.Set(sum);
            }

    #2
    mike82,

    Check for division by zero? Suggest you break down the steps and try to find where the logic falls apart through Print()s and try-catch blocks.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      the problem seems to only pertain to the sum bit

      it went away when i added other code

      or set the indicator to close[0]

      i had print() in there from the start it always printed fine, but the plot would only show on the first few days of the chart then disappear when you scrolled to the right.
      once it disappeared you had to reload the scripts on the chart (after you scrolled left) for them to show again.

      Comment


        #4
        Look in your Control Center logs for errors. Your sum bit is doing a division. Please check for division by zero or any other types of illegal math operations.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          periodMax-periodMin
          are both input parameters they're not equal and therefore not zero (also sum prints to the output window just fine)

          Comment


            #6
            You will need to check your Control Center for errors.
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              overflow error in the plot or onbarupdate methods

              Comment


                #8
                You need to isolate the line causing the issues and address it. If you feel its the sum line, break it down and find the exact component and then remove the issue.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  changing:
                  sum=sum+AMDMR[i]/(periodMax-periodMin);

                  to
                  sum=sum+(AMDMR[i]/(periodMax-periodMin));

                  seems to have fixed it

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by kujista, Today, 06:23 AM
                  0 responses
                  1 view
                  0 likes
                  Last Post kujista
                  by kujista
                   
                  Started by traderqz, Yesterday, 04:32 PM
                  1 response
                  10 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Started by f.saeidi, Today, 05:56 AM
                  1 response
                  4 views
                  0 likes
                  Last Post Jltarrau  
                  Started by Jltarrau, Today, 05:57 AM
                  0 responses
                  4 views
                  0 likes
                  Last Post Jltarrau  
                  Started by Stanfillirenfro, Yesterday, 09:19 AM
                  7 responses
                  52 views
                  0 likes
                  Last Post NinjaTrader_Gaby  
                  Working...
                  X