Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Canīt reach NinjaScript from custom event

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

    Canīt reach NinjaScript from custom event

    Hi!

    I canīt reach a NinjaScript method (Draw()) from a custom event. The behaviour is the same if a do it with or without passing the event through TriggerCustomEvent()/MyCustomHandler(). Most code is reached, such as Print() and MessageBox, wich makes it hard to find the logic causing the problem. Help is appreciated:


    Code:
    protected override void OnStateChange()
    {
    ..
     else if (State == State.Configure)
     {   
      wa = new WebAutomation();
      wa.IsLoggedInEvent += OnIsLoggedIn;
     }
    }
    
    
    protected void OnIsLoggedIn()
    {
     TriggerCustomEvent(MyCustomHandler, 0, null);
    }
    
    
    public void MyCustomHandler(object state)
    {
     DrawLabels();
    }
    
    
    protected void DrawLabels()
    {
     if (CurrentBar != Bars.Count-2) return; // Draw on last bar only
    
     Print("Hello Print!"); // WORKS!
     MessageBox.Show("Hello MessageBox!" // WORKS!
     Draw.TextFixed(this, "textLabel", "Hello Label!"...); // FAILS!
    }

    #2
    Hello FREEN,

    Thank you for your post.

    Could you copy and paste your code for the DrawLabels() method exactly as it is in your script? Looks like there's a few things missing and I'd like to test exactly as you have it. The fact that the Print and the MessageBox show up lead me to believe you might have something wrong with the Draw statement.

    Thanks in advance; I look forward to assisting you further.

    Comment


      #3
      Thanks Kate,

      The same method (DrawLabels()) is also triggered in NT8īs OnBarUpdate() without issues:

      Code:
      
        /// <summary>
        /// Draw text.
        /// </summary>
        protected void DrawLabels()
        {
         if (CurrentBar != Bars.Count-2) return; // Draw on last bar only
      
         string stringData =
         "\nNinjaTrader:"
         + "\n   Connection:\t\t" + connectionStatus
         + "\n   State:\t\t\t" + State +" (" + (int)State + ")"
         + "\n   CurrentBar:\t\t" + CurrentBar
         + "\n   CurrentBar time:\t" + Time[0].TimeOfDay
         + "\n\n"
      
         + priceBars.Label
         + tlc.Label
         + wa.Label;
      
         Draw.TextFixed(this, "textLabel", stringData, TextPosition.Center, ChartControl.Properties.ChartText, ChartControl.Properties.LabelFont, new SolidColorBrush(Color.FromRgb(49,51, 53)), new SolidColorBrush(Color.FromRgb(49,51, 53)), 100);
        }

      Comment


        #4
        Hello FREEN,

        Thank you for your reply.

        Do you receive any errors when running the code, either in the NinjaScript Output window or in the Log Tab of the Control Center?

        I'd like to take a look at your log and trace files to check for errors that may point us in the right direction, if you would please email us at PlatformSupport [AT] NinjaTrader [DOT] com. In your message please include a link to this forum thread and '2238294 ATTN Kate' in the body of your email.

        Additionally, please follow the steps below to manually attach your log and trace files to your response so I may investigate this matter further.
        • Open your NinjaTrader folder under My Documents.
        • Right click on the 'log' and 'trace' folders and select Send To> Compressed (zipped) Folder.
        • Send the 2 compressed folders as attachments to this email.
        • Once complete, you can delete these compressed folders.
        Thanks in advance; I look forward to resolving this item.

        Comment


          #5
          Thanks Kate,

          I used a different solution for my objective. Hence my problem is "solved", even though I dont know what really went wrong. You may delete this thread since I doubt it will help anyone else.

          I appreciate your time and effort, thanks!

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          571 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          331 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          101 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          549 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          550 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X