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

MessageBox Class

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

    MessageBox Class

    I'm trying to do some basic error checking with a complicated group of inputs. Correct me if I'm wrong, but I just assumed that MessageBox.Show() would be the best method to accomplish this.

    I tried placing Show() inside of Initialize(), but Initialize() runs before the user has a chance to modify the inputs. So, I moved Show() down to OnBarUpdate(). I tried changing it over and over again, until I finally tried this:

    Code:
    protected override void OnBarUpdate()
            {
             MessageBox.Show("This is an OnBarUpdate() test", "Testing OnBarUpdate()!");
            }
    I can't get Show() to run.

    Can someone either a) Explain why this isn't working or b) suggest an alternative?

    #2
    Hello texasnomad,

    This is unfortunately beyond our scope of support. To check values you can use Print() statements and view output window. (Tools > Output Window)

    As a hint, you probably need to add the Using statement to your indicator.

    using System.Windows.Forms;
    Ryan M.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_RyanM View Post
      Hello texasnomad,

      This is unfortunately beyond our scope of support. To check values you can use Print() statements and view output window. (Tools > Output Window)

      As a hint, you probably need to add the Using statement to your indicator.

      using System.Windows.Forms;
      Ryan,

      Thanks for the hint, but I already had that in there.

      I also have loads of print statements goign to the output window. Do you have any suggestions for how to alert the user to conflicting inputs that are within the scope of your support?

      Comment


        #4
        You can call Alert() method. This requires an open alert window to view the message. (File > New > Alert)
        Ryan M.NinjaTrader Customer Service

        Comment


          #5
          I switched gears and tried to use DrawTextFixed("error", "Something is wrong", TextPosition.TopRight);. I can't get it to show up anywhere on the chart.

          I tried placing it in OnBarUpdate() and Initialize(). The text doesn't show up anywhere on the chart.

          Comment


            #6
            Using message box etc

            Texas

            May I suggest you look at the following thread



            You will find information on adding a strategy which produces a windows form box. If
            you look at the files provided all the information is in there. Of course all this is 'unsupported'

            Comment


              #7
              It belongs in OnBarUpdate()

              Perhaps add DrawOnPricePanel = true; to Initialize() method.

              Check log tab of control center for any error messages.

              Reapply any instances of indicator after making changes.

              Let me know if you're still not seeing it and I'll put together a simple script.
              Ryan M.NinjaTrader Customer Service

              Comment


                #8
                Thank you for suggesting this. I think I'd rather go with a simpler solution.

                Is anyone familiar with DrawTextFixed()? I think this will do the job well enough. I tried another simple experiment of the following:

                [code] protected void OnBarUpdate() {
                DrawTextFixed("tag1", "Text to draw", TextPosition.TopRight);
                }

                No text appears. Thoughts?

                Comment


                  #9
                  The sytnax looks fine. Perhaps try with attached sample and work from that.
                  Attached Files
                  Ryan M.NinjaTrader Customer Service

                  Comment


                    #10
                    here's my code snippet for displaying a form with custom label text and repeating sound.
                    messagebox is not good for me as when clicking "Ok" on it all variables got reset.
                    hope this will be of help to somebody.

                    PHP Code:
                    using System.Windows.Forms;
                    using System.Media;
                    using System.Threading;
                    using System.Drawing;
                    using System.Text;
                    using System.ComponentModel;


                            
                    #region Variables
                            // User defined variables (add any user defined variables below)
                                
                    private static DateTime at;
                            
                    #endregion

                        
                    public class Splay
                        
                    {
                        
                    // This method that will be called when the thread is started
                            
                    public void play()
                            {
                                    
                    SoundPlayer simpleSound = new SoundPlayer(@"c:\Windows\Media\chimes.wav");
                                    while (
                    true) {
                                        
                    simpleSound.Play();
                                        
                    Thread.Sleep(2000);
                                    }
                            }
                        }

                        public class 
                    TestForm Form
                        
                    {
                            public 
                    Label lblResult;
                            public 
                    Thread oThread;
                            
                    //constructor
                            
                    public TestForm()
                            {
                                
                    ClientSize = new System.Drawing.Size(400,100);
                                
                    StartPosition FormStartPosition.CenterScreen;
                                
                    lblResult = new Label();
                                
                    lblResult.Size = new Size(380,80);
                                
                    lblResult.Location = new Point(10,10);
                                
                    lblResult.Text="t: ";
                                
                    Controls.Add(lblResult);
                                
                    //this.Load += new System.EventHandler(this.TestForm_Load);
                                
                    this.Shown += new System.EventHandler(this.TestForm_Shown);
                                
                    this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.TestForm_FormClosing);
                            }
                            private 
                    void TestForm_Load(object senderEventArgs e)
                            {
                            }
                            private 
                    void TestForm_Shown(object senderEventArgs e)
                            {
                                
                    Splay splay = new Splay();
                                
                    oThread = new Thread(new ThreadStart(splay.play));
                                
                    // Start the thread
                                
                    oThread.Start();
                                
                    // Spin for a while waiting for the started thread to become
                                // alive:
                                
                    while (!oThread.IsAlive);
                            }
                            private 
                    void TestForm_FormClosing(object senderFormClosingEventArgs e)
                            {
                                
                    // Request that oThread be stopped
                                
                    oThread.Abort();
                                
                    // Wait until oThread finishes. Join also has overloads
                                // that take a millisecond interval or a TimeSpan object.
                                
                    oThread.Join();
                            }
                        }

                    //the below is placed in OnBarUpdate()

                                
                    if (CurrentBar==Bars.Count-1) {
                                    if (
                    at!=Time[1])  {
                                        
                    TestForm frm = new TestForm();
                                        
                    frm.lblResult.Text="custom alert text put here";
                                        
                    frm.Show(); 
                                        
                    at=Time[1];
                                    }
                                } 

                    Comment


                      #11
                      Thanks for the code snippet, Buxxx.
                      Ryan M.NinjaTrader Customer Service

                      Comment


                        #12
                        That's seriously useful, but what do you have to do to clean it up afterwards?

                        I'm implementing it all over the place - should I have one form and then just dispose it in Termination() or is it fine just creating that new instance of the form class and leaving it to be garbage collected?

                        I suppose my user might want to have two windows open at the same time to compare them.

                        Comment


                          #13
                          Buxxx, thanks! helped much.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by xiinteractive, 04-09-2024, 08:08 AM
                          5 responses
                          13 views
                          0 likes
                          Last Post NinjaTrader_Erick  
                          Started by swestendorf, Today, 11:14 AM
                          2 responses
                          6 views
                          0 likes
                          Last Post NinjaTrader_Kimberly  
                          Started by Mupulen, Today, 11:26 AM
                          0 responses
                          2 views
                          0 likes
                          Last Post Mupulen
                          by Mupulen
                           
                          Started by Sparkyboy, Today, 10:57 AM
                          1 response
                          6 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Started by TheMarlin801, 10-13-2020, 01:40 AM
                          21 responses
                          3,918 views
                          0 likes
                          Last Post Bidder
                          by Bidder
                           
                          Working...
                          X