NinjaTrader Support Forum  
X

Attention!

This website will be down for maintenance from Friday May 24th at 6PM MDT until Saturday May 25th at 11AM MDT. We apologize for the inconvenience. If you need assistance during this time, please email sales@ninjatrader.com


Go Back   NinjaTrader Support Forum > NinjaScript Development Support > General Programming

General Programming General NinjaScript programming questions.

Reply
 
Thread Tools Display Modes
Old 04-30-2012, 07:02 PM   #16
NJA_MC
Member
 
Join Date: Nov 2010
Posts: 51
Thanks: 8
Thanked 3 times in 3 posts
Default

Hi Brett,

Here is a simple strategy, but it does similar things to what I am seeing in the complex case. It will give you something to play with. You can see there is nothing in the Custom Event section. It is truly the TriggerCustomEvent() that creates the error, and I can't trap it, which may be part of the problem...

It is run on a 4 Range chart on the CL 03-12 for 1/23/2012 (Downloaded the data from your service).

I have enclosed a Pic to show you what happens, trades just stop occurring..... The error on this one has been consistently this error:
**NT** Error on triggering custom event for strategy 'NTTimerTesting/b72dfaea2c654817b98e737a5340f26c': Collection was modified; enumeration operation may not execute.

Time of the error will depend upon your system speed, I have run this at 500X and got the problem anywhere from 4AM to 2PM on that day. Your mileage may vary....

I enclosed the Log file as well.
Attached Images
File Type: png Stopped.png (157.5 KB, 9 views)
Attached Files
File Type: zip NTTimerTesting.zip (14.8 KB, 10 views)
File Type: zip log.20120430.zip (170.3 KB, 0 views)
NJA_MC is offline  
Reply With Quote
Old 05-01-2012, 12:08 PM   #17
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
Default

Hello,

I have not had a chance to setup tests yet. However I did review the code.

The only thing I see of the top of the head is that you are not disposing your timer in OnTermination()? If this just in the sample code or the production code as well?

-Brett
NinjaTrader_Brett is offline  
Reply With Quote
Old 05-01-2012, 05:39 PM   #18
NJA_MC
Member
 
Join Date: Nov 2010
Posts: 51
Thanks: 8
Thanked 3 times in 3 posts
Default

Mainly just this code, I will play with it but I know you can restart NT and get this error, so it would not have called the OnTerminate(). Certainly for subsequent runs, it may be an issue, but I could see the timed events (printing) where it still seems like only one occurance is running. Sometimes I need to restart NT to get the new software libraries to load.

Although that is better practice, I don't think it is the cause of the problem I am seeing.
NJA_MC is offline  
Reply With Quote
Old 05-02-2012, 06:49 AM   #19
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
Default

Thanks for that.

To clarify, you only see this in market replay and you have not seen it in live correct?

-Brett
NinjaTrader_Brett is offline  
Reply With Quote
Old 05-02-2012, 06:58 AM   #20
NJA_MC
Member
 
Join Date: Nov 2010
Posts: 51
Thanks: 8
Thanked 3 times in 3 posts
Default

Unfortunately, I haven't done enough live testing yet to really trigger the issue. I was hoping to find the cause of the issue before burning lots of time (at 1X).

Replay is currently the only confirmed fault to date.
NJA_MC is offline  
Reply With Quote
Old 05-02-2012, 07:03 AM   #21
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
Default

I see.

I was able to replicate, with that said however I feel that using a timer and setting market replay at anything other then 1x will give you bad/incorrect results.

As the timer would not be sped up but the bars would be. Throwing off all timing and accuracy of your code.

Therefor the primary issue is it simply doesn't make since to debug a scenario that is not accurate or correct in the first place. Do you disagree?

-Brett
NinjaTrader_Brett is offline  
Reply With Quote
Old 05-02-2012, 07:15 AM   #22
NJA_MC
Member
 
Join Date: Nov 2010
Posts: 51
Thanks: 8
Thanked 3 times in 3 posts
Default

Hi Brett,

I understand your reasoning. I would not have a big issue with this error if I could be sure it was a replay issue only. I am hoping you guys can confirm that fact, maybe it gives you insite into a different issue as it would seem NT shouldn't through this error.

From a Sim perspective, although I know the Timed Events are not valid, there are times you want to test the strategy containing timed events but simply looking at other aspects of the logic such as Entry, Exit, trailing, and money management. In these cases, I would still want to run at 500X. If I knew this issue was within the Replay section, and you guys could point me to detecting a Sim account running >1X, I could disable the timer automatically (As I speed up/slow down as thing of interest happen).

Hopeful that makes sense. So if we can get some level of comfort that order entry isn't going to freeze like the demo in Live runs or 1X and I can screen >1X, I can get around this issue. My biggest concern is if this same fault could occur Live Trading and freeze an order open!

Thanks,
NJA_MC is offline  
Reply With Quote
Old 05-02-2012, 12:40 PM   #23
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
Default

Understood.

Giving you a quick update I have already contacted development to get a bit more information on this and this is expected. If it is not expected we will check into it further and if expected then running in live shouldn't give you any issues.

I will update you when I have heard back.

-Brett
NinjaTrader_Brett is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Brett for this post:
Old 05-02-2012, 02:31 PM   #24
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
Default

Thanks for patience.

Here is what development suggested:

Timers in market replay would not make any sense except in 1x speed. If the instrument he is testing against is liquid enough he could redo the test code with pseudo "close enough" timer based off OnMarketDate timestamps.


Therefor the idea is you should be fine in 1X mode and not run into this. However if you wanted to test it out on live market data you could run tests on this in OnMarketData live and test to make sure you never run into it. We do not suspect that you would however wanted to be the first to know if you did.

-Brett
NinjaTrader_Brett is offline  
Reply With Quote
Old 05-02-2012, 02:35 PM   #25
NJA_MC
Member
 
Join Date: Nov 2010
Posts: 51
Thanks: 8
Thanked 3 times in 3 posts
Default

Okay,

So it sounds like Development said this is a replay issue only?

What I would like to do is detect if the "strategy" is in replay mode and if it is >1X, is there a way I can do this?

Thanks,
NJA_MC is offline  
Reply With Quote
Old 05-02-2012, 02:36 PM   #26
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
Default

Sorry, no facilities to that. I will send the user request in.

-Brett
NinjaTrader_Brett is offline  
Reply With Quote
Old 05-04-2012, 07:04 PM   #27
NJA_MC
Member
 
Join Date: Nov 2010
Posts: 51
Thanks: 8
Thanked 3 times in 3 posts
Default

I am struggling to get around this issue during simulations. It would be nice if I could at least Try/Catch the error, but NT doesn't seem to through an exception. It only reports this type of error:
**NT** Error on calling 'OnMarketData' method for strategy 'GHPLOMSampleGoodUntilTime/edcb6a99aeaa48e2ba03582b14fc2a95': Collection was modified; enumeration operation may not execute.

If I could catch this and have the strategy continue would be fine, but right now, it trashes the ability to place orders for some reason.
NJA_MC is offline  
Reply With Quote
Old 05-07-2012, 06:06 AM   #28
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
Default

Just curious have to tried a Try/Catch around OnMarketData()?

What code segment is generating this error? I would not expect this to be related at all to our other issue.

-Brett
NinjaTrader_Brett is offline  
Reply With Quote
Old 05-07-2012, 07:49 AM   #29
NJA_MC
Member
 
Join Date: Nov 2010
Posts: 51
Thanks: 8
Thanked 3 times in 3 posts
Default

Brett,

Thanks, I have tried that. As you can see if the demo version I posted, you cannot trap that "error" from the CustomTimerEvent() function either. It stops NT7 from processing Orders which is the issue. If I could trap the error and ignore it, that would be one thing, but it doesn't seem like the error is Thrown, but simply reported from NT7.
NJA_MC is offline  
Reply With Quote
Old 05-07-2012, 08:19 AM   #30
NinjaTrader_Brett
NinjaTrader Customer Service
 
NinjaTrader_Brett's Avatar
 
Join Date: Dec 2009
Location: Denver, CO, USA
Posts: 6,498
Thanks: 109
Thanked 291 times in 280 posts
Default

Ok, so in that case we would need to reset here and re attack this new case.

Is it somehow related to the timer again? If it is I would be sure to get it into development.

I would not expect an NT method to fail, unless there was some code inside the override that you are doing to cause this.

What specifically are you doing inside of OnMarketData()?

Is this in market reply or live data?


-Brett
NinjaTrader_Brett is offline  
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

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


All times are GMT -6. The time now is 06:13 PM.