"Error on triggering custom event for strategy 'MyStrategy'. More than 100 subsequent user events."
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!
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
NinjaTrader
Subsequent User Events Error
Collapse
X
-
Subsequent User Events Error
I am getting the following error in my strategy. I am assuming this happens due to a large number of cancel/replaces. How can I change this?
"Error on triggering custom event for strategy 'MyStrategy'. More than 100 subsequent user events."Tags: None
-
It will take some time to modify the code to post. Is it possible that too many cancel/replaces would cause the error?
Comment
-
Well I am not sure what you mean by cancel/replace. What are you cancelling and replacing? Limit orders? From my experience we have never had problems with modifying orders before.
From the error message you will want to focus your attention on your user created events. Perhaps this reference sample may be of some help in using custom events: http://www.ninjatrader-support.com/v...ead.php?t=5965Josh P.NinjaTrader Customer Service
Comment
-
I've been through that sample and no joy. By Cancel/Replace, I simply mean replacing the order with a new price. I have found out that if I set my timer interval to 1000, it is less likely to occur. However if I set it to 10, it happens almost immediately.
Comment
-
Ok. So you are placing your orders within the custom events. I suspect you maybe running into race conditions with the spamming of order modifications every 10 milliseconds.
Try running with TraceOrders = true and see what you get before you hit the error. Also, please post a simple as possible reference sample demonstrating what you are seeing when you get the chance so we can test it on our end. Thanks.Josh P.NinjaTrader Customer Service
Comment
-
I ran TraceOrders and it didn't give me much info. My strategy basically does something like this...
Code:[FONT=Courier New][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] MyCustomHandler([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] state)[/SIZE][/FONT] [SIZE=2][FONT=Courier New]{[/FONT][/SIZE] [FONT=Courier New][SIZE=2][COLOR=#008000]// Flat futures [/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (Positions[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]].MarketPosition==MarketPosition.Flat[/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT] [SIZE=2][FONT=Courier New]{ [/FONT][/SIZE] [SIZE=2][FONT=Courier New]LongEntry=EnterLongLimit([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],Contracts,[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]Close[0][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"LEntry"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT] [SIZE=2][FONT=Courier New]} [/FONT][/SIZE] [FONT=Courier New][SIZE=2][COLOR=#008000]// Long futures[/COLOR][/SIZE][/FONT] [FONT=Courier New][SIZE=2][COLOR=#0000ff]else[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] (Positions[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]].MarketPosition==MarketPosition.Long[/SIZE][/FONT][FONT=Courier New][SIZE=2])[/SIZE][/FONT] [SIZE=2][FONT=Courier New]{[/FONT][/SIZE] [SIZE=2][FONT=Courier New]LongExit=ExitLongLimit([/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],Positions[[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]].Quantity,Close[0][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"LEntryX"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2],[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800000]"LEntry"[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]);[/SIZE][/FONT] [SIZE=2][FONT=Courier New]}[/FONT][/SIZE] [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
Comment
-
Here is the rest of the code. I am not disposing of the object at all. How would I go about that?
Code:[FONT=Courier New][SIZE=2][COLOR=#0000ff] private[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] TimerEventProcessor(Object myObject, EventArgs myEventArgs) { [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]/* Important to use the TriggerCustomEvent() to ensure that NinjaScript indexes and pointers are correctly set. Do not process your code here. Process your code in the MyCustomHandler method. */ [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]TriggerCustomEvent(MyCustomHandler,[/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#800080]0[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2], MyTimer.Interval); } [/SIZE][/FONT]
Comment
-
OK I have the following. This did not work. Why do I dispose the timer? I only create 1 timer in the Initialize event. Also, where in the code should I dispose of it?
Code:[FONT=Courier New][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] TimerEventProcessor(Object myObject, EventArgs myEventArgs) [/SIZE][/FONT]..... [FONT=Courier New][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] MyCustomHandler([/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]object[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] state) [/SIZE][/FONT]..... [FONT=Courier New][SIZE=2][COLOR=#0000ff]public[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] Dispose() { [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]// Make sure you include base.Dispose() whenever you override the Dispose() method [/COLOR][/SIZE][/FONT][FONT=Courier New][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]base[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2].Dispose(); [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#008000]// Cleans up our Timer object [/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]MyTimer.Dispose(); } [/SIZE][/FONT]
Comment
-
You need to dispose to release the resources of that object or else it will hang there. Long story short: it is bad to leave things uncleaned up.
You place it just like how it is in the SampleCustomEvents reference indicator.
Please post the line you are using in the Initalize() method. Also post up the lines you are using for setting the timer interval and starting it.Josh P.NinjaTrader Customer Service
Comment
-
This is all the code. I looked at SampleCustomEvents and everything seems correct in my code.
Code:#region Variables [FONT=Courier New][SIZE=2][COLOR=#0000ff]private[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] System.Windows.Forms.Timer MyTimer = [/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] System.Windows.Forms.Timer();[/SIZE][/FONT] #endregion [FONT=Courier New][SIZE=2][COLOR=#0000ff]protected[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]override[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] Initialize()[/SIZE][/FONT] [SIZE=2][FONT=Courier New]{[/FONT][/SIZE] [SIZE=2][FONT=Courier New]CalculateOnBarClose = [/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2];[/SIZE][/FONT] [SIZE=2][FONT=Courier New]EntriesPerDirection = [/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]; [/SIZE][/FONT] [SIZE=2][FONT=Courier New]EntryHandling = EntryHandling.UniqueEntries;[/FONT][/SIZE] [SIZE=2][FONT=Courier New]Add(ForexSymbol, PeriodType.Minute, [/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#800080]1[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] ); [/SIZE][/FONT] [SIZE=2][FONT=Courier New]TraceOrders = [/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2]; [/SIZE][/FONT] [SIZE=2][FONT=Courier New]MyTimer.Tick += [/FONT][/SIZE][FONT=Courier New][SIZE=2][COLOR=#0000ff]new[/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2] EventHandler(TimerEventProcessor);[/SIZE][/FONT] [SIZE=2][FONT=Courier New]MyTimer.Interval = TimerInterval;[/FONT][/SIZE] [SIZE=2][FONT=Courier New]MyTimer.Start();[/FONT][/SIZE] [SIZE=2][FONT=Courier New]}[/FONT][/SIZE]
Originally posted by NinjaTrader_Josh View PostYou need to dispose to release the resources of that object or else it will hang there. Long story short: it is bad to leave things uncleaned up.
You place it just like how it is in the SampleCustomEvents reference indicator.
Please post the line you are using in the Initalize() method. Also post up the lines you are using for setting the timer interval and starting it.Last edited by SystemTrading; 09-02-2008, 06:36 PM.
Comment
-
After running this morning I got some interesting results. When the market is actually active, I do not get the error. I still believe that I am sending duplicate orders too frequently, prompting the IgnorePlaceOrders method in Ninja.
Comment
-
The issue essentially boils down to that NinjaTrader is multi threaded so it doesn't guarantee that everything is synchronized. When you trade on your own custom event interval at very short frequencies you can be sending orders 5-10 times on a single tick. I would expect the exchange not to like this and when they are trying to send you back order state changes you have already tried to change your order again. This is probably where the IgnorePlaceOrders is coming from.
I would recommend you not place orders from within your custom timer event. To change orders as often as possible placing it in the OnBarUpdate() with CalculateOnBarClose set to false is already the best possible time for modifying orders on every change of the market.Josh P.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by rene69851, 05-02-2024, 03:25 PM
|
1 response
20 views
0 likes
|
Last Post
by rene69851
Today, 08:20 PM
|
||
Started by ETFVoyageur, Yesterday, 07:05 PM
|
5 responses
42 views
0 likes
|
Last Post
by ETFVoyageur
Today, 08:08 PM
|
||
Started by jpeep, 08-16-2020, 08:31 AM
|
13 responses
487 views
0 likes
|
Last Post
by notenufftime
Today, 07:39 PM
|
||
Started by realblubb, 04-28-2024, 09:28 AM
|
2 responses
32 views
0 likes
|
Last Post
by realblubb
Today, 07:35 PM
|
||
Started by bmarovets, Today, 06:33 PM
|
0 responses
12 views
0 likes
|
Last Post
by bmarovets
Today, 06:33 PM
|
Comment