Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

TriggerCustomEvent()

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

    TriggerCustomEvent()

    I'm trying to get the custom event functionality to work for me. I can raise an event and it successfully runs the event handler. I can print something from this method. This method then calls TriggerCustomEvent(MyCustomHandler, 0, null) and MyCustomHandler() is supposed to Print some text. Also your example, SampleCustomEvents, only has 2 arguments for TriggerCustomEvent() but when I try I get a compile error saying that no overload takes 2 arguments. It compiles if I add the barsInProgress of 0. There are no errors being reported when I run it but MyCustomHandler() is not being run. Any ideas where I should look?

    -thanks

    #2
    TriggerCustomEvent() with 2 parameters is a deprecated signature. I suspect you were trying to do this in a strategy which is why it did not work.

    Please provide code snippets for us to evaluate on your MyCustomHandler issue. Thank you.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      This is the code I am using. It puts a button on the chart and when I click it I get the tradeButton_Click() method printing to the output window. It doesn't follow through to MyCustomHandler() though. This is running within a strategy.

      -thanks

      Code:
      protected void CreateToolStripButtons()
              {
                  if( ChartControl != null )
                  {
                      ToolStrip toolStrip = (ToolStrip) ChartControl.Controls["tsrTool"];
                      
                      if( toolStrip != null )
                      {
                      
      
                          tradeButton = new ToolStripButton();
                          tradeButton.Name = "tradeButton";
                          tradeButton.Text = "Trade";
                          tradeButton.Click += new EventHandler(tradeButton_Click);
                          toolStrip.Items.Add(tradeButton);
                          
      
                      }
                  }
              }
              private void tradeButton_Click(Object sender, EventArgs e)
              {
                  Print("Click! tradeButton_Click");
                  TriggerCustomEvent(MyCustomHandler, 0, null);
                  
              }
      private void MyCustomHandler(object state)
              {
                  
                  Print("Click! MyCustomHandler");
              {

      Comment


        #4
        laparker,

        Please try using a non-null object state.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Tried that with no luck.

          Code:
          private void tradeButton_Click(Object sender, EventArgs e)
                  {
                      Print("Click! tradeButton_Click");
                      TriggerCustomEvent(MyCustomHandler, 0, "MyCustomHandler");
                      
                  }
          private void MyCustomHandler(object state)
                  {
                      
                      Print("Click! " + state);
                  }

          Comment


            #6
            Taking a step back, any errors in Control Center logs?
            Josh P.NinjaTrader Customer Service

            Comment


              #7
              There's nothing in the control center logs.

              I added this functionality to SampleMACrossOver and got the same problem. I have attached it.
              Attached Files

              Comment


                #8
                Not sure I follow. Here is what I see as I clicked on the "Trade" label on the toolbar:
                Click! tradeButton_Click
                Click! MyCustomHandler
                Click! tradeButton_Click
                Click! MyCustomHandler
                Click! tradeButton_Click
                Click! MyCustomHandler
                Click! tradeButton_Click
                Click! MyCustomHandler
                Click! tradeButton_Click
                Click! MyCustomHandler

                This was on a 1-min ES chart, sim feed, session = 24/7, all default

                Comment


                  #9
                  I must be doing something really dumb then. I get:

                  Click! tradeButton_Click
                  Click! tradeButton_Click
                  Click! tradeButton_Click
                  Click! tradeButton_Click

                  I am running this on 7.0.0.6
                  Running through backtest. Clicking the Chart tab. Then clicking "Trade".

                  Comment


                    #10
                    Sorry I'm out of ideas.

                    Comment


                      #11
                      Dierk

                      I would welcome your support in fixing this. Please do not give up.

                      What else can I try?

                      -thanks

                      Comment


                        #12
                        Try something like a timer event and not unsupported menu manipulation. I believe there is a sample available.

                        Comment


                          #13
                          When trying to import the example SampleCustomEvents.zip I get the error message:
                          "Import failed. The NinjaScript Archive File may contain duplicate method names that already exist on your PC or there is a required file missing on either your PC or in the import archive."

                          I can import other scripts.

                          Comment


                            #14
                            The sample is not compatible for reasons outlined in the code breaking changes. The indicator uses volume as ints, please change them to long then you will be able to use it.

                            Attached below for your convenience.
                            Attached Files
                            Josh P.NinjaTrader Customer Service

                            Comment


                              #15
                              Thanks for your help Josh and Dierk.

                              Looks like it doesn't work when running it on backtest. I have hooked it up to a live chart and it works peachy! I can put a button up on the chart and trap when it is clicked through to your TriggerCustomEvent(). Got to be good, hasn't it.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                              0 responses
                              635 views
                              0 likes
                              Last Post Geovanny Suaza  
                              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                              0 responses
                              364 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by Mindset, 02-09-2026, 11:44 AM
                              0 responses
                              106 views
                              0 likes
                              Last Post Mindset
                              by Mindset
                               
                              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                              0 responses
                              567 views
                              1 like
                              Last Post Geovanny Suaza  
                              Started by RFrosty, 01-28-2026, 06:49 PM
                              0 responses
                              570 views
                              1 like
                              Last Post RFrosty
                              by RFrosty
                               
                              Working...
                              X