![]() |
|
|||||||
| 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. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Member
Join Date: Oct 2008
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
|
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");
}
ExitShort is not acting well, why is that ?
Last edited by stormze; 05-27-2009 at 02:41 PM.
|
|
|
|
|
|
#2 |
|
Member
Join Date: Oct 2008
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
|
Note: this started happening since I manually closed one of the orders that the script submitted
|
|
|
|
|
|
#3 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#4 |
|
Member
Join Date: Oct 2008
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#5 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
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
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#6 |
|
Member
Join Date: Oct 2008
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#7 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#8 |
|
Member
Join Date: Oct 2008
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#9 |
|
NinjaTrader Customer Service
Join Date: Sep 2008
Location: Germany
Posts: 22,567
Thanks: 261
Thanked 1,016 times in 997 posts
|
You can use Position.MarketPosition for checking if you're flat or not - http://www.ninjatrader-support.com/H...tPosition.html
Bertrand
NinjaTrader Customer Service |
|
|
|
|
|
#10 |
|
Member
Join Date: Oct 2008
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
|
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 |
|
|
|
|
|
#11 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
|
|
#12 |
|
Member
Join Date: Oct 2008
Posts: 53
Thanks: 0
Thanked 0 times in 0 posts
|
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='', |
|
|
|
|
|
#13 |
|
NinjaTrader Product Manager
Join Date: May 2007
Location: Denver, CO
Posts: 17,458
Thanks: 1
Thanked 107 times in 70 posts
|
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.
Josh
NinjaTrader Customer Service |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|
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 |