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

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.
    Kate W.NinjaTrader Customer Service

    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.
        Kate W.NinjaTrader Customer Service

        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 selu72, Today, 02:01 PM
          1 response
          3 views
          0 likes
          Last Post NinjaTrader_Zachary  
          Started by WHICKED, Today, 02:02 PM
          2 responses
          8 views
          0 likes
          Last Post WHICKED
          by WHICKED
           
          Started by f.saeidi, Today, 12:14 PM
          8 responses
          21 views
          0 likes
          Last Post f.saeidi  
          Started by Mikey_, 03-23-2024, 05:59 PM
          3 responses
          50 views
          0 likes
          Last Post Sam2515
          by Sam2515
           
          Started by Russ Moreland, Today, 12:54 PM
          1 response
          7 views
          0 likes
          Last Post NinjaTrader_Erick  
          Working...
          X