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 > 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 07-25-2011, 07:47 AM   #1
outstretchedarm
Senior Member
 
Join Date: Jun 2011
Posts: 120
Thanks: 10
Thanked 3 times in 3 posts
Default Closing an Automated Trade Position with a Limit Order

hello all,

let's say your automated trading strategy creates a juicy trade. you are way up, and you want to take profits, instead of waiting for strategy to exit.

what is correct way to exit the trade so that:

a) you place a limit order and get that current profitable price? (not a less profitable market price)

b) you don't mess up the strategy's "accounting", meaning after you exit, the strategy will show a flat position, not 1L or what have you.

thanks in advance. you are generally super helpful.
outstretchedarm is offline  
Reply With Quote
Old 07-25-2011, 08:04 AM   #2
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,

Thanks for the note.

This depends heavily on the coding of the strategy.

Are you using ATM Strategies or EnterLong() calls?

Mostly however you will want to cancel the strategy and to do this simply hit the Close button. This will close the strategy, get you out of your position, and cancel any remaining orders left. You can then re-enable your strategy at a later time.
NinjaTrader_Brett is offline  
Reply With Quote
Old 07-25-2011, 08:08 AM   #3
outstretchedarm
Senior Member
 
Join Date: Jun 2011
Posts: 120
Thanks: 10
Thanked 3 times in 3 posts
Default

Quote:
Originally Posted by NinjaTrader_Brett View Post
Hello,

Thanks for the note.

This depends heavily on the coding of the strategy.

Are you using ATM Strategies or EnterLong() calls?

Mostly however you will want to cancel the strategy and to do this simply hit the Close button. This will close the strategy, get you out of your position, and cancel any remaining orders left. You can then re-enable your strategy at a later time.
Yes, but I want to get out at a limit price, not market price. that's the crux of the matter.

and for the record, my strategies are coded in terms of EnterLong() calls.


Thanks for responding so quickly
outstretchedarm is offline  
Reply With Quote
Old 07-25-2011, 09:15 AM   #4
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,

In this case I would shutdown the strategy. Strategies Tab->Disable.

Then submit your limit order to exit. By disabling the strategy you will ensure that when you exit, your strategy wont then try to exit at a later time (When the strategy was programmed to exit) to submit a order to sell 1 contract (lets say you where long 1 contract before you did the limit order to go flat) then you would end up with an unexpected short position.

Let me know if I can be of further assistance.
NinjaTrader_Brett is offline  
Reply With Quote
Old 07-25-2011, 09:17 AM   #5
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

You can then re-enable the strategy at a later time and make sure to follow in sync instructions.


Strategy Position vs. Account Position:
http://www.ninjatrader-support2.com/...ead.php?t=4033

1st solution:

You can include the following statement in your code to avoid the strategy to be calculated on historical data.

// Only run on real-time data
if (Historical)
return;
Add the statement to the top of OnBarUpdate()

2nd solution:
You can set 'On starting a real-time strategy' to 'Wait until flat before executing live'.
This option can be found at Tools-->Options-->Strategies-->NinjaScript-tab.

3rd solution, would be submitting manual orders to sync the strategy and account positions described in the link

4th solution, would be to enable Sync account position to true.

http://www.ninjatrader.com/support/h..._positions.htm
NinjaTrader_Brett is offline  
Reply With Quote
Old 07-25-2011, 09:37 AM   #6
outstretchedarm
Senior Member
 
Join Date: Jun 2011
Posts: 120
Thanks: 10
Thanked 3 times in 3 posts
Default

thanks, I'll try this
outstretchedarm is offline  
Reply With Quote
Old 11-21-2011, 09:34 AM   #7
LTWCI
Member
 
Join Date: Sep 2008
Posts: 48
Thanks: 0
Thanked 2 times in 2 posts
Default

I've been experimenting using limit orders in my strategies and see that some strategies don't begin to enter trades. Might this be due to a 2 or more tick gap in the bid to ask price? Also, when using market replay, limit orders don't respond properly in strategies. Market orders work fine. I tested grain futures. It appears that using market orders in strategies works best. In these volatile markets, I would prefer to use limit orders in strategies. Any feedback on this subject?
LTWCI is offline  
Reply With Quote
Old 11-21-2011, 09:54 AM   #8
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,

Thanks for the note.

This is the downside of using limit orders. You will get a good fill but that comes at the price of not getting in the market if the market cannot fill you at that price at that time.

Let me know if you feel something else is going on and what information you have that would help us further assist.

-Brett
NinjaTrader_Brett is offline  
Reply With Quote
Old 11-21-2011, 10:04 AM   #9
outstretchedarm
Senior Member
 
Join Date: Jun 2011
Posts: 120
Thanks: 10
Thanked 3 times in 3 posts
Default

I totally agree with LTWCI. I'd rather get in on limit orders, knowing full well the order might not be filled. I'm trying to make more successful trades, not necessarily more trades.

I have changed certain strategies to limit orders however, only to find that the strategies never fires. I mean, they totally go "green" and never fire and never turn yellow. They just sit there, like they are broken strategies.
outstretchedarm is offline  
Reply With Quote
Old 11-21-2011, 10:10 AM   #10
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

Yellow means waiting to go flat to enter live. This means that your strategy has a position in historical that it has no exited. You will need to wait for the exit for the strategy to enable or turn off the option under control center->tools->options->strategies->ninjascript sub tab->uncheck wait for flat before executing live.

Let me know if I can be of further assistance.
NinjaTrader_Brett is offline  
Reply With Quote
Old 11-21-2011, 10:13 AM   #11
outstretchedarm
Senior Member
 
Join Date: Jun 2011
Posts: 120
Thanks: 10
Thanked 3 times in 3 posts
Default

Yes, we understand that. What I mean is these suckers just stay green.

Usually, when you enable a strategy over a whole bunch of futures, some of them start off yellow, meaning using historical value, they would have already entered hypothetical trades. but when you enable a strategy with limits orders, it is not uncommon to get all greens, which makes me suspicious
outstretchedarm is offline  
Reply With Quote
Old 11-21-2011, 10:43 AM   #12
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,

In this case you needed to make sure you are debugging your strategies correctly and checking there status to make sure everything is correctly operating.

Please see these guides:

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

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

Let me know if I can be of further assistance.
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
Automated Limit Order Problem jul0625 Automated Trading 5 07-05-2011 11:32 AM
Closing ATM or discretionary entries with automated strategies theKonshus1 ATM Strategies (Discretionary Trading) 1 05-01-2011 06:44 PM
Closing a trade - urgent tusurtees Miscellaneous Support 1 02-03-2010 10:32 AM
Enter*Limit order + ProfitTarget + reverse position problem Argo1 Strategy Development 9 09-08-2009 10:04 AM
Automated entry with limit order John_Aus SuperDOM and other Order Entry Windows 5 05-12-2008 09:27 AM


All times are GMT -6. The time now is 04:45 AM.