-thanks
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
TriggerCustomEvent()
Collapse
X
-
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?
-thanksTags: None
-
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
-
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
-
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
-
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
-
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
-
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
626 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
359 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
105 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
562 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
567 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment