Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Variable reference problem

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

    Variable reference problem

    Hi: I'm creating an Indicator. I declare a variable JU. In the Initialize section I assign JU a calculated value intended to be used as a constant later in the program. I can now print that value and it is correct.

    Now I use that variable in the OnBarUpdate part of my indicator. JU shows equal to 0 rather that the assigned calculated value from the initialize section. How do I pass the value of JU from the initialize section so I can use it in the ONBarUpdate section??

    Any help or suggestions truly appreciated.

    #2
    It sounds like you declared and assigned that variable in Initialize(). If you declare in the variables section of your class, then it will work as expected (modifications done in Initialize() are visible in OnBarUpdate()).

    Regards
    Ralph

    Welcome to the forum, rhbishop5.

    Comment


      #3
      Reply to Reply

      Thanks, Ralph. The variable was declared in the Variables section by private double JU; It was then assigned a value in the initialize section by double JU=(-100/(U-100))-1; . When printed in this section, JU shows the proper value. When used in the OnBar Update area it comes up as 0.

      Comment


        #4
        Attached you find an example that works as I would expect to. An integer is defined in the variables section then modified in Initialize() and finally displayed on a chart as depicted in the little picture. Now you could use this code example to demonstrate where your problem is.

        Regards
        Ralph
        Attached Files

        Comment


          #5
          YES!!!!! Thanks, Ralph. That did the trick. I had a "double" in front of the variable when I assigned it in the initialize area and evidently the compiler considers that a separate variable not related too the one declared in the variable area. Thanks much!!!! Bob

          Comment


            #6
            Glad to see, that variable assignments work too for your Ninja installation, Bob

            The lesson in your case is to take care when and where to declare a variable. C# is very flexible, you could declare a variable nearly everywhere, Although a declaration at the beginning of a method is a viable spot. More strict compilers with the possibility to write out log messages (not only compiler errors) sometimes issue warnings about name-clashes.

            Regards
            Ralph

            Comment


              #7
              Bob, great to hear you've found a working solution. As you've found out, this is a pretty helpful forum. If you have any other questions, just ask.

              Ralph, thank you for your continued support and contributions to the forum.
              AustinNinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              571 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              330 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              101 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              548 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              549 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X