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

Why does my code execute before I add the indicator to my chart?

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

    Why does my code execute before I add the indicator to my chart?

    As a test - I created a new indicator using Tools/New Ninjascript/Indicator.

    I added one integer variable called 'count'
    and then added 2 lines of code to the 'on bar update' method
    count ++;
    Print (count);



    I loaded the ES0613 1 Minute chart (see JPG#1)
    I then cleared the output window to make sure nothing was sitting in there.

    I then got an unexpected result when I loaded the indicator.

    The output window showed 2 instance of the count value before I even loaded the indicator (Called A1Test). See JPG#2 -- notice I have not even selected the indicator named A1TEST - but the output window shows 2 values (1 & 1)

    To me this says my code is being executed even before I add the indicator to my chart.

    I'm somewhat of a noob with Ninja - so Im hoping there is a simple explanation
    Thanks


    Attached Files

    #2
    How is count declared?

    Shouldn't the output be:

    Code:
    1
    2
    Can you post your test code and exact steps to repeat?

    I have some indicator code some where that print out stuff, so my output window is sometimes cluttered with random stuff that I don't feel bothered to deal with.


    Originally posted by mgabriel01 View Post
    As a test - I created a new indicator using Tools/New Ninjascript/Indicator.

    I added one integer variable called 'count'
    and then added 2 lines of code to the 'on bar update' method
    count ++;
    Print (count);



    I loaded the ES0613 1 Minute chart (see JPG#1)
    I then cleared the output window to make sure nothing was sitting in there.

    I then got an unexpected result when I loaded the indicator.

    The output window showed 2 instance of the count value before I even loaded the indicator (Called A1Test). See JPG#2 -- notice I have not even selected the indicator named A1TEST - but the output window shows 2 values (1 & 1)

    To me this says my code is being executed even before I add the indicator to my chart.

    I'm somewhat of a noob with Ninja - so Im hoping there is a simple explanation
    Thanks


    Comment


      #3
      mgabriel01, like sledge noted could be those prints are coming from another script's Initialize() potentially? It would be called across scripts...
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Gents
        Indeed - that was the problem
        So 'initialize' is run across all scripts even before a particular indicator is selected.
        Do I understand that correctly?
        Thanks

        Comment


          #5
          Yes that is correct - this is done to populate the list of scripts from the indicator/strategy grid.
          MatthewNinjaTrader Product Management

          Comment


            #6
            Originally posted by NinjaTrader_Matthew View Post
            Yes that is correct - this is done to populate the list of scripts from the indicator/strategy grid.

            Got it!
            Thank you for the explanation

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Max238, Today, 01:28 AM
            1 response
            22 views
            0 likes
            Last Post CactusMan  
            Started by giulyko00, Yesterday, 12:03 PM
            2 responses
            10 views
            0 likes
            Last Post giulyko00  
            Started by r68cervera, Today, 05:29 AM
            0 responses
            4 views
            0 likes
            Last Post r68cervera  
            Started by geddyisodin, Today, 05:20 AM
            0 responses
            6 views
            0 likes
            Last Post geddyisodin  
            Started by JonesJoker, 04-22-2024, 12:23 PM
            6 responses
            38 views
            0 likes
            Last Post JonesJoker  
            Working...
            X