Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

MessageBox shows infinitely

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

    MessageBox shows infinitely

    Hi,

    I developed an indicator and I wish it could play a sound and show a pop up message on certain condition.
    The sound works but the message shows up in infinite loop.

    Here's my code:

    Code:
    if (CurrentBar != savedBar) // if current bar is NOT equal to the savedBar
                    {
                        PlaySound(NinjaTrader.Core.Globals.InstallDir + @"\sounds\Alert4.wav");
                        MessageBox.Show("This is an OnBarUpdate() test", "Testing OnBarUpdate()!");
                        savedBar = CurrentBar; // save the current bar here to make them equal
                    }​
    I'd like the pop up to overlay everything I have opened if it is possible.

    Thanks,

    #2
    Hello Vincere,

    Thank you for your post.

    It appears you are using the Microsoft MessageBox object. There is also a NinjaTrader message box called NTMessageBoxSimple that you could test out to see if it achieves your desired result:


    As for the infinite loop, I suggest adding a Print statement to check the values of CurrentBar and savedBar to verify if the condition might be triggering multiple times. Here is an example of a print statement you could add both outside of your condition as well as inside of your condition:

    Print(String.Format("{0} CurrentBar: {1} savedBar: {2}", Time[0], CurrentBar, savedBar));

    For more information about using prints as a debugging tool:


    Please let us know if we may be of further assistance.

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by CarlTrading, 03-31-2026, 09:41 PM
    1 response
    156 views
    1 like
    Last Post NinjaTrader_ChelseaB  
    Started by CarlTrading, 04-01-2026, 02:41 AM
    0 responses
    90 views
    1 like
    Last Post CarlTrading  
    Started by CaptainJack, 03-31-2026, 11:44 PM
    0 responses
    140 views
    2 likes
    Last Post CaptainJack  
    Started by CarlTrading, 03-30-2026, 11:51 AM
    0 responses
    130 views
    1 like
    Last Post CarlTrading  
    Started by CarlTrading, 03-30-2026, 11:48 AM
    0 responses
    107 views
    0 likes
    Last Post CarlTrading  
    Working...
    X