Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Strategy is being disabled when backtesting although order reference is transitioned
Collapse
X
-
Hey! It looks like your strategy isn't switching to real-time as it should, causing the error. Make sure your code logic is solid and meets the transition conditions. Simplify your code if needed and keep exploring. Also, for more IT advice, check out https://www.proximitum.com/ . They should have useful solutions. Good luck!Last edited by Nothinox; 04-05-2024, 07:11 AM.
-
Hello Emily,
thank you for your reply.
Unfortunatly I won't be able to commit more time on this subject and produce a reduced sample. The error itself is not that critical as it only occurs in backtests and I have already posted a solution that works for me.
I thank you very much for your effort and support and wish you a nice day.
Leave a comment:
-
Hello Padan,
Thank you for your reply.
Please reduce your strategy by commenting out portions of code that do not cause this error and/or adding print statements to narrow down which line of code is the last thing processed before the error is thrown. This way we can narrow down the potential cause of this error and also create a test strategy to see if it is indeed related to something specific with IsLiveUntilCanceled orders. For more information on using prints and comments for debugging, please see the links below:- https://support.ninjatrader.com/s/ar...language=en_US
- https://ninjatrader.com/support/help...script_cod.htm
- https://forum.ninjatrader.com/forum/...956#post671956
I look forward to your reply.
Leave a comment:
-
Hello Emily,
thank your for the clarification.
As promised I now have tested this error on some other machines with different data providers and NinjaTrader versions.
First attempt was on NinjaTrader 8.1.1.7 64-bit with Rithmic.
Here is the output:
The second test I made was on NinjaTrader 8.1.2.1 64-bit with Tradovate as data provider.Code:OnStateChange() state: SetDefaults OnStateChange() state: Configure TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar -1/BarsInProgress 0): Set values in State.Configure. OnStateChange() state: DataLoaded TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar -1/BarsInProgress 0): StrategyBase (ES/Backtest) has loaded. OnStateChange() state: Historical TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar 0/BarsInProgress 0): Bar number 0 was the first bar processed of the session at 25.03.2024 00:01:00. TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar 0/BarsInProgress 0): Reset values on session start. TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar 0/BarsInProgress 0): Set significant market values. TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar 1369/BarsInProgress 0): Placed long entry limit order at: 5279,5 OnStateChange() state: SetDefaults OnStateChange() state: Terminated OnStateChange() state: Terminated Strategy 'TitanEdgeStrategyRandomEntryV4/306601665' has been disabled because it attempted to modify a historical order that has transitioned to a live order. Please see the help guide for more information on transitioning order references from historical to live. TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar -1/BarsInProgress 0): Cancelled all entry orders. OnStateChange() state: Terminated OnStateChange() state: SetDefaults OnStateChange() state: SetDefaults OnStateChange() state: Terminated
Here is the output:
Code:OnStateChange() state: SetDefaults OnStateChange() state: Configure TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar -1/BarsInProgress 0): Set values in State.Configure. OnStateChange() state: DataLoaded TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar -1/BarsInProgress 0): StrategyBase (ES/Backtest) has loaded. OnStateChange() state: Historical TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar 0/BarsInProgress 0): Bar number 0 was the first bar processed of the session at 25.03.2024 00:01:00. TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar 0/BarsInProgress 0): Reset values on session start. TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar 0/BarsInProgress 0): Set significant market values. TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar 1369/BarsInProgress 0): Placed long entry limit order at: 5279,5 OnStateChange() state: SetDefaults OnStateChange() state: Terminated OnStateChange() state: Terminated Strategy 'TitanEdgeStrategyRandomEntryV4/323533003' has been disabled because it attempted to modify a historical order that has transitioned to a live order. Please see the help guide for more information on transitioning order references from historical to live. TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar -1/BarsInProgress 0): Cancelled all entry orders. OnStateChange() state: Terminated OnStateChange() state: SetDefaults OnStateChange() state: SetDefaults OnStateChange() state: Terminated
Leave a comment:
-
That is because my platform is set to MST which is 2 hours behind the EST time zone.Originally posted by Padan View PostHello Emily, when you have selected Default 24 x 5 why does your backtest output start at .... the first bar processed of the session at 3/24/2024 10:01:00 PM ?
Leave a comment:
-
Hello Emily, when you have selected Default 24 x 5 why does your backtest output start at .... the first bar processed of the session at 3/24/2024 10:01:00 PM ?
Leave a comment:
-
The Default 24 X 5 Trading Hours session is 12am to 12am M-F EST:Originally posted by Padan View PostHello Emily,
I will try to update the version and let you know.
One thing I noticed is, we still have a difference in our backtesting time ranges. Your trace output is:
In the backtest throwing the error it is:Code:TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar -1/BarsInProgress 0): StrategyBase (ES/Backtest) has loaded. OnStateChange() state: Historical TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar 0/BarsInProgress 0): [B]Bar number 0[/B] was the first bar processed of the session at [B]3/24/2024 10:01:00 PM[/B]. TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar 0/BarsInProgress 0): Reset values on session start. TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar 0/BarsInProgress 0): Set significant market values. TitanEdgeRandomEntry 0.0.4(ES/Backtest/[B]Bar 110[/B]/BarsInProgress 0): Placed long entry limit order at: 5286.5 OnStateChange() state: SetDefaults OnStateChange() state: Terminated etc.
I have marked the differences as bold. From what I see the limit entry order in your backtest is not placed near the end of the backtesting time range - maybe therefore it could not trigger the error. I will have a look at timezone differences, maybe rework the script to just place the entry order on a specific bar number. Default 24 x5 should be a session starting and ending at 00:00, right?Code:TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar -1/BarsInProgress 0): StrategyBase (ES/Backtest) has loaded. OnStateChange() state: Historical TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar 0/BarsInProgress 0): [B]Bar number 0[/B] was the first bar processed of the session at [B]25/03/2024 00:01:00[/B]. TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar 0/BarsInProgress 0): Reset values on session start. TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar 0/BarsInProgress 0): Set significant market values. TitanEdgeRandomEntry 0.0.4(ES/Backtest/[B]Bar 1369[/B]/BarsInProgress 0): Placed long entry limit order at: 5279,5 OnStateChange() state: SetDefaults OnStateChange() state: Terminated OnStateChange() state: Terminated Strategy 'TitanEdgeStrategyRandomEntryV4/281664542' has been disabled because it attempted to modify a historical order that has transitioned to a live order. Please see the help guide for more information on transitioning order references from historical to live.
Thank you for your support.
World's leading screen capture + recorder from Snagit + Screencast by Techsmith. Capture, edit and share professional-quality content seamlessly.
You may find more information about Trading Hours templates in the Control Center > Tools > Trading Hours window.
I look forward to your updates with the additional results.
Leave a comment:
-
Hello Emily,
I will try to update the version and let you know.
One thing I noticed is, we still have a difference in our backtesting time ranges. Your trace output is:
In the backtest throwing the error it is:Code:TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar -1/BarsInProgress 0): StrategyBase (ES/Backtest) has loaded. OnStateChange() state: Historical TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar 0/BarsInProgress 0): [B]Bar number 0[/B] was the first bar processed of the session at [B]3/24/2024 10:01:00 PM[/B]. TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar 0/BarsInProgress 0): Reset values on session start. TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar 0/BarsInProgress 0): Set significant market values. TitanEdgeRandomEntry 0.0.4(ES/Backtest/[B]Bar 110[/B]/BarsInProgress 0): Placed long entry limit order at: 5286.5 OnStateChange() state: SetDefaults OnStateChange() state: Terminated etc.
I have marked the differences as bold. From what I see the limit entry order in your backtest is not placed near the end of the backtesting time range - maybe therefore it could not trigger the error. I will have a look at timezone differences, maybe rework the script to just place the entry order on a specific bar number. Default 24 x5 should be a session starting and ending at 00:00, right?Code:TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar -1/BarsInProgress 0): StrategyBase (ES/Backtest) has loaded. OnStateChange() state: Historical TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar 0/BarsInProgress 0): [B]Bar number 0[/B] was the first bar processed of the session at [B]25/03/2024 00:01:00[/B]. TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar 0/BarsInProgress 0): Reset values on session start. TitanEdgeRandomEntry 0.0.4(ES/Backtest/Bar 0/BarsInProgress 0): Set significant market values. TitanEdgeRandomEntry 0.0.4(ES/Backtest/[B]Bar 1369[/B]/BarsInProgress 0): Placed long entry limit order at: 5279,5 OnStateChange() state: SetDefaults OnStateChange() state: Terminated OnStateChange() state: Terminated Strategy 'TitanEdgeStrategyRandomEntryV4/281664542' has been disabled because it attempted to modify a historical order that has transitioned to a live order. Please see the help guide for more information on transitioning order references from historical to live.
Thank you for your support.
Leave a comment:
-
Hello Padan,Originally posted by Padan View PostHello Emily,
I have attached a template file with the settings for the strategy ( [ATTACH]n1298055[/ATTACH] ). It is important to note, that the session template for the backtest must be Default 24x5.
All the individual settings for the strategy do not matter too much, as the code now only should place a limit buy order at 23:51:01. This limit buy order should then be valid till the end date of the backtest (25.03.2024)
AND in the Signal function.Code:if(ToTime(Time[0]) >= 235100 && ToTime(Time[0]) < 235101) { Signal(TitanEdgeNamespace.TradeDirection.Long, TitanEdgeNamespace.OrderType.Limit, Close[0] - (3 * TickSize)); }
Using these settings above the error occurs for me all the time. If you change the Bars until cancel parameter in the Entry section of the properties to e.g. 8. the order will be cancelled before the backtest finishes and there is no error. As far as I understand the whole subject, the error occurs when there is an active buy limit with isLiveUntilCancelled = true order when the backtest ends.Code:EnterLongLimit(0, true, Convert.ToInt32(DefaultQuantity), entryPrice, LongPositionTier1);
I have created a ''fix'' for this strange behavior which cancels any active entry order in the case of a backtest one minute before the backtest ends and added it in the OnBarUpdate event. This seems to fix the issue as well, but I am sure this issue should not arise at all in the first place.
Code:if(IsInStrategyAnalyzer && (State == State.Historical) && HasActiveEntry() ) { if(Time[0] > To.AddMinutes(-1)) { // CancelAllOrders(); } }
Thank you for your reply.
I was not able to reproduce the error with the template provided. I have attached both the settings as well as the output after running a backtest several times with the provided template.
One thing I noticed is that in the export file, it says you exported from version 8.0.27.0. What are the results if you update to 8.0.28.0 or even optionally upgrade to NinjaTrader 8.1?
To update to the latest version of NinjaTrader Desktop please follow the steps below.- Login into the NinjaTrader Account Dashboard
- Click "Download" in the bottom left-hand corner of the sidebar
- Either select "Download" in the "Most Recent Release" Window in the main screen to upgrade to 8.1 or select the Download option for Version 8.0.28.0 in the "Prior Releases" section on the right-hand side
- Once the installation had downloaded, ensure any previous version of NinjaTrader is closed before running the installation package.
- Note: You may need to locate this in your "Downloads" folder in a Windows File Explorer
If you have updated from 8.0 to 8.1 and would prefer to remain on 8.0 please follow the steps below to migrate your version.
Please follow the steps below to migrate from the 8.1 platform back to the 8.0 platform:- Make sure all versions of NinjaTrader are Closed
- Go to the Windows Control Center > Click “Add/Remove Programs” (Sometimes “Uninstall a program” > Click NinjaTrader > Click Uninstall
- Click Next through the prompts until it is finished uninstalling
- Click the link below to directly download the Installer for version 8.0.28.0
- After downloading, click on the file and Open or Run it > Click Next through the prompts until it is Finished installing
- From here you can reopen NinjaTrader and continue using the platform like before.
Please let me know the results.
Attached Files
Leave a comment:
-
Hello Emily,
I have attached a template file with the settings for the strategy ( TitanEdgeStrategyRandomEntryV4.zip ). It is important to note, that the session template for the backtest must be Default 24x5.
All the individual settings for the strategy do not matter too much, as the code now only should place a limit buy order at 23:51:01. This limit buy order should then be valid till the end date of the backtest (25.03.2024)
AND in the Signal function.Code:if(ToTime(Time[0]) >= 235100 && ToTime(Time[0]) < 235101) { Signal(TitanEdgeNamespace.TradeDirection.Long, TitanEdgeNamespace.OrderType.Limit, Close[0] - (3 * TickSize)); }
Using these settings above the error occurs for me all the time. If you change the Bars until cancel parameter in the Entry section of the properties to e.g. 8. the order will be cancelled before the backtest finishes and there is no error. As far as I understand the whole subject, the error occurs when there is an active buy limit with isLiveUntilCancelled = true order when the backtest ends.Code:EnterLongLimit(0, true, Convert.ToInt32(DefaultQuantity), entryPrice, LongPositionTier1);
I have created a ''fix'' for this strange behavior which cancels any active entry order in the case of a backtest one minute before the backtest ends and added it in the OnBarUpdate event. This seems to fix the issue as well, but I am sure this issue should not arise at all in the first place.
Code:if(IsInStrategyAnalyzer && (State == State.Historical) && HasActiveEntry() ) { if(Time[0] > To.AddMinutes(-1)) { // CancelAllOrders(); } }
Leave a comment:
-
Hello Padan,
Thank you for your reply.
Please advise what strategy settings you are using that always generate the error. I imported the file and used the attached settings without errors. If you have a specific template you are using, please compare it to these settings to see what might be different between the two that could result in the error.
I look forward to your reply.Attached Files
Leave a comment:
-
Hello Emily,
first of all, thank you for your efforts!
You and the whole support team are really awesome and do play a large role for me personally to select NinjaTrader as trading software.
I have consolidated all the logic into one strategy file so there is no longer any inheritance, but still get the error.
I have attached a new archive containing the consolidated version of the strategy. ExportConsolidated2.zip
Can you reproduce the error as well, with the consolidated-no-inheritance version of the strategy? Any help would be highly appreciated.
UPDATE: I have updated the archive with a version of the strategy which always generates the error. The error occurs when there is an active working limit buy order in the moment the backtesting period ends.
Attached FilesLast edited by Padan; 04-02-2024, 06:37 AM.
Leave a comment:
-
Hello Padan,
Thanks again for your patience.
I was able to reproduce the error on my end, and I suspect it is caused by the inheritance you are attempting in the TitanEdgeStrategyRandomEntryV1 script:
I do see that the TitanEdgeStrategyBaseV3 script is properly inheriting from the Strategies class:Code:public class TitanEdgeStrategyRandomEntryV1 : TitanEdgeStrategyBaseV3
Having the TitanEdgeStrategyRandomEntryV1 file inherit from TitanEdgeStrategyBaseV3 is not supported. Please consolidate your logic into one strategy file and test it out; I suspect that this will not run into the same issues and will behave as expected. Currently, since you are inheriting from a strategy, no assumptions can be made about the State of either script and likely the issue is arising based on the States of each script and OnStateChange(). Ultimately, NinjaTrader does not support inheritance with Indicators, Strategies, or other script types because this breaks the NinjaTrader generated code for method overloads and also breaks optimizations and property grids.Code:public class TitanEdgeStrategyBaseV3 : Strategy
Unfortunately, NinjaTrader cannot support inheritance with Indicators, Strategies, or any of the other provided script types, other than custom addon classes that open in their own window outside of the structures of NinjaTrader windows.
I see you already have an AddOn with custom methods. I suggest adding all helper logic and/or custom methods you'd like into that same file, or you could use partial classes in the Indicators or Strategies namespace. For more information, please see the linkss below:
I've built a large framework on top in ninjatrader. Some of my indicators require many levels of inheritance. It works just fine, however I recently noticed that if there have been more then 2 levels of inheritance on an indicator then the auto generated code doesn't update properly. Specifically let's say C inherits from B
Thank you for your understanding. Please feel free to reach out with any additional questions or concerns.
Leave a comment:
-
No worries! I was able to download the attachment now. I will test this once I have a chance and follow up with you when I have an update, which should be early next week. In the meantime, please don't hesitate to reach out with any additional questions or concerns.Originally posted by Padan View PostHere it is. Sorry, I was sure I had attached it.
Thank you for your patience.
Leave a comment:
-
Here it is. Sorry, I was sure I had attached it.Attached Files
Leave a comment:
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by CarlTrading, 03-31-2026, 09:41 PM
|
1 response
81 views
1 like
|
Last Post
|
||
|
Started by CarlTrading, 04-01-2026, 02:41 AM
|
0 responses
42 views
0 likes
|
Last Post
by CarlTrading
04-01-2026, 02:41 AM
|
||
|
Started by CaptainJack, 03-31-2026, 11:44 PM
|
0 responses
64 views
2 likes
|
Last Post
by CaptainJack
03-31-2026, 11:44 PM
|
||
|
Started by CarlTrading, 03-30-2026, 11:51 AM
|
0 responses
66 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:51 AM
|
||
|
Started by CarlTrading, 03-30-2026, 11:48 AM
|
0 responses
54 views
0 likes
|
Last Post
by CarlTrading
03-30-2026, 11:48 AM
|
Leave a comment: