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 > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

Reply
 
Thread Tools Display Modes
Old 01-15-2011, 10:35 AM   #1
Jim-Boulder
Senior Member
 
Join Date: May 2007
Posts: 154
Thanks: 0
Thanked 0 times in 0 posts
Default Question on A reference Sample

I have a question of the reference sample:

Strategy: Using OnOrderUpdate() and OnExecution() methods to submit protective orders

I assume the point of the example is to show how to submit stops and targets in the OnExecution method--but in the reference the stopOrder is submitted in the OnBarUpdate method once price has moved 4 ticks in our favor

Is there a reason that the stopOrder is submitted in the OnBarUpdate method and not in the OnExecution method? Is it because we can't get the 'last' trade price (Close[0]) in the OnExecution method?

I am not clear when to use OnBarUpdate vs. OnExecution (I realize that OnBarUpdate is triggered either at the start of a new bar or by tick-by-tick depending on CalculateOnBarClose setting while the OnExecution is triggered on Order executions)--but seems like if the point is to submit changes in stop orders or targets as soon as possible-that we would always use OnExecution.

So could you expand on when you should NOT use OnExecution methods to handle changes in stop orders, etc.

thanks.
Jim-Boulder is offline  
Reply With Quote
Old 01-15-2011, 12:41 PM   #2
NinjaTrader_Austin
NinjaTrader Customer Service
 
NinjaTrader_Austin's Avatar
 
Join Date: Jun 2009
Location: Denver, CO
Posts: 3,149
Thanks: 10
Thanked 89 times in 81 posts
Default

Jim, the stopOrder is submitted for the exact reason you've listed. OnExecution() has no idea of the current bars on the chart, so it doesn't know prices. This is why it must be called from OnBarUpdate(), so it can grab the chart prices to place the order at the appropriate place.

OnExecution() should only be used when the order you're trying to submit depends on the fill (or unfilled) status of another order. It should not be used in many other situations. For example, if you're trying to modify the price of a trailing stop order, that would not be an OnExecution() thing; it would occur in OnBarUpdate() (or OnMarketData() or something like that).

Please let us know if you have any other questions.
NinjaTrader_Austin is offline  
Reply With Quote
Reply

Tags
onexecution

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
Reference Sample: Strategy: Stopping a strategy after consecutive losers AnotherTrader Automated Trading 6 02-05-2012 02:15 AM
Real-time Marketh Depth Indicator Reference Sample NinjaTrader_Ray Indicator Development 17 11-29-2011 02:21 AM
Question about Reference Sample about OnExection method GorSvet Strategy Development 1 01-23-2009 03:59 PM
Sample Strategy octrout Strategy Development 1 10-21-2008 12:20 PM
Reference sample request pdawg Indicator Development 2 04-09-2008 11:49 PM


All times are GMT -6. The time now is 07:09 PM.