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

Showing the output window when starting up a strategy (code)

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

    Showing the output window when starting up a strategy (code)

    Hi there,

    In NT7, I had this bit of code that would automatically open an output window once a custom strategy was enabled:

    Code:
    protected override void OnStartUp() 
    {
    	//  Show the output window on startup
    	NinjaTrader.Gui.Globals.OutputWindow.Show();
    }
    Is there any NT8 equivalent to this, either in the if (State == State.SetDefaults) section, or through an add-on?

    Thanks in advance for any help you can provide. It's always appreciated.

    - Spider

    #2
    Hello,

    Thank you for posting.

    I am unaware if this specific method was moved into NT8, I will need to research this. Once I have further details I will reply back here.

    I look forward to being of further assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      Hello,

      I just wanted to reply back on this item.

      It looks like this is possible using undocumented/unsupported code:

      Code:
      Core.Globals.RandomDispatcher.BeginInvoke(new Action(() => 
      { 
      	NinjaTrader.Gui.NinjaScript.NinjaScriptOutput newNsOutput = new NinjaTrader.Gui.NinjaScript.NinjaScriptOutput();
      	newNsOutput.Show(); 
      	newNsOutput.Activate();
      }));
      This opens a new window, so if you had an existing window open you would likely need to check that first by using the NinjaTrader.Core.Globals.AllWindows collection. If it exists you could likely just focus the window in that case.

      I look forward to being of further assistance.
      JesseNinjaTrader Customer Service

      Comment


        #4
        Originally posted by NinjaTrader_Jesse View Post
        Hello,

        I just wanted to reply back on this item.

        It looks like this is possible using undocumented/unsupported code:

        Code:
        Core.Globals.RandomDispatcher.BeginInvoke(new Action(() => 
        { 
        	NinjaTrader.Gui.NinjaScript.NinjaScriptOutput newNsOutput = new NinjaTrader.Gui.NinjaScript.NinjaScriptOutput();
        	newNsOutput.Show(); 
        	newNsOutput.Activate();
        }));
        This opens a new window, so if you had an existing window open you would likely need to check that first by using the NinjaTrader.Core.Globals.AllWindows collection. If it exists you could likely just focus the window in that case.

        I look forward to being of further assistance.
        Thank you very much Jesse!

        Two quick follow-ups:

        1. Where would you recommend I place that code if I wanted to try it out in my script?
        2. Would I e-mail platform support to get a complete list of methods available to me as a NT coder?

        Please let me know when you have a moment.

        - Spider

        Comment


          #5
          Hello,

          Thank you for the reply.

          you could place this in an if statement from OnBarUpdate that allows it to occur one time or one of the states in the script after SetDefaults such as Historical.

          Our support would not have a complete list of all possible methods that can be used, is there some specific syntax you are trying to convert? Undocumented items we would generally need to research, these would be items that were not documented in NT7. Otherwise, for most everything that was documented, you can locate the changes in the code-breaking changes guide: https://ninjatrader.com/support/help...ng_changes.htm

          I would only suggest emailing support if you are unable to locate any information on the subject or something is unclear. Also in the case of unsupported nt7 code that is not going to be in the NT8 help guide so we would need to research those questions.

          I look forward to being of further assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            Thanks again!

            Hi Jesse,

            No specific one. It's more for understanding what my options are. The 'Strategy' link you posted in the other thread (https://ninjatrader.com/support/help.../?strategy.htm) is a perfect example. I'll only reach out to platform support if I'm really stuck.

            Btw, this is the code I ended up drafting. I haven't compiled it, but let me know if I'm in compliance:

            Code:
            protected override void OnBarUpdate()
            		{
            			//Check and see if the Output window is open.  If not, put it up
            			if (newNSOutput == null)
            			{
            				Core.Globals.RandomDispatcher.BeginInvoke(new Action(() => 
            				{ 
            					NinjaTrader.Gui.NinjaScript.NinjaScriptOutput newNsOutput = new NinjaTrader.Gui.NinjaScript.NinjaScriptOutput();
            					newNsOutput.Show(); 
            					newNsOutput.Activate();
            				}));
            			}
            			//Add your custom strategy logic here.
            		}
            Last edited by Spiderbird; 12-19-2017, 01:28 PM. Reason: Corrected the code...

            Comment


              #7
              Hello,

              Thank you for the reply.

              In this case, I would suggest to just give it a compile to allow the platform to tell you if it is ok or not, you will see errors in this case.

              You would need to modify the variable name to match, and also move it out of the scope of OnBarUpdate:

              Code:
              NinjaTrader.Gui.NinjaScript.NinjaScriptOutput newNsOutput;
              protected override void OnBarUpdate()
              {
              	//Check and see if the Output window is open.  If not, put it up
              	if (newNsOutput == null)
              	{
              		Core.Globals.RandomDispatcher.BeginInvoke(new Action(() => 
              		{ 
              			newNsOutput = new NinjaTrader.Gui.NinjaScript.NinjaScriptOutput();
              			newNsOutput.Show(); 
              			newNsOutput.Activate();
              		}));
              	}
              }

              I look forward to being of further assistance.
              JesseNinjaTrader Customer Service

              Comment


                #8
                Hi Jesse,

                Sorry for hijacking this post, but I'm trying to achieve the exact same thing. The code snippet in #7 works fine to some extent, but it brings up a new Output Window for every "Run" of the same strategy. Thus, I'm obviously struggling with "if (newNsOutput == null)".

                Interesting fact. Although a new Output Window is opened for every "Run", the strategy updates ALL open Output Windows, not only the one added last.

                Can you please elaborate a bit further how I can check, if an Output Window is already open?

                Thank you.

                KR
                NT-Roland

                Comment


                  #9
                  Hello NT-Roland,

                  In this case you can use the Globals.AllWIndows collection to see if an output is open already. I made a quick test to expand on the last post and have attached it.

                  The indicator (for ease of testing) demonstrates either bringing forward an existing output window or creating a new one. This is only a test though which does not include handling other scenarios such as multiple output windows. This would be a good start at handling this in a custom strategy where you can fine-tune it toward your workspace.

                  I look forward to being of further assistance.
                  Attached Files
                  JesseNinjaTrader Customer Service

                  Comment


                    #10
                    Hello Jesse,

                    Great stuff. I was able to adapt it to my strategy w/in 5 minutes.

                    Thank you very much.

                    KR
                    NT-Roland

                    Comment


                      #11
                      Hi Jesse,

                      I am using your snippet above to make sure an output window is visible while I run my strategy. In using this my strategy is fairly verbose on startup. How can I ensure the output window is ready to receive print statements before printing to it. Effectively I would need the process to not be async but actually synchronous I suppose, even if it takes a few secs... Thanks for your help!

                      Frank

                      Comment


                        #12
                        To make sure the window is loaded and ready, simply change the code as follows:
                        //NinjaTrader.Core.Globals.AllWindows[i].Dispatcher.InvokeAsync(() => {
                        NinjaTrader.Core.Globals.AllWindows[i].Dispatcher.Invoke(() => {

                        ...same needs to happen a 2nd time further down:
                        //Core.Globals.RandomDispatcher.InvokeAsync(() =>
                        Core.Globals.RandomDispatcher.Invoke(() =>

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by NRITV, Today, 01:15 PM
                        2 responses
                        6 views
                        0 likes
                        Last Post NRITV
                        by NRITV
                         
                        Started by frankthearm, Today, 09:08 AM
                        7 responses
                        30 views
                        0 likes
                        Last Post NinjaTrader_Clayton  
                        Started by maybeimnotrader, Yesterday, 05:46 PM
                        5 responses
                        25 views
                        0 likes
                        Last Post NinjaTrader_ChelseaB  
                        Started by quantismo, Yesterday, 05:13 PM
                        2 responses
                        18 views
                        0 likes
                        Last Post quantismo  
                        Started by adeelshahzad, Today, 03:54 AM
                        5 responses
                        33 views
                        0 likes
                        Last Post NinjaTrader_BrandonH  
                        Working...
                        X