-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 CarlTrading, 03-31-2026, 09:41 PM
|
1 response
43 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
21 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
30 views
1 like
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
50 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
42 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|

Comment