Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Output Window issues - chooses its own tab and insists on clearing itself

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

    Output Window issues - chooses its own tab and insists on clearing itself

    I'm having some trouble getting the output window to behave as expected. Basically I'd like to programmatically direct which output tab the script prints to and initially I had parametrized the OutputTab variable so it could be set to 1 or 2. So

    private int outputTab; /// up top

    And in Properties section:

    [NinjaScriptProperty]
    [Range(1, 2)]
    [Display(Name="OutputTab", Description="OutputTab", Order=6, GroupName="Parameters")]
    public int OutputTab
    {
    get { return outputTab; }
    set { outputTab = value; }


    }​

    Then a statement like:

    PrintTo = (outputTab==1? PrintTo.OutputTab1:PrintTo.OutputTab2);
    ClearOutputWindow();​ in OnStateChange would direct the output properly after clearing it when starting a new strategy.

    Then oddly that just seemed to stop working and I was only able to get it to start working again if I put the above statement into the OnBarUpdate method so it was reinitialized each time.

    Now that I'm no longer using that statement for some reason my code is always printing to OutputTab2.

    Worse, when opening a strategy on a chart (ctrl+s) to check parameters or to stop it so I can examine the output tab the output tab immediately clears itself which is very unhelpful.

    I don't have any ClearOutputWindow();​ statements anywhere in the code.

    This all seems to be very different from how the output tab was initially working where among other things described above, after stopping a script the output would remain in the output tab.

    Any ideas?

    #2
    Hello markdshark,

    Having ClearOutputWindow inside OnStateChange is not a good idea, that will be called frequently when using the platforms UI so it will clear it when you don't want it cleared. If you need this to happen at the start of your script I would suggest making a condition inside OnBarUpdate to check for CurrentBar == 0 and then clear it at that point. That ensures your script is running before it gets cleared.

    I wouldn't be able to comment on why the output 2 is being used other than potentially you have not compiled or re applied the new instance with the changes after removing that code, the default window is 1.

    I would suggest to double check that you have totally removed any PrintTo syntax and also ClearOutputWindow, Compile and then remove all instances of the script before re applying a new instance. If you leave an old instance and just use F5 to reload that won't see the changes to OnStateChange.

    Comment


      #3
      Nearly all PrintTo statements were removed many iterations ago. Compiled/ recompiled/ reloaded/ removed and reloaded/ restarted many many times. the behavior remains the same. A couple of weeks now I'm just finally at a point where I had to ask.

      I did have a PrintTo = (outputTab==1? PrintTo.OutputTab1:PrintTo.OutputTab2); left in OnBarUpdate which I just removed and recompiled, and restarted the whole thing. It's now printing to OutputTab1, But...

      Ctrl+S or right click and choose Strategy on my system still apparently means: First clear outputTab2 and then bring up the strategy chooser interface

      Thankfully OutputTab1 is not getting cleared.
      Last edited by markdshark; 04-12-2023, 07:50 AM.

      Comment


        #4
        Hello markdshark,

        If you have ClearOutputWindow in OnStateChange that will be called when the script is not running, its not a good location to have that code. If the purpose is to clear it before running you should move that code to OnBarUpdate inside a condition checking if(CurrentBar == 0). OnStatechange is called many times, one case is when opening the strategies window before selecting your script. You can read about the lifecycle of scripts here: https://ninjatrader.com/support/help...fecycle_of.htm

        Comment


          #5
          Thanks Jesse, gotcha.The ClearOutputWindow() is long gone from the code. But OutputTab2 WILL clear itself whenever the strategy picker interface is brought up. That's just what it does and it will not be denied by such minor matters such as the presence or absence of instructions. OutputTab2 does what it feels is best for OutputTab2


          Could it be that remnant ClearOutputWindow in that section in code not in use is somehow in play? Like in an old script that I'm not loading? I wouldn't think so...
          Last edited by markdshark; 04-12-2023, 08:09 AM.

          Comment


            #6
            Hello markdshark,

            If you are seeing the output clear that means you still have ClearOutputWindow being run from one of your scripts. You would need to search your scripts to find where that is and remove it. If its being cleared when you open the strategies menu that means that the code is in a scripts OnStateChange override. All scripts OnStateChange method is run when you open that window.

            Comment


              #7
              Thank you ...so ALL OnStateChange methods are run when the window is opened regardless of whether the strategy has been applied to a chart or not? That seems a bit odd

              Comment


                #8
                Hello markdshark,

                Yes, the window that displays the strategies needs to get the defaults so an instance of each script is made and OnStateChange is run. You can read about the lifecycle of your scripts in the following link:
                https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?understanding_the_li fecycle_of.htm

                •"UI" instances representing its default properties on various user interfaces

                •The "configured" instance executing your custom instructions

                To elaborate on that process, imagine the sequence of user events required to start an indicator on a chart:

                1.User right clicks on a Chart and select "Indicator"

                2.User adds an Indicator from the Available list

                3.User configures desired Properties and presses "Apply" or "OK"


                During this sequence, there are actually 3 instances of the same indicator created by NinjaTrader:

                1.The instance displaying the Name property to the list of "Available" indicators (Note: this process involves creating an instance of all indicators in order to build the complete list)

                2.The instance displaying the individual Name and its default Properties

                3.The instance configured and executing on the chart
                ​​

                Comment


                  #9
                  Thatss kompletely kraaazzyy maaan! And here I thought OutputTab2 just had a bad attitude. Turns out its actually one of the nicer tabs. Demure, docile, good looking. Doesn't print unless specifically asked to...

                  Many thanks for solving this for me!
                  Last edited by markdshark; 04-12-2023, 08:35 AM.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, Yesterday, 05:17 AM
                  0 responses
                  64 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  139 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  75 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  45 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  50 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X