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 05-27-2009, 02:36 PM   #1
stormze
Member
 
Join Date: Oct 2008
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
Default ExitShort ExitLong behaviour

Hello, Im seeing some kind of problem with a strategy executed in real time on the simulated NT account...
This is the code:
Code:
if(/*some short condition*/)
{
if(Position.Quantity > 0)
 ExitLong(1, 1, "TO_ExitLong", "TO_EnterLong");
if((ToTime(Time[0]) > 103000 && ToTime(Time[0]) < 163000))
 EnterShort(1, 1, "TO_EnterShort");
}
elseif(/*some long condition*/)
{
if(Position.Quantity > 0)
 ExitShort(1, 1, "TO_ExitShort", "TO_EnterShort");
if((ToTime(Time[0]) > 103000 && ToTime(Time[0]) < 163000))
 EnterLong(1, 1, "TO_EnterLong");
}
The problem is that the long condition is executing 2 orders of buy and the short part just closes that 2 positions... (the script never go short)
ExitShort is not acting well, why is that ?

Last edited by stormze; 05-27-2009 at 02:41 PM.
stormze is offline  
Reply With Quote
Old 05-27-2009, 02:38 PM   #2
stormze
Member
 
Join Date: Oct 2008
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
Default

Note: this started happening since I manually closed one of the orders that the script submitted
stormze is offline  
Reply With Quote
Old 05-27-2009, 02:42 PM   #3
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

stormze,

If you want to reverse there is no need to place ExitShort then EnterLong orders like that. Just call EnterLong and just call EnterShort. If you were in an opposing position it will automatically close that position first and then get you into your long/short.
NinjaTrader_Josh is offline  
Reply With Quote
Old 05-27-2009, 02:52 PM   #4
stormze
Member
 
Join Date: Oct 2008
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
Default

I know but I only want to reverse on some circustances and just close the actual position on others.
Apparently when Im long 1 contract and I do a close, instead of selling that contract, is buying another one
stormze is offline  
Reply With Quote
Old 05-27-2009, 03:06 PM   #5
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

If you were long and you called ExitLong() it will close the position. If in addition you called EnterShort() you will for sure get the additional short. You will need to debug your orders to see which are being placed with TraceOrders = true.

http://www.ninjatrader-support2.com/...ead.php?t=3627
NinjaTrader_Josh is offline  
Reply With Quote
Old 05-27-2009, 03:30 PM   #6
stormze
Member
 
Join Date: Oct 2008
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
Default

Ok I will try to collect some logs with TraceOrders = true
But may be there is a bug here, I think what happened is the following:

- Script executed EnterShort of 1 contract
- I manually closed that position and went to flat
- Script executed an ExitShort of 1 contract but it didnt realized that it was already flat and bought 1 contract
- Script executed an EnterLong of 1 contract and bought another contract being long 2 contracts... and so on
stormze is offline  
Reply With Quote
Old 05-27-2009, 03:37 PM   #7
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

Could happen since your code is never checking for a flat. Plus inflight executions can occur. If the execution has not been reported back yet and you still submit a new order it will go through.
NinjaTrader_Josh is offline  
Reply With Quote
Old 05-27-2009, 04:05 PM   #8
stormze
Member
 
Join Date: Oct 2008
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
Default

Ah interesting...
I tryed to check for a flat on my code with

if(Position.Quantity > 0)
close actual position

Is that wrong or some other better way to do it ? Note that all orders are submitted to only one ticker but its not the main ticker
stormze is offline  
Reply With Quote
Old 05-28-2009, 05:17 AM   #9
NinjaTrader_Bertrand
NinjaTrader Customer Service
 
NinjaTrader_Bertrand's Avatar
 
Join Date: Sep 2008
Location: Germany
Posts: 22,567
Thanks: 261
Thanked 1,016 times in 997 posts
Default

You can use Position.MarketPosition for checking if you're flat or not - http://www.ninjatrader-support.com/H...tPosition.html
NinjaTrader_Bertrand is online now  
Reply With Quote
Old 05-28-2009, 10:03 AM   #10
stormze
Member
 
Join Date: Oct 2008
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
Default

Ok I still have the problem.
EnterLong of 1 contract is buiyng me 2 contracts being flat, and I can't change that behaviour
Is acting like if it were short 1 contract.
I tryed reseting the Sim101 db restarting NT but nothing.
What can I do
stormze is offline  
Reply With Quote
Old 05-28-2009, 10:13 AM   #11
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

stormze,

You need to use TraceOrders = true to see what is going on. If you really are flat it will never buy 2 if the order was submitted as 1. Changes you make to the code need to be compiled by pressing F5 in the compiler and changes are only reflected AFTER you start a new instance of the strategy.
NinjaTrader_Josh is offline  
Reply With Quote
Old 05-28-2009, 10:33 AM   #12
stormze
Member
 
Join Date: Oct 2008
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
Default

I dont see anything unusual with TraceOrders = true, prior EnterLong is baing executed I see a "Close position" order generated automatically, I want to prevent this or reset the counter it has. How NT knows that it need to close a position ???
Yea I also reload the strategy for every change...

5/28/2009 1:22:01 PM,Position,Instrument='ES 06-09' Account='Sim101' Avg price=895.5 Quantity=2 Market position=Long Operation=Update Currency=Unknown,
5/28/2009 1:22:01 PM,Execution,Execution='a399113f8e2041e18abb6b5828 e69295' Instrument='ES 06-09' Account='Sim101' Exchange=Default Price=895.5 Quantity=1 Market position=Long Operation=Insert Order='bb5f8897c86b42a19f78711279b930b1' Time='5/28/2009 1:22:01 PM',
5/28/2009 1:22:01 PM,Order,Order='bb5f8897c86b42a19f78711279b930b1/Sim101' Name='TO_EnterLong' New State=Filled Instrument='ES 06-09' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=1 Fill price=895.5 Error=NoError Native error='',
5/28/2009 1:22:01 PM,Order,Order='bb5f8897c86b42a19f78711279b930b1/Sim101' Name='TO_EnterLong' New State=Working Instrument='ES 06-09' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error='',
5/28/2009 1:22:01 PM,Order,Order='bb5f8897c86b42a19f78711279b930b1/Sim101' Name='TO_EnterLong' New State=Accepted Instrument='ES 06-09' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error='',
5/28/2009 1:22:01 PM,Position,Instrument='ES 06-09' Account='Sim101' Avg price=895.5 Quantity=1 Market position=Long Operation=Insert Currency=Unknown,
5/28/2009 1:22:01 PM,Execution,Execution='a12a22d9449a4f3ca052efb15f 3a92df' Instrument='ES 06-09' Account='Sim101' Exchange=Default Price=895.5 Quantity=1 Market position=Long Operation=Insert Order='f242023ab619414aa912c98857ffc9d4' Time='5/28/2009 1:22:01 PM',
5/28/2009 1:22:01 PM,Order,Order='f242023ab619414aa912c98857ffc9d4/Sim101' Name='Close position' New State=Filled Instrument='ES 06-09' Action=BuyToCover Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=1 Fill price=895.5 Error=NoError Native error='',
5/28/2009 1:22:01 PM,Order,Order='f242023ab619414aa912c98857ffc9d4/Sim101' Name='Close position' New State=Working Instrument='ES 06-09' Action=BuyToCover Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error='',
5/28/2009 1:22:01 PM,Order,Order='f242023ab619414aa912c98857ffc9d4/Sim101' Name='Close position' New State=Accepted Instrument='ES 06-09' Action=BuyToCover Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error='',
5/28/2009 1:22:00 PM,Order,Order='bb5f8897c86b42a19f78711279b930b1/Sim101' Name='TO_EnterLong' New State=PendingSubmit Instrument='ES 06-09' Action=Buy Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error='',
5/28/2009 1:22:00 PM,Order,Order='f242023ab619414aa912c98857ffc9d4/Sim101' Name='Close position' New State=PendingSubmit Instrument='ES 06-09' Action=BuyToCover Limit price=0 Stop price=0 Quantity=1 Type=Market Filled=0 Fill price=0 Error=NoError Native error='',
stormze is offline  
Reply With Quote
Old 05-28-2009, 10:38 AM   #13
NinjaTrader_Josh
NinjaTrader Product Manager
 
NinjaTrader_Josh's Avatar
 
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
Default

stormze,

It is evident your signal tracking has gone awry. You will need to debug your strategy and find exactly where it happens. You have a lot of Enter/Exits mixing and matching everywhere. You will need to check them by hand.
NinjaTrader_Josh 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
ExitLong and ExitShort not exiting Positions laserwolf Automated Trading 1 01-09-2009 07:28 AM
ExitLong()/ExitShort() not working as expected Tight Face Strategy Development 3 11-10-2008 09:27 AM
ExitShort / ExitLong Not Exiting Ari Gold General Programming 8 07-19-2008 12:29 AM
ExitShort() / ExitLong() andrewbee General Programming 1 02-06-2008 10:57 AM
ExitLong and ExitShort mazachan Strategy Development 3 07-30-2007 03:15 PM


All times are GMT -6. The time now is 09:12 AM.