• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

Announcement

Collapse
No announcement yet.

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

            http://www.ninjatrader.com/support/f...=windows+forms

            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 traderpards, 12-12-2018, 01:15 PM
                          5 responses
                          151 views
                          0 likes
                          Last Post BrianL
                          by BrianL
                           
                          Started by Cyanez, Today, 08:41 AM
                          1 response
                          6 views
                          0 likes
                          Last Post NinjaTrader_Jesse  
                          Started by TonyParisi, Today, 07:38 AM
                          1 response
                          8 views
                          0 likes
                          Last Post NinjaTrader_Kate  
                          Started by tgn55, 09-24-2019, 06:34 AM
                          13 responses
                          48 views
                          0 likes
                          Last Post NinjaTrader_Jim  
                          Started by jasphere, Today, 07:37 AM
                          4 responses
                          20 views
                          0 likes
                          Last Post jasphere  
                          Working...
                          X