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

Error on calling 'OnStateChange' method: Added Plots or Lines must have a unique name

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

    Error on calling 'OnStateChange' method: Added Plots or Lines must have a unique name

    Hello,

    I have read the documentation and the other thread with the same name. So my 2 plots and the Values are where they should be but still am getting the above error.

    My two plots are as per the documentation:


    if (State == State.SetDefaults)

    {
    AddPlot(Brushes.Blue, "PlotA"); // Defines the plot for Values[0]

    AddPlot(Brushes.Red, "PlotB"); // Defines the plot for Values[1]
    }

    protected override void OnBarUpdate()

    {
    Values[0][0] = GreenValue;

    Values[1][0] = RedValue;
    }

    The error happens even if I comment the lines AddPlot and Values!.

    I tried to copy and paste in a blank editor page all the code except NinjaScript generated code. But the problem persists.

    ​​​
    So which are the causes that can cause the above error?

    #2
    Originally posted by roblogic View Post
    Hello,

    ...

    protected override void OnBarUpdate()

    {
    Values[0][0] = GreenValue;

    Values[1][0] = RedValue;
    }

    ...
    So which are the causes that can cause the above error?
    not correct syntax, replace with these;
    protected override void OnBarUpdate()
    {
    //Add your custom indicator logic here.
    Values[0][0] = High[0]; //GreenValue;
    Values[1][0] = Low[0]; //RedValue;
    }

    Comment


      #3
      Hello roblogic,

      Thanks for your post.

      Make sure that the error is from the actual file you are working on. When compiled, all scripts are compiled at the same time and an error is any file will be shown below the code you are working on. The first column of the error message identifies the file with the error.

      If member nkhoi's reply did not answer your question and you've confirmed the error is within the file you are working on, please post or attach your source code file.
      Paul H.NinjaTrader Customer Service

      Comment


        #4
        Thanks for your answers but I found the problem and probably it is something NT8 development should address. Please report that.

        The problem I had is that I created a file with the Editor. It compiled well but then when loading the indicator in the log there was the error above, so the indicator was not working. The problem is that I did a Save As of the file and saved it with a different name so the file that was compiling but giving the error was still in the indicators list. So I had to delete this original file that originated the problem to resolve the issue. Once this file was deleted the problem was gone and the indicator was loading and working fine.

        Comment


          #5
          Hello roblogic,

          Thanks for your reply.

          Could you clarify what the issue is that you feed should be reported to development?
          Can you provide a complete example that demonstrates the issue to be reported and the steps to recreate?
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            unfortunately i don't have the original files as I deleted them but here is what I did:

            1 Create a new indicator file that was compiling well but has the above error at runtime.
            2 Save as this file and create a new one. Now both files compile fine but have the error.
            3 Fix the error in the newer file. Both files compile fine but the older file still has the error. And AFAIR the error shown in the log refers to the newer file (not the old).
            4 So you have the fix or delete the older file in order for the newer file to run.

            Comment


              #7
              Hello roblogic,

              Thanks for your reply.

              I tried to recreate the issue of "error shown in the log refers to the newer file (not the old)." and was not able to. When the new file without the error runs, no run time error message is produced and this would be expected.

              If you should run into this again, please feel free to add to your post here or write into PlatformSupport[at]NinjaTrader[dot]com with the details so we can recreate.
              Paul H.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by tsantospinto, 04-12-2024, 07:04 PM
              5 responses
              67 views
              0 likes
              Last Post tsantospinto  
              Started by cre8able, Today, 03:20 PM
              0 responses
              6 views
              0 likes
              Last Post cre8able  
              Started by Fran888, 02-16-2024, 10:48 AM
              3 responses
              49 views
              0 likes
              Last Post Sam2515
              by Sam2515
               
              Started by martin70, 03-24-2023, 04:58 AM
              15 responses
              115 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Started by The_Sec, Today, 02:29 PM
              1 response
              8 views
              0 likes
              Last Post NinjaTrader_Jesse  
              Working...
              X