Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
strategy start behavior in live Simulation
Collapse
X
-
strategy start behavior in live Simulation
I'm testing a strategy in live feed simulation. My strategy start behavior is set to immediately submit at start. I'm flattening all open orders at 15:45, then restarting the strategy at 17:00. I want the strategy to immediately submit at 17:00 according to it's market position. However, in simulation, the strategy looks back in time and submits this order on the historical data before 15:45 when I flattened all open orders. Is it possible to have this strategy submit this order at the current live market price at 17:00 in simulation, in order to mimic how it would operate if submitting an actual live market order to the exchange at 17:00?Tags: None
-
Hello 2inthebush,
Thanks for your post.
We are using ImmediatlySubmit so the strategy will process historical data to determine what the strategy position what active orders the strategy should have. The behavior is used when we want to resume a position and we know the account position is what the strategy position would be.
There are a few items I will need clarity on:
Are you just canceling orders or also flattening the position? (When we restart the strategy, is it restarted when the account is flat without any orders pending, or when the account is in position without any active orders?)I'm flattening all open orders at 15:45,
Do you mean that you want the strategy to resume an active position, and submit a historical order, but instead of submitting the historical order, you want to submit an order based on factors that would have been calculated at 17:00?I want the strategy to immediately submit at 17:00 according to it's market position.
Could you elaborate on the order you want submitted at 17:00? Market/Stop/Limit?Is it possible to have this strategy submit this order at the current live market price at 17:00 in simulation, in order to mimic how it would operate if submitting an actual live market order to the exchange at 17:00?
Can you also confirm if it is used for an entry/exit in this case?
-
Hi Jim,
Correct. This is my goal. However, I'm not completely clear about the meaning of "we know the account position is what the strategy position would be." In this case the account will have zero open trades or pending orders at 17:00, before I enable the strategy at approximately 17:00. However, the historical position of the strategy would be long, short, or flat, depending upon it's historical calculation prior to 17:00.We are using ImmediatlySubmit so the strategy will process historical data to determine what the strategy position what active orders the strategy should have. The behavior is used when we want to resume a position and we know the account position is what the strategy position would be.
I'm using the "flatten everything" in the positions tab. Maybe this is what I'm doing incorrectly. The account has zero open trades and zero orders pending when I restart the strategy at 17:00. Perhaps I've misunderstood exactly what is meant by "flatten".I'm flattening all open orders at 15:45,
Are you just canceling orders or also flattening the position? (When we restart the strategy, is it restarted when the account is flat without any orders pending, or when the account is in position without any active orders?)
At 17:00, I want to enable the strategy and have it calculate it's historical position (it's position before 17:00), then submit a market entry in that direction at the live market price at the close of the first bar after 17:00. This strategy calculates at bar close.I want the strategy to immediately submit at 17:00 according to it's market position.
Do you mean that you want the strategy to resume an active position, and submit a historical order, but instead of submitting the historical order, you want to submit an order based on factors that would have been calculated at 17:00?
Just simply a market entry order with a basic stop loss (managed approach). Overall, my intention is to avoid carrying positions between sessions to avoid the increased margin requirements. Then at the beginning of the next session at 17:00, submit a market order to resume the position that I closed at 15:45. I presume that this should work fine when submitting live orders to the exchange (I haven't tried that yet). However, while trading the simulated account, when I enable the strategy at 17:00, NT enters at the historical entry signal (prior to 15:45) instead of the current live feed market price at 17:00. I'm looking for a solution for this simulated trading behavior.Is it possible to have this strategy submit this order at the current live market price at 17:00 in simulation, in order to mimic how it would operate if submitting an actual live market order to the exchange at 17:00?
Could you elaborate on the order you want submitted at 17:00? Market/Stop/Limit?
Can you also confirm if it is used for an entry/exit in this case?Last edited by 2inthebush; 03-31-2022, 03:21 PM.
Comment
-
Hello 2inthebush,
I think you will just want to use ImmediatelySubmit, Synchronize Account.
This will have the NinjaTrader submit a live market order to the account when you enable the strategy to sync the account position to the strategy position. This would be your market entry order, and it would be submitted at 17:00 when you re-enable to re-sync the account/strategy
This way, you would disable the strategy and flatten it (Flatten Everything does this)
(Strategy and account are now de-synced)
When you re-enable with Immediately Submit Synchronize Account, the position is immediately re-entered on the account since the strategy calculated it would be in position, and any pending orders will be submitted immediately upon start up.
Comment
-
OK. This strategy is set to ImmediatelySubmit, Synchronize Account. At least I can presume that it will behave as I've intended when placing live orders to the exchange. However, this doesn't solve the issue I've described while trading the simulated account with live data feed.
I've attached a screenshot to demonstrate the behavior. I'm currently connected to my live CQG data feed. First, I flattened all open trades and orders and disabled the strategy. Then I enabled the strategy after 17:00. Instead of entering at the current live price, the strategy has entered at the original historical signal at approx. 14:51.Last edited by 2inthebush; 03-31-2022, 04:46 PM.
Comment
-
Hello 2inthebush,
To be clear, the simulated and Live account will be the same in this case.
You are correct that this will adjust the realtime order (and also the realtime strategy performance report) but the markers on the chart and the historical executions calculated by the strategy, would reflect the historically calculated orders.
Immediately Submit, Sync Account will allow you to re-enter, and re-sync the strategy position, but yes, the active orders would be relative to the historical entry.
To have the target/stop relative to the newly entered position, and not the historical position, you could consider using AdoptAccountPosition and adopt a workflow so you:- Manually re-enter
- Enable the strategy with AdoptAccountPosition
AdoptAccountPosition also exhibits behaviors as ImmediatelySubmit where previously calculated orders would be submitted. You could maybe consider making a copy of your strategy that skips processing historical data, and uses AdoptAccountPosition. I have attached examples.
Alternatively, and maybe what you were trying to do in the first place:
You could consider checking if there is a position on the last historical bar, exit that historical position, and set a bool representing that you need to enter on the first realtime bar. (This could be used with ImmediatelySubmit, without using Sync Account.)
This could look something like:
Code:private bool NeedToReEnter = false; protected override void OnBarUpdate() { if (State == State.Historical && CurrentBar == BarsArray[0].Count-2 && Position.MarketPosition == MarketPosition.Long) { ExitLong(); NeedToReEnter = true; } else if (State == State.Realtime && NeedToReEnter) { EnterLong(); NeedToReEnter = false; } }
Comment
-
Alright cool, I'll look into those options which you've described. I'd tried a similar approach recently with the bool but was having trouble getting it to work right. I'll try it again using your instructions above. Thank you for you help, Jim!
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by NullPointStrategies, Today, 05:17 AM
|
0 responses
25 views
0 likes
|
Last Post
|
||
|
Started by argusthome, 03-08-2026, 10:06 AM
|
0 responses
121 views
0 likes
|
Last Post
by argusthome
03-08-2026, 10:06 AM
|
||
|
Started by NabilKhattabi, 03-06-2026, 11:18 AM
|
0 responses
64 views
0 likes
|
Last Post
|
||
|
Started by Deep42, 03-06-2026, 12:28 AM
|
0 responses
41 views
0 likes
|
Last Post
by Deep42
03-06-2026, 12:28 AM
|
||
|
Started by TheRealMorford, 03-05-2026, 06:15 PM
|
0 responses
46 views
0 likes
|
Last Post
|

Comment