![]() |
|
|||||||
| General Programming General NinjaScript programming questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Nov 2010
Posts: 51
Thanks: 8
Thanked 3 times in 3 posts
|
Hi,
I have a fairly complex strategy that uses a timer and MarketData updates. I am trying to debug the following errror: **NT** Error on calling 'OnMarketData' method for strategy 'XXXXXXXXXXX/93f924f11b9f479caea25cf72ea3b31d': Item has already been added. Key in dictionary: 'PnL' Key being added: 'PnL' I am hoping you can tell me what NinjaTrader functions might e setting this key 'PnL' so I can lock code segment to avoid this collision. Thanks, |
|
|
|
|
|
#2 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
|
NJA_MC, this would normally not be a default OnMarketData() event arg - http://www.ninjatrader.com/support/h...aeventargs.htm
Do you write to a custom DB here in your script? You could look into adding try / catch blocks to isolate further the code section giving rise to the issues seen.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
The following user says thank you to NinjaTrader_Bertrand for this post: |
|
|
|
#3 | |
|
Member
Join Date: Nov 2010
Posts: 51
Thanks: 8
Thanked 3 times in 3 posts
|
Quote:
Regards, |
|
|
|
|
|
|
#4 |
|
Member
Join Date: Nov 2010
Posts: 51
Thanks: 8
Thanked 3 times in 3 posts
|
Okay,
Kinda Stuck, I am starting to think this might be a side-affect of using Replay with "TriggerCustomEvent()" functions. Do you know if they are compatible. I know you guys do something a little different in replay mode. I am wondering if I am chasing a ghost and will not see the issue with a real-time run. I seem to get almost Random errors with this code segment under Replay as I don't want to spend weeks checking to see if this is a problem real-time. Code:
public void SetupTimer(int m_milliseconds)
{
if (Historical)
return; // Ignore timer requests in Historical Mode
Print(" SetupTimer: "+m_milliseconds+" ms");
if (m_timer==null)
{
Print(" NEW TIMER SetupTimer: "+m_milliseconds+" ms");
m_timer = new System.Timers.Timer();
//m_timer.Elapsed += (sender, args) => TimerEventProcessor("myCallHere", args);
m_timer.Elapsed+=new ElapsedEventHandler(TimerEventProcessor);
}
if (!m_timer.Enabled)
{
m_timer.Interval=m_milliseconds;
m_timer.AutoReset=true; // Must Start() for each interval;
m_timer.Start();
Print(" Vol:STARTED SetupTimer: "+m_milliseconds+" ms");
}
}
void TimerEventProcessor(Object myObject, EventArgs myEventArgs)
{
try
{
TriggerCustomEvent(MyCustomHandler, 0, myObject);
}
catch (Exception e)
{
Print("Exception CustomHandler "+e.ToString());
}
}
private void MyCustomHandler(object state)
{
}
4/25/2012 9:57:20 PM|3|128|Error on triggering custom event for strategy 'GHPVolatilityBreakOut01/5b6c2ac3e2c745ca9f5d4405a01c26f2': More than 100 subsequent user events or 4/25/2012 9:36:12 PM|3|128|Error on triggering custom event for strategy 'GHPVolatilityBreakOut01/842fb6b7c3624543a3115011bab59cfb': Object reference not set to an instance of an object. I have tried this without the Try/Catch with the same results.. Seems like the random result might be do to funny timing with the Replay Connection at high rates of speed? Is there a way to confirm this without spending weeks testing? |
|
|
|
|
|
#5 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
|
For this setup, please try with a higher .MaxProcessedEvents in Initialize(), this would be an undocumented property that could help you here testing the trigger event with higher speeds in replay. I don't feel this would be an issue realtime, as it's likely just seen in high speed replay as a large # method calls / events are queued up before control is returned to NT.
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Senior Member
Join Date: Dec 2009
Location: Netherlands
Posts: 180
Thanks: 15
Thanked 72 times in 51 posts
|
|
|
|
|
|
The following user says thank you to marcow for this post: |
|
|
|
#7 |
|
Member
Join Date: Nov 2010
Posts: 51
Thanks: 8
Thanked 3 times in 3 posts
|
Hi,
I tried setting that parameter to 1000. Still getting problems with the same shell code, at about the same point when it was the default 100. I was expecting it to be 10 times longer or somewhere around there if this had an impact. This time I got this error: **NT** Error on triggering custom event for strategy 'GHPVolatilityBreakOut01/bd4314bf54644255b5dd2dfe6b5af4a8': Collection was modified; enumeration operation may not execute. The strange thing is the Try/Catch doesn't trigger on any of these error, so I can't stop the damage which is the Unmanaged Orders stop being processed. |
|
|
|
|
|
#8 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,569
Thanks: 262
Thanked 1,018 times in 999 posts
|
Hi NJA_MC, you're running into a different error now, the queued up custom event chain is resolved with the higher max processed setting you use. It looks to me like the code is not prepared to run this quick event wise in a multi threading environment - do you see this at all when running slower in your replay?
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#9 |
|
Member
Join Date: Nov 2010
Posts: 51
Thanks: 8
Thanked 3 times in 3 posts
|
Hi Bertrand,
Speed does seem to affect the frequency but the errors seem to be random. I have a few new errors being cause by simply the CustomerTimerFunction: **NT** Error on triggering custom event for strategy 'GHPVolatilityBreakOut01/f25b3354922744508726c3391430a9e9': Object reference not set to an instance of an object. **NT** Error on triggering custom event for strategy 'GHPVolatilityBreakOut01/f25b3354922744508726c3391430a9e9': You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart. I did add back in some of the code in the timed event which may give new perspective on the issue: Error on calling 'OnBarUpdate' method for indicator 'TradersDynamicIndexzt379': Item has already been added. Key in dictionary: 'My down arrow275' Key being added: 'My down arrow275' **NT** Error on calling 'OnOrderStatus' method for strategy 'GHPVolatilityBreakOut01/73f10ea00aea444980c098056552b14e': Collection was modified; enumeration operation may not execute. It seems like this might be a Replay issue, is there a way I might be able to force better synchronization. I have found these commands: Account.SimulationReset(); Account.SimulationSynchronize(); Can I add the Synchronization function or something similar before the call to the timer function to see if that helps get NT ready for the CustomerTimer even? |
|
|
|
|
|
#10 |
|
NinjaTrader Customer Service
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,499
Thanks: 109
Thanked 291 times in 280 posts
|
Hello,
This is Brett assisting for Bertrand who will be out of the office this week. I am starting over new on your ticket therefor I have gone over it but i may be restating something Bertrand stated apologize for the inconvenience. Here is what I am interested in. What specifically is causing the log error: **NT** Error on triggering custom event for strategy 'GHPVolatilityBreakOut01/f25b3354922744508726c3391430a9e9': Object reference not set to an instance of an object. To isolate this if it was my code is first start pulling out everything I do in the custom method I am calling.Can you please create a new test indicator and then delete all the code out of the method and then test. Does the fact of just the timer event there cause the issue or not? If not then continue by adding in half the lines of code back or whatever is easiest to test on. Does it happen now? Specifically I'm interested what exact line of code in the custom method is giving us issue or is it not related to the code in the custom method and is instead related to the custom event NinjaTrader method. -Brett
Brett
NinjaTrader Customer Service |
|
|
|
|
|
#11 |
|
Member
Join Date: Nov 2010
Posts: 51
Thanks: 8
Thanked 3 times in 3 posts
|
Hi Brett,
That is current where I am at which is what doesn't make sense. As you can see in post #4, there is a shell of a code which just calls the TriggerCustomEvent with nothing in the event. So just be basic NT functions are creating the error (which vary from time to time). Regards, |
|
|
|
|
|
#12 |
|
NinjaTrader Customer Service
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,499
Thanks: 109
Thanked 291 times in 280 posts
|
Can you please post this strategy so I can run tests on my side and the if the test conditions are not already defined please let me know what settings and time and date to reply and I will do some tests to attempt to replicate the problem.
I understand its random however I would need to run some tests on my side to get it into development and would need reproduce it at least once on my side. -Brett
Brett
NinjaTrader Customer Service |
|
|
|
|
|
#13 |
|
Member
Join Date: Nov 2010
Posts: 51
Thanks: 8
Thanked 3 times in 3 posts
|
I will see if I can make a generic version I can post, if not I may need to email you the code privately as it has proprietary code (which is quite complex, used for placing orders).
In the mean time, it does look like this thread had the same/similar problem: http://www.ninjatrader.com/support/f...ad.php?t=20470 I don't know if NT came up with a solution here... |
|
|
|
|
|
#14 |
|
NinjaTrader Customer Service
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,499
Thanks: 109
Thanked 291 times in 280 posts
|
Please simplify down if possible.
If this is not possible you can email me to support at ninjatrader dot com ATTN: Brett. -Brett
Brett
NinjaTrader Customer Service |
|
|
|
|
|
#15 |
|
Senior Member
Join Date: Dec 2009
Location: Netherlands
Posts: 180
Thanks: 15
Thanked 72 times in 51 posts
|
sorry NJA_MC to hijack your thread, I posted a suggestion in the suggestions thread for a native NinjaTrader Timer Method, see http://www.ninjatrader.com/support/f...ad.php?t=49494
Marco |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Multi-instrument strategy PnL | jp_kettunen | Miscellaneous Support | 5 | 03-18-2010 09:46 AM |
| Is OnMarketData multi-threaded? | evlap | General Programming | 2 | 10-24-2009 11:46 AM |
| Exposing a dictionary | blarouche | Indicator Development | 8 | 10-20-2009 10:25 AM |
| NT is multi-threaded? | JS999 | Suggestions And Feedback | 3 | 04-16-2009 09:03 AM |
| Multi-Threaded | bsamani | General Programming | 1 | 02-08-2009 09:24 AM |