NinjaTrader Support Forum  

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 08-13-2012, 04:41 PM   #1
gsreddy
Member
 
Join Date: May 2012
Posts: 46
Thanks: 12
Thanked 2 times in 2 posts
Exclamation Multiple Entries with SET methods to exit (OCO)

Hi,
Can you please explain how the strategy works with multiple entries with different entry name with setprofittarget and setstoploss for exits for below two cases? It will be great if you can answer all the questions, it will help me in my strategy design and helps in understanding order execution. I went through the HELP and understand most of it related to SET methods. I am more interested in Case1 as I will have more control to modify Profit Target (PT). i have not started implementing entry and exits in my strategy(to go live) as i have not completely understand the process.

I have used ES price for examples and used below long limit order for entry
EnterLongLimit(int barsInProgressIndex, bool liveUntilCancelled, int quantity, double limitPrice, string signalName)

Case1: current market is trading @ 1390 and executed below two entry methods at same price
Entry 1: EnterLongLimit(0, true,1,1389, “entry1”)
Entry 2: EnterLongLimit(0, true,1,1389, “entry2”)
SetProfitTarget(“entry1”, CalculationMode.Ticks, 4)
SetStopLoss(“entry1”, CalculationMode.Ticks, 4,false)
SetProfitTarget(“entry2”, CalculationMode.Ticks, 4)
SetStopLoss(“entry2”, CalculationMode.Ticks, 4,false)
If entry1 gets filled and market moves 5 ticks in favor,
will the profit target for entry1 gets filled and stop loss for entry1 gets cancelled (Entry2 limit buy order is still in the exchange, not yet filled)?
What will happen to entry2?

When the market comes below entry2 level after trading above entry1 PT(assuming entry1 exited with PT) will it get filled with entry2 price and sends PT and Stoploss orders for entry2?

If entry1 and 2 gets filled at the same time and sends exit orders for PT and Stoploss,
can I update the PT for one of the entries by resetting the profit target with fromEntrySignal SetProfitTarget(“entry1”, CalculationMode.Ticks, 24)?

Case2: current market is trading @ 1390 and executed below entry method along with SET methods
Entry 3: EnterLongLimit(0, true,100,1389, “entry3”)
SetProfitTarget(“entry3”, CalculationMode.Ticks, 4)
SetStopLoss(“entry3”, CalculationMode.Ticks, 4,false)

If the price comes to 1389 and partially fill 10 out of 100,
will the profit target and stop loss be set for 10 related to entry3?

if the market moves in favor and traders above entry3 PT will the PT order gets filled and cancels stoploss order for 10 quantity?

If there is a partial fill @ entry3 profit target (4 out of 10) and market comes back to entry3 level(1389) and partially fill 20 out of 90 (remaining 100 -10), will these 20 gets added to PT and stop loss orders?

Can this process partial fill/ exit with PT or complete fill with PT or Stop loss continues till entry3 quantity completely fill?

Thanks
gsreddy.
gsreddy is offline  
Reply With Quote
Old 08-13-2012, 09:24 PM   #2
NinjaTrader_Matthew
NinjaTrader Customer Service
 
NinjaTrader_Matthew's Avatar
 
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 5,710
Thanks: 189
Thanked 772 times in 739 posts
Default

Quote:
Originally Posted by gsreddy View Post
If entry1 gets filled and market moves 5 ticks in favor,
will the profit target for entry1 gets filled and stop loss for entry1 gets cancelled (Entry2 limit buy order is still in the exchange, not yet filled)?
What will happen to entry2?
This would depend on how quickly this occurs. If the market is moving quick enough, it's possible that the price will exceed the level you are submitting the profit target before the target has been accepted by the broker.

For the quickest submission of your Stops and Targets, we recommend placing these in OnExecution() or OnOrderUpdate():

http://www.ninjatrader.com/support/f...ead.php?t=7499

Entry 2 would not be filled unless price came back down to your original working price.


Quote:
Originally Posted by gsreddy View Post
When the market comes below entry2 level after trading above entry1 PT(assuming entry1 exited with PT) will it get filled with entry2 price and sends PT and Stoploss orders for entry2?
Yes, this is correct.

Quote:
Originally Posted by gsreddy View Post
If entry1 and 2 gets filled at the same time and sends exit orders for PT and Stoploss,
can I update the PT for one of the entries by resetting the profit target with fromEntrySignal SetProfitTarget(“entry1”, CalculationMode.Ticks, 24)?
Yes, you can change the profit target dynamically under certain conditions. Please have a look at our reference sample on changing profit target and stop loss orders:

http://www.ninjatrader.com/support/f...ead.php?t=3222

Quote:
Originally Posted by gsreddy View Post
If the price comes to 1389 and partially fill 10 out of 100,
will the profit target and stop loss be set for 10 related to entry3?
Yes, it would match the position quantity.

"A strategy will either generate a target order for each partial fill of an entry order or one order for all fills."

This means you may have 10 contracts as a target and another 90 elsewhere, depending on how you were filled.

You can test this out by going to Tools--> Options--> Simulator tab--> check "Enforce Partial Fills". Then you can run the strategy in the Sim101 account and see how it will behave on a partial fill.


Quote:
Originally Posted by gsreddy View Post
if the market moves in favor and traders above entry3 PT will the PT order gets filled and cancels stoploss order for 10 quantity?
Yes.

Quote:
Originally Posted by gsreddy View Post
If there is a partial fill @ entry3 profit target (4 out of 10) and market comes back to entry3 level(1389) and partially fill 20 out of 90 (remaining 100 -10), will these 20 gets added to PT and stop loss orders?
Yes

Quote:
Originally Posted by gsreddy View Post
Can this process partial fill/ exit with PT or complete fill with PT or Stop loss continues till entry3 quantity completely fill?
Yes, this would be the designed behavior.

Please let me know if you have additional questions.
NinjaTrader_Matthew is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Matthew for this post:
Old 08-13-2012, 10:42 PM   #3
gsreddy
Member
 
Join Date: May 2012
Posts: 46
Thanks: 12
Thanked 2 times in 2 posts
Default

Hi,

Thanks for providing all the answers. This clarifies lot of question on OCO orders and Helps me complete my design on order entry/exits.

I just started thing of possible error handling.
Can you please point me to any extensive discussion thread related to error handling on entry, exit orders and connection losses (Not the Ninja HELP)? Would like to know more on real time errors after go live with a completely automated strategy.

Thanks,
gsreddy.
gsreddy is offline  
Reply With Quote
Old 08-13-2012, 10:54 PM   #4
NinjaTrader_Matthew
NinjaTrader Customer Service
 
NinjaTrader_Matthew's Avatar
 
Join Date: Apr 2010
Location: Denver, CO, USA
Posts: 5,710
Thanks: 189
Thanked 772 times in 739 posts
Default

I don't have any threads handy for you to read.

I'd suggest submitting initial illegal orders, such as a stop above/below the current price.

You can use the OnOrderUpdate event to capture the order state.
http://www.ninjatrader.com/support/h...rderupdate.htm

Code:
protected override void OnOrderUpdate(IOrder order)
{
	if (order.OrderState == OrderState.Rejected)
	{
		//do something
	}
}
NinjaTrader_Matthew is offline  
Reply With Quote
The following user says thank you to NinjaTrader_Matthew for this post:
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
How to Set OCO Entry Orders With ATM Strategy? maxreturn ATM Strategies (Discretionary Trading) 11 05-21-2012 11:02 AM
When does the framework call the 'set' methods for strategy parameters? HitTheCity Strategy Development 4 04-13-2012 05:21 AM
Multiple output methods Hawk Arps General Programming 2 07-11-2011 04:23 PM
unable to script strategy with entries limit and stop OCO adamus Strategy Development 2 08-06-2010 12:05 PM
Chart Trader: Condition based entries, time-axis entries, multiple OCO pairs etc. Elliott Wave Suggestions And Feedback 1 11-25-2008 04:23 AM


All times are GMT -6. The time now is 03:20 PM.