Thanks!
Announcement
Collapse
Looking for a User App or Add-On built by the NinjaTrader community?
Visit NinjaTrader EcoSystem and our free User App Share!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less
Partner 728x90
Collapse
NinjaTrader
1 Second Delay Between Orders
Collapse
X
-
1 Second Delay Between Orders
I am implementing a strategy with 2 orders. They are currently sent at the same time and the broker (TDA) is able to manage the initial creation of the 2. When I need to close one or both of them and then enter the other direction, the broker gets confused by receiving the too much data at the same time. I would like to implement a one second delay between the orders. Do you know of a sample code set that I can use to accomplish this?
Thanks!Tags: None
-
Hello cpabiz20k,
Are you getting an error message when this happens?
If so, what is the error message?
Are you using the managed approach and attempting to call an exit and an entry on the same bar?
You could wait until the next tick updates OnBarUpdate if you don't want to use a timer. However, I would not expect a 'Close position' and 'SellShort' order to be too many orders for TD Ameritrade.Chelsea B.NinjaTrader Customer Service
-
// Condition set 3...If we have not hit our Take Profit target and the candle changes,
// exit and go the other way
if (Position.MarketPosition == MarketPosition.Long
&& Close[1] > Close[0]
&& BarsSinceEntry() <= TakeProfitBars
&& (ToTime(Time[0]) >= TimeBegin
&& ToTime(Time[0]) < TimeEnd))
{
Print ("3: < TP, Reverse Long to Short");
EnterShort(NumSharesA, "Regular Short A");
EnterShort(NumSharesB, "Regular Short B");
}
This is the code I am using. In the description of EnterShort it says it will automatically close out any long that exists. I am wondering if adding an ExitLong() before the EnterShort would clear it and then allow it to process.
There were no error commands, just a cancelled order response for the B shares. All 3 (exit, enter A, enter B) had the same time stamp, that is why I thought that adding a one second timer between them might be good to allow TDA to catch up.
Comment
-
Hello cpabiz20k,
If the orders are not being rejected, it may not be an issue with TDA receiving the orders.
Calling ExitLong() and EnterShort() on the same bar will cause the strategy to enter double in the opposite direction or will cause an overfill. This is detailed in the post I have linked in post #2.
What is the exact issue?
You mentioned there was a cancelled order response. Was there a cancellation request sent from NinjaTrader. Did the order enter a CancelPending state?
Is the issue that an order was cancelled unexpectedly?
You appear to be sending two entry orders at the same time. What is EntriesPerDirection set to in the strategy parameters?Chelsea B.NinjaTrader Customer Service
Comment
-
Hello cpabiz20k,
One thing I would suggest doing to discover why the close orders are causing issues would be to turn on TraceOrders.
Code:[TABLE="border: 0, cellpadding: 0, cellspacing: 0"] [TR] [TD]protected override void Initialize() { TraceOrders = true; }[/TD] [/TR] [/TABLE]
Here is a link to our help guide that goes into more detail on tracing orders:
https://ninjatrader.com/support/helpGuides/nt7/traceorders2.htm
As a side note, to amzounslide's comment, using BarsSinceEntry() (this is the correct syntax) would be an option to stagger the reversals by a bar or two:
Please let us know if we may be of further assistance to you.Kate W.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by Nickgiaco, 02-26-2024, 10:23 AM
|
2 responses
71 views
0 likes
|
Last Post Today, 05:12 AM | ||
Started by Johndc, Today, 04:39 AM
|
0 responses
4 views
0 likes
|
Last Post
by Johndc
Today, 04:39 AM
|
||
Started by johntraderuser2, Today, 02:34 AM
|
0 responses
9 views
0 likes
|
Last Post Today, 02:34 AM | ||
Started by IanS00, 03-27-2024, 11:24 AM
|
2 responses
13 views
0 likes
|
Last Post Today, 02:00 AM | ||
Started by Mariawilcoxi, Today, 01:32 AM
|
0 responses
5 views
0 likes
|
Last Post
by Mariawilcoxi
Today, 01:32 AM
|
Comment