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

Is it possible to run the built-in alert window within NinjaScript?

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

    Is it possible to run the built-in alert window within NinjaScript?

    Hello.

    Is there any way to run built-in NT alert dialogue window from within NinjaScript code?

    Thank You.
    Attached Files
    Last edited by fx.practic; 11-03-2018, 08:59 AM.
    fx.practic
    NinjaTrader Ecosystem Vendor - fx.practic

    #2
    While waiting for answer I decided to make some experiments with standard WPF System.Windows.MessageBox Class

    This code:
    Code:
    if(  CurrentBar == First_Realtime_Bar_Number +3 && State == State.Realtime )
    {
         MessageBoxResult result = MessageBox.Show( "Some text", "Caption Text" );    
    }
    causing freezing of Simulated Data Feed and produced error message:

    Failed to call 'Add' method: System.Threading.LockRecursionException: Write lock may not be acquired with read lock held. This pattern is prone to deadlocks. Please ensure that read locks are released before taking a write lock. If an upgrade is necessary, use an upgrade lock in place of the read lock. at System.Threading.ReaderWriterLockSlim.TryEnterWrit eLockCore(TimeoutTracker timeout) at System.Threading.ReaderWriterLockSlim.TryEnterWrit eLock(TimeoutTracker timeout) at NinjaTrader.Data.BarsSeries.Add(Bars bars, Double open, Double high, Double low, Double close, DateTime time, Int64 volume, Double tickSize, Boolean isBar, Double bid, Double ask)

    Here is video of how it happened: https://www.screencast.com/t/prnd6OGvIk5

    The code below work without errors and freezing, but message window some times appears under chart window:

    Code:
    if(  CurrentBar == First_Realtime_Bar_Number +3 && State == State.Realtime )
    {
        new Thread(() =>
        {
            MessageBoxResult result = MessageBox.Show( "Some text", "Caption Text" );    
        }).Start();
    }
    and this works correct at first sight:

    Code:
                if(  CurrentBar == First_Realtime_Bar_Number +3 && State == State.Realtime )
                {
                    ChartControl.Dispatcher.InvokeAsync(new Action(() => 
                    { 
                        MessageBoxResult result = MessageBox.Show( "Some text", "Caption Text" );                
                    }));    
                }
    Any other special recommendations and restrictions?
    Last edited by fx.practic; 11-03-2018, 10:25 AM.
    fx.practic
    NinjaTrader Ecosystem Vendor - fx.practic

    Comment


      #3
      Also, found on forum mentions about these classes:

      NTMessageBox
      NTMessageBoxSimple

      Are there any recommendations of proper use?

      found this, looks working:
      https://ninjatrader.com/support/foru...box-in-a-class
      https://ninjatrader.com/support/forum/forum/historical-beta-archive/version-8-beta/86030-how-do-we-get-a-messagebox-that-supports-skins


      Thank you.
      Last edited by fx.practic; 11-04-2018, 11:56 AM.
      fx.practic
      NinjaTrader Ecosystem Vendor - fx.practic

      Comment


        #4
        Hello

        Thank you for your note.

        There would be no supported method to call the alert dialogue window from NinjaScript, however it may be possible.

        You could create a alert with NinjaScript, not requiring a popup,


        The error you've posted looks related to the AddBar method. If you strip all logic from your indicator aside from the message box, are you able to replicate the issue?



        I look forward to your reply.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Hello, Chelsea.

          Thank You for answer.
          Error was caused by code above it.
          But, when I run it in separate thread, it works normal.


          I have 2 questions about NTMessageBoxSimple:

          1. Can I run it in non-modal mode (but always on top) form indicator without blocking user interface?
          2. Can I increase it's height? I haver big message and need to fit window to message size.

          Thank You.



          --- UPD 1:
          I tried to create instance to manipulate with properties:

          PHP Code:
          NinjaTrader.Gui.Tools.NTMessageBoxSimple test = new NinjaTrader.Gui.Tools.NTMessageBoxSimple(); 

          but: 'NinjaTrader.Gui.Tools.NTMessageBoxSimple.NTMessag eBoxSimple()' is inaccessible due to its protection level[/QUOTE]



          --- UPD 2:
          ChartControl.Dispatcher.BeginInvoke() still block UI thread with both WPF MessageBox and NTMessageBoxSimple



          --- UPD 3:
          This crushes NT with guarantee:
          PHP Code:

          new Thread(() =>
          {
          MessageBox.ShowWindow.GetWindow(ChartControl.OwnerChart as DependencyObject),  "Some text""Caption Text" );    

          }).
          Start(); 

          --- UPD 4:
          This (MessageBoxOptions.ServiceNotification) work almost fine, but show window in the centre of main monitor - not above parent chart:

          PHP Code:

          new Thread(() =>
          {                            

              
          MessageBox.Show(
                  
          msg_content,
                  
          window_caption,
                  
          MessageBoxButton.OK,
                  
          MessageBoxImage.Information,
                  
          MessageBoxResult.OK,
                  
          MessageBoxOptions.ServiceNotification
                  
          );                                              
          }).
          Start(); 
          Last edited by fx.practic; 11-05-2018, 06:16 AM.
          fx.practic
          NinjaTrader Ecosystem Vendor - fx.practic

          Comment


            #6
            Hello fx.practic,

            There is no supported method to specify the location of the Messagebox, however it may be possible.

            I will submit a feature request for this.

            Please let us know if you need further assistance.
            Alan P.NinjaTrader Customer Service

            Comment


              #7
              Thank You, Alan.
              fx.practic
              NinjaTrader Ecosystem Vendor - fx.practic

              Comment


                #8
                fx.practic
                have you found a way to implement NT message box programatically, instead of Windows MessageBox ?


                ___
                update:
                found on your link.
                Last edited by ttodua; 05-10-2019, 01:40 AM.

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by helpwanted, Today, 03:06 AM
                0 responses
                0 views
                0 likes
                Last Post helpwanted  
                Started by Brevo, Today, 01:45 AM
                0 responses
                6 views
                0 likes
                Last Post Brevo
                by Brevo
                 
                Started by aussugardefender, Today, 01:07 AM
                0 responses
                5 views
                0 likes
                Last Post aussugardefender  
                Started by pvincent, 06-23-2022, 12:53 PM
                14 responses
                242 views
                0 likes
                Last Post Nyman
                by Nyman
                 
                Started by TraderG23, 12-08-2023, 07:56 AM
                9 responses
                384 views
                1 like
                Last Post Gavini
                by Gavini
                 
                Working...
                X