I need to do this because I only want to call EnterLong if there is a corresponding order that occurred in the past. I understand the same thing can be accomplished by setting sync account position to true but the fact that it submits synchronize orders to my account (for which i will need to pay commissions) is not acceptable.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Accessing Orders When Historical == true
Collapse
X
-
Accessing Orders When Historical == true
Hi. I've noticed that Orders.Count is always zero when Historical is true. Is there a way to access orders before the first live bar?
I need to do this because I only want to call EnterLong if there is a corresponding order that occurred in the past. I understand the same thing can be accomplished by setting sync account position to true but the fact that it submits synchronize orders to my account (for which i will need to pay commissions) is not acceptable.Tags: None
-
Hi Spiralhead,
You can access orders historically. Orders.Count is not supported, but you can structure orders as IOrders, and expose values related to them. It works the same real time or historical.
TradePerformance class can be used historically as well.Ryan M.NinjaTrader Customer Service
-
Thanks for the info however it appears I am not understanding something. It seems everything in the Performance object is empty although I have an open position for the Instrument in question. For example Performance.AllTrades.Count is zero, Performance.Executions.Count is zero, and Performance.OpenPositions.Count is zero. What am I missing?
Comment
-
Thanks. Is there a way to access the individual orders or executions associated with the position?
Comment
-
Yes, if you structure your orders as IOrders, then you can expose information related to them. Depending on what you want to expose about them, you can work in OnOrderUpdate() or OnExecution(). This sample can help with the IOrders structure and work with these handlers:
The OnOrderUpdate() and OnExecution() methods are reserved for experienced programmers. Instead of using Set() methods to submit stop-loss and profit target orders, you can submit and update them manually through the use of IOrder and IExecution objects in the OnOrderUpdate() and OnExecution() methods. The OnOrderUpdate()Ryan M.NinjaTrader Customer Service
Comment
-
Thanks but I'm afraid this doesn't solve my problem. The problem is that I cannot access my IOrder objects until the first live bar. When Historical == true there is nothing in the Orders collection.
Comment
-
I'm not sure why you are seeing that. Please run the attached script on your side. It enters today historically and prints details regarding the order after a Historical check.
Code:**NT** Enabling NinjaScript strategy 'HistoricalOrders/8752d726b0254a9db6dd8bf9d8a654f5' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositions ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=False MaxRestarts=4 in 5 minutes Order='NT-00000/Sim101' Name='Buy' State=PendingSubmit Instrument='ES 09-11' Action=Buy Limit price=0 Stop price=0 Quantity=1 Strategy='HistoricalOrders' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='9c34aded363349eaaf51394de4392e14' Gtd='12/1/2099 12:00:00 AM' Order='NT-00000/Sim101' Name='Buy' State=Accepted Instrument='ES 09-11' Action=Buy Limit price=0 Stop price=0 Quantity=1 Strategy='HistoricalOrders' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='9c34aded363349eaaf51394de4392e14' Gtd='12/1/2099 12:00:00 AM' Order='NT-00000/Sim101' Name='Buy' State=Working Instrument='ES 09-11' Action=Buy Limit price=0 Stop price=0 Quantity=1 Strategy='HistoricalOrders' Type=Market Tif=Gtc Oco='' Filled=0 Fill price=0 Token='9c34aded363349eaaf51394de4392e14' Gtd='12/1/2099 12:00:00 AM' Order='NT-00000/Sim101' Name='Buy' State=Filled Instrument='ES 09-11' Action=Buy Limit price=0 Stop price=0 Quantity=1 Strategy='HistoricalOrders' Type=Market Tif=Gtc Oco='' Filled=1 Fill price=1265.75 Token='9c34aded363349eaaf51394de4392e14' Gtd='12/1/2099 12:00:00 AM'
Attached FilesRyan M.NinjaTrader Customer Service
Comment
-
I'm afraid we're not understanding each other. Let me run through a hypothetical scenario to describe my problem:
On Monday I fire up my strategy which enters a long MSFT position on live data (when Historical == false). At the end of the day I shut down NT still long MSFT over night.
Tuesday I fire up my strategy again and I want to be able to "resume" my position from Monday. NinjaTrader's built-in functionality for accomplishing this (setting sync account position to true) is inadequate for my purposes since it sends live sync orders to my broker from what i understand. SO, I was hoping I could only call EnterLong historically ONLY when there was an actual existing historical order so NT would not try to exit any positions I don't actually hold or send any sync orders. My strategy generates many signals and I can only trade a fraction of them because of capital limitations, obviously.
The problem I'm facing is that I don't seem to be able to access my order history until the first non-historical OnBarUpdate occurs so there's no way of knowing what historical trades my strategy actually entered.
Hopefully I'm making sense. I really like what NT brings to the table but I'm having a really hard time getting it to do what I want.
Comment
-
I see - thanks for the reply. Your topic is on strategy persistence. NinjaTrader is only able to map prior strategy orders when the historical run produces orders that match exactly with a prior, actual run. There are a few different behaviors depending on whether it found a match, and the interaction of a few settings. This is detailed here on the sync page.
Any order info exposed from a strategy relates to orders specific to one particular strategy instance, which is not necessarily account submitted orders. For some background on strategy mechanics, like the difference between a strategy position and an account position, please see here:
Ryan M.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
649 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
370 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
109 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
574 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
576 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|
Comment