NinjaTrader Support Forum  

Go Back   NinjaTrader Support Forum > Application Technical Support > Automated Trading

Automated Trading Support for automated trading systems using NinjaScript. Support for our ATI (Automated Trading Interface) used to link an external application such as TradeStation and eSignal to NinjaTrader.

Reply
 
Thread Tools Display Modes
Old 08-19-2008, 02:21 PM   #1
trock168
Junior Member
 
Join Date: Aug 2008
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
Default OnTimer event

Is there an OnTimer event in NT? If not is there a work around? Thanks.
trock168 is offline  
Reply With Quote
Old 08-19-2008, 03:12 PM   #2
NinjaTrader_Ray
Administrator
 
NinjaTrader_Ray's Avatar
 
Join Date: Nov 2004
Location: Denver, CO, USA
Posts: 11,163
Thanks: 6
Thanked 45 times in 32 posts
Default

You can use the following method TriggerCustomEvent() and then you can use standard .NET System Timer class.

http://www.ninjatrader-support.com/H...stomEvent.html
NinjaTrader_Ray is offline  
Reply With Quote
Old 08-19-2008, 06:58 PM   #3
trock168
Junior Member
 
Join Date: Aug 2008
Posts: 7
Thanks: 0
Thanked 0 times in 0 posts
Default

Got it. Thanks a lot!
trock168 is offline  
Reply With Quote
Old 12-16-2008, 10:50 PM   #4
KBJ
Senior Member
 
Join Date: Mar 2007
Location: , Florida, USA
Posts: 663
Thanks: 36
Thanked 7 times in 6 posts
Default

Quote:
Originally Posted by NinjaTrader_Ray View Post
You can use the following method TriggerCustomEvent() and then you can use standard .NET System Timer class.

http://www.ninjatrader-support.com/H...stomEvent.html
I find this help entry to be confusing, since the Syntax section for TriggerCustomEvent shows that the TriggerCustomEvent method can have either 2 or 3 arguments, whereas the Examples section gives an example with only 1 argument.
KBJ is offline  
Reply With Quote
Old 12-17-2008, 06:28 AM   #5
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,377
Thanks: 252
Thanked 966 times in 949 posts
Default

Thanks for the feedback KBJ, please also review this reference sample using the TriggerCustomEvent() - http://www.ninjatrader-support2.com/...ead.php?t=5965
NinjaTrader_Bertrand is offline  
Reply With Quote
Old 12-17-2008, 12:43 PM   #6
KBJ
Senior Member
 
Join Date: Mar 2007
Location: , Florida, USA
Posts: 663
Thanks: 36
Thanked 7 times in 6 posts
Default

Sorry, I forgot to mention that I had already done that.

What I noticed was that the reference sample does not match the example given in the help.

When I implemented code in a fashion matching the reference sample (instead of matching the help example), I found that the code consistently aborted giving me a repeating message stating that NinjaTrader had to be restarted.

That was the point that I backed out the use of TriggerCustomEvent and made my earlier posting, hoping that the help would be fixed and elaborated on.

By the way, when the help is fixed, can this be posted somewhere that we can access it online, without having to wait for the next NinjaTrader update?
KBJ is offline  
Reply With Quote
Old 12-17-2008, 01:33 PM   #7
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

Not sure I follow KBJ. Are you saying the reference sample crashed NT?
NinjaTrader_Josh is offline  
Reply With Quote
Old 12-17-2008, 05:20 PM   #8
KBJ
Senior Member
 
Join Date: Mar 2007
Location: , Florida, USA
Posts: 663
Thanks: 36
Thanked 7 times in 6 posts
Default

No, what I'm saying is that I had trouble with code that I wrote which looked like this....

Code:
private void OnTimer(object sender, EventArgs e)
{
  TriggerCustomEvent( new CustomEvent( TimerSynchronized ), 0 );
  timer.Enabled = false;    // Done with the timer.
}

private void TimerSynchronized(object obj)
{
  Special_Timer_Flag = true;
}
I realize that this is not what's in the help, and it's not what's in the reference sample either. I'm confused because the help and the reference sample conflict with each other.

I notice that the reference sample doesn't mention "CustomEvent" at all, so does this mean it's obsolete?

Could someone who's familiar with Ninja internals please document what the parameters are supposed to be for "new CustomEvent()" and how these parameters are supposed to be used?
KBJ is offline  
Reply With Quote
Old 12-18-2008, 07:23 AM   #9
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

KBJ,

Not sure why you think they conflict. They are inline with each other and will work as advertised.

new CustomEvent(MyCustomHandler, 0, "myText")
NinjaTrader_Josh is offline  
Reply With Quote
Old 12-18-2008, 09:06 AM   #10
KBJ
Senior Member
 
Join Date: Mar 2007
Location: , Florida, USA
Posts: 663
Thanks: 36
Thanked 7 times in 6 posts
Default

Quote:
Originally Posted by NinjaTrader_Josh View Post
Not sure why you think they conflict. They are inline with each other and will work as advertised.

new CustomEvent(MyCustomHandler, 0, "myText")
The help for TriggerCustomEvent says:
Code:
Examples
...
TriggerCustomEvent(new CustomEvent(MyCustomHandler, 0, "myText"));
Thus, there is one argument to TriggerCustomEvent in that example, which is:
Code:
new CustomEvent(MyCustomHandler, 0, "myText")
The syntax shown for TriggerCustomEvent in the help description shows 2 or 3 arguments:
Code:
Syntax 
TriggerCustomEvent(CustomEvent customEvent, object state)
TriggerCustomEvent(CustomEvent customEvent, int barsIndex, object state)
and the reference sample uses 2 arguments:
Code:
TriggerCustomEvent(MyCustomHandler, myTimer.Interval);
See what I mean?
Last edited by KBJ; 12-18-2008 at 09:14 AM.
KBJ is offline  
Reply With Quote
Old 12-18-2008, 10:03 AM   #11
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

I see. Disregard the Syntax portion and just go with what you see in either the Help Guide example or the reference sample.
NinjaTrader_Josh is offline  
Reply With Quote
Old 12-18-2008, 10:30 AM   #12
KBJ
Senior Member
 
Join Date: Mar 2007
Location: , Florida, USA
Posts: 663
Thanks: 36
Thanked 7 times in 6 posts
Default

I'm still confused, as the Help Guide example (1 argument, undocumented syntax) disagrees with the reference sample (2 arguments).
KBJ is offline  
Reply With Quote
Old 12-18-2008, 10:47 AM   #13
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 106 times in 70 posts
Default

KBJ,

Disregard trying to correlate the two into one overload. Just call your CustomEvent and pass the object afterwards. Easiest to just follow the reference sample.
NinjaTrader_Josh is offline  
Reply With Quote
Old 01-07-2010, 12:13 PM   #14
jonnyg
Junior Member
 
Join Date: Jan 2010
Posts: 3
Thanks: 0
Thanked 0 times in 0 posts
Default TriggerCustomEvent

When I call:
TriggerCustomEvent(MyCustomHandler, myTimer.Interval);
as listed in the SampleCustomEvents.cs example, I get a compiler error:

Strategy\drawtest1.cs No overload for method 'TriggerCustomEvent' takes '2' arguments CS1501 - click for info 57 4

Also, using:
TriggerCustomEvent(new CustomEvent(MyCustomHandler), e);
gives the same error.

TriggerCustomEvent(MyCustomHandler, 1, "message");
compiles, but MyCustomHandler is never called. I know from debugging that TriggerCustomEvent *is* called.

Can you tell me which invocation I should be trying to use? I expect I'm making an error somewhere, but am confused by the differences/conflicts in the examples and in the documentation.

Thanks.
jonnyg is offline  
Reply With Quote
Old 01-07-2010, 01:19 PM   #15
jonnyg
Junior Member
 
Join Date: Jan 2010
Posts: 3
Thanks: 0
Thanked 0 times in 0 posts
Default

My apologies, but of course not long after I posted my message, I tried something that finally worked. I called:

TriggerCustomEvent(new CustomEvent(MyCustomHandler), BarsInProgress, 1);

Apparently, it is important to pass in the correct 'BarsInProgress' value.

Also, note that you can also call:
TriggerCustomEvent(MyCustomHandler, BarsInProgress, 1);

If I could find documentation on CustomEvent, I might be able to figure out why that is.
jonnyg 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
MouseMove event cls71 General Programming 34 11-24-2010 06:44 AM
Mouse Event shortorlong Charting 3 07-26-2008 11:59 AM
event-driven methods? mktrend General Programming 8 04-29-2008 06:17 AM
Order Event Warning Moda1 Miscellaneous Support 4 02-14-2008 09:44 AM
Chaining strategy and event afifio ATM Strategies (Discretionary Trading) 6 06-26-2005 01:52 PM


All times are GMT -6. The time now is 06:43 AM.