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
Market replay price process understanding.
Collapse
X
-
Let's add two more pieces of information, so we can know if, and if so exactly when, the price reached 50.12 after 50.11. Please make the following changes to your code :
Code:[FONT=Courier New] /// <summary> /// Called on each bar update event (incoming tick) /// </summary> protected override void OnBarUpdate() {[B] // OnMarketData will only work with live data // If you were backtesting to get this before, // please use the Market Replay connection instead if (Historical) return;[/B] // make sure we are using the primary series if (BarsInProgress != 0) return; // Condition set 1 if (Close[0] <= MyInput0 && !entered) { entered = true; Print("OnBarUpdate: Time = " + Times[1][0].ToString("dd MMM yyyy HH:mm:ss.ffff") + " / Close = " + Close[0][/FONT][FONT=Courier New][B][FONT=Courier New] + " / Current Bar " + CurrentBar[/FONT][/B]); SubmitOrder(0, OrderAction.Sell, OrderType.Limit, 1, 50.12, 0, null, "Entry"); } } // This gets triggered once a trade is placed protected override void OnExecution(IExecution execution) { Print(String.Format("OnExecution: [B]Execution [/B]Time = {0:dd MMM yyyy HH:mm:ss.ffff} / [B]Execution Price [/B]= {1:C} [B]/ Close = {2:C} / CurrentBar = {3}[/B]", execution.Time, execution.Pric[B]e, Close[0], CurrentBar[/B][/FONT][FONT=Courier New]));[B] entered = false;[/B] }[/FONT][B][FONT=Courier New] [/FONT][/B][B][FONT=Courier New] [/FONT][/B][B][FONT=Courier New][FONT=Courier New] [/FONT]// http://ninjatrader.com/support/helpGuides/nt7/onmarketdata.htm[/FONT][/B][B][FONT=Courier New] [/FONT][/B][B][FONT=Courier New][FONT=Courier New] [/FONT]protected override void OnMarketData(MarketDataEventArgs e)[/FONT][/B][B][FONT=Courier New] [/FONT][/B][B][FONT=Courier New][FONT=Courier New] [/FONT]{[/FONT][/B][B][FONT=Courier New] [/FONT][/B][B][FONT=Courier New] [/FONT][/B][B][FONT=Courier New][FONT=Courier New] [/FONT] if (entered && e.MarketDataType == MarketDataType.Last)[/FONT][/B][B][FONT=Courier New] [/FONT][/B][B][FONT=Courier New] [/FONT][/B][B][FONT=Courier New][FONT=Courier New] [/FONT] {[/FONT][/B][B][FONT=Courier New] [/FONT][/B][B][FONT=Courier New] [/FONT][/B][B][FONT=Courier New][FONT=Courier New] [/FONT] Print("OnMarketData: Time = " + e.Time.ToString("dd MMM yyyy HH:mm:ss.ffff") + " / New price = " + e.Price + " / Current Bar " + CurrentBar);[/FONT][/B][B][FONT=Courier New] [/FONT][/B][B][FONT=Courier New] [/FONT][/B][B][FONT=Courier New][FONT=Courier New] [/FONT] }[/FONT][/B][B][FONT=Courier New] [/FONT][/B][B][FONT=Courier New][FONT=Courier New] [/FONT]}[/FONT][/B]
Last edited by NinjaTrader_JessicaP; 04-27-2017, 07:58 AM.Jessica P.NinjaTrader Customer Service
Comment
-
Hello, Jessica.
I have attach result.
How we can see, after price 50.11, we have now price 50.12, but order have execute by this price...
Code:OnBarUpdate: Time = 04 апр 2017 07:39:50.0000 / Close = 50,11 / Current Bar 471347 OnMarketData: Time = 04 апр 2017 07:39:50.0000 / New price = 50,11 / Current Bar 471347 OnExecution: Execution Time = 04 апр 2017 07:39:50.0000 / Execution Price = 50,12 ? / Close = 50,11 ? / CurrentBar = 471347 OnBarUpdate: Time = 04 апр 2017 07:39:50.0000 / Close = 50,11 / Current Bar 471348 OnMarketData: Time = 04 апр 2017 07:39:50.0000 / New price = 50,11 / Current Bar 471348 OnExecution: Execution Time = 04 апр 2017 07:39:50.0000 / Execution Price = 50,12 ? / Close = 50,11 ? / CurrentBar = 471348 OnBarUpdate: Time = 04 апр 2017 07:39:50.0000 / Close = 50,11 / Current Bar 471349 OnMarketData: Time = 04 апр 2017 07:39:50.0000 / New price = 50,11 / Current Bar 471349 OnExecution: Execution Time = 04 апр 2017 07:39:50.0000 / Execution Price = 50,12 ? / Close = 50,11 ? / CurrentBar = 471349 OnBarUpdate: Time = 04 апр 2017 07:39:50.0000 / Close = 50,11 / Current Bar 471350 OnMarketData: Time = 04 апр 2017 07:39:50.0000 / New price = 50,11 / Current Bar 471350 OnExecution: Execution Time = 04 апр 2017 07:39:50.0000 / Execution Price = 50,12 ? / Close = 50,11 ? / CurrentBar = 471350 OnBarUpdate: Time = 04 апр 2017 07:39:50.0000 / Close = 50,11 / Current Bar 471351 OnMarketData: Time = 04 апр 2017 07:39:50.0000 / New price = 50,11 / Current Bar 471351 OnExecution: Execution Time = 04 апр 2017 07:39:50.0000 / Execution Price = 50,12 ? / Close = 50,11 ? / CurrentBar = 471351 OnBarUpdate: Time = 04 апр 2017 07:39:50.0000 / Close = 50,11 / Current Bar 471352
Attached Files
Comment
-
Would it be possible to answer some questions about how we are backtesting?
- I noticed you have an execution every single bar. Can you let me know which instrument, time period you have data downloaded for, and number of bars back we are testing?
- I am assuming this is over 1 minute bars as in the original picture, on April 4th 2017?
- I noticed in your OP that you are using CL-## . NinjaTrader's market replay servers do not offer continuous contract data for this instrument. Can you let us know where you received this data, and where I can find a copy I can use to test on my end?
- If not, can you repeat this test with CL 06-17 or CL 05-17 data?
The answer to these two questions will make it easier to determine exactly why and how this happened. I look forward to assisting further.Last edited by NinjaTrader_JessicaP; 05-02-2017, 08:03 AM.Jessica P.NinjaTrader Customer Service
Comment
-
I realize your time is valuable. In order to repair any potential bug in NinjaTrader, we need to give the developers a clear case that they can see on their end. We need to be able to make the behavior you are seeing occur under controlled conditions to be able to learn what needs to be changed. If other customers observe the same behavior you are seeing I will report back here. Please let us know if there are any other ways we can help.Jessica P.NinjaTrader Customer Service
Comment
-
Originally posted by NinjaTrader_JessicaP View Post- I noticed you have an execution every single bar. Can you let me know which instrument, time period you have data downloaded for, and number of bars back we are testing?
Originally posted by NinjaTrader_JessicaP View Post- I am assuming this is over 1 minute bars as in the original picture, on April 4th 2017?
Originally posted by NinjaTrader_JessicaP View Post- I noticed in your OP that you are using CL-## . NinjaTrader's market replay servers do not offer continuous contract data for this instrument. Can you let us know where you received this data, and where I can find a copy I can use to test on my end?
Attached Files
Comment
-
Originally posted by NinjaTrader_JessicaP View PostThank you Dzammer. Would it be possible to generate some real output using market conditions you can describe to me? This will make it easier for me to see the same thing on my end that you are seeing on yours.
Comment
-
I appreciate your patience. I mentioned in post 17,
Code:[FONT=Courier New] // OnMarketData will only work with live data // If you were backtesting to get this before, // please use the Market Replay connection instead if (Historical) return;[/FONT]
The line of code from post 17
Code:[FONT=Courier New]if (Historical) return;[/FONT]
When you try to act on the advice I have given in this thread, please
- Add that line of code to your strategy at the beginning of OnBarUpdate
- Use Market Replay data
- Use a chart for testing
- Send us your unmodified output. Please do not attempt to do anything for visualizing or for any similar reason
This said, I realize your time is valuable. If for any reason you can not set aside the time to follow the steps in this post, please do not attempt any more testing on your end, and please do not post any more results. Instead, we can reset your database to resolve your query. If this is the case, please
- Shut down NinjaTrader 8
- Delete the contents of your (My) Documents\NinjaTrader 8\db\cache folder
- Copy your (My) Documents\NinjaTrader 8\db\NinjaTrader.sdf file to another location as a back-up
- Restart NinjaTrader holding down the ctrl key on your keyboard
- In the Tools -> Database menu, in the Reset DB section, check both boxes and press Reset, Yes, and OK
- In the Tools -> Database menu, in the Update Instruments section, check all the boxes and press Update
- Restart NinjaTrader 8
Whichever path you choose, please don't hesitate to reach out if there is any other way we can help.Jessica P.NinjaTrader Customer Service
Comment
-
The data you gave us is historical data, not market replay data. Historical data has the extension .ntd and the data you sent has the extension .nrd .
Here link with all "db" folder and script. So you can reproduce problem on you PC.
Additionally, while I understand you were attempting to make things easier to see
Add that line of code to your strategy at the beginning of OnBarUpdate
Shut down NinjaTrader 8
Comment
-
The same error in other ticker GC 04-16.
Look in the screen. In the code we have:
Code:if (Close[0] <= MyInput0 && !entered) { entered = true; Print("OnBarUpdate: Time = " + Times[1][0].ToString("dd MMM yyyy HH:mm:ss.ffff") + " / Close = " + Close[0] + " / Current Bar " + CurrentBar); SubmitOrder(0, OrderAction.Sell, OrderType.Limit, 1, 1225.6, 0, null, "Entry"); }
So, when price <= 1225.0 we send sell limit by 1225.6. But how we can see on the screen, there is a no price 1225.6 after 1225.
How I wrote here (post #5) I think that problem in the time. All ticks have the same time. And NT interpretive all ticks how one bar, so in one bar we have both prices 1225 and 1225.6. And in this "bar" our condition become true and NT fill by price, that we have in this "bar".
Comment
-
Thank you for pointing out the data behind the link was different from the data you attached directly in post 21. I also understand that I overlooked this being an NT7 strategy. I was able to load this data in the playback connection in NT7.
I believe I will need just one more piece of information before I can see the same thing on my end. I found a run of bars that seemed to match the one in your picture, but this did not trigger the same trades the same way with the attached strategy. Could you let me know what time zone you are in? Could you also try the attached strategy in the Market Replay connection on the 4th of April and confirm that you get the same trades when using the Market Replay connection?Attached FilesJessica P.NinjaTrader Customer Service
Comment
-
I apologize but I missed your most recent reply as it was not up when I began replying.
You are correct that the underlying cause of this behavior must be multiple ticks having the same timestamp. This situation is detailed here.
NinjaTrader 8 will grant more granular features surrounding this situation, including using a custom bars series for fill resolution with no additional code, and filling when limit orders are touched.Jessica P.NinjaTrader Customer Service
Comment
-
Hello.
Could you let me know what time zone you are in?
Could you also try the attached strategy in the Market Replay connection on the 4th of April and confirm that you get the same trades when using the Market Replay connection?
1. Because
Code:public class Example1687462 : Strategy { private bool entered = false; [B] // You not set Unmanaged = true and CalculateOnBarClose = false protected override void Initialize() { Unmanaged = true; CalculateOnBarClose = false; }[/B] protected override void OnBarUpdate() { /[B]/You use price 1225, but this is price for GC (Second example)if (Close[0] <= 1225.0 && !entered) if (Close[0] <= 50.11 && !entered)[/B] { entered = true; Print("Time = " + Time[0] + " / Close = " + Close[0]); SubmitOrder(0, OrderAction.Sell, OrderType.Limit, 1, 50.12, 0, null, "Entry"); } } protected override void OnExecution(IExecution execution) { Print(String.Format("OnExecution: Execution Time = {0:dd MMM yyyy HH:mm:ss.ffff} / Execution Price = {1:C} / Close = {2:C} / CurrentBar = {3}", execution.Time, execution.Price, Close[0], CurrentBar)); entered = false; } protected override void OnMarketData(MarketDataEventArgs e) { if (entered && e.MarketDataType == MarketDataType.Last) { Print("OnMarketData: Time = " + e.Time.ToString("dd MMM yyyy HH:mm:ss.ffff") + " / New price = " + e.Price + " / Current Bar " + CurrentBar); } } }
You are correct that the underlying cause of this behavior must be multiple ticks having the same timestamp. This situation is detailed here.
So, my question still opened.
Comment
-
Thank you again for bringing this behavior to our attention. As NinjaTrader 7 is no longer under active development, we will be using the information you have provided us to revise our documentation so that other users are aware of this corner case in backtesting. Thank you for using NinjaTrader 7.Jessica P.NinjaTrader Customer Service
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by nicthe, Today, 09:24 AM
|
0 responses
1 view
0 likes
|
Last Post
by nicthe
Today, 09:24 AM
|
||
Started by stalt, 12-28-2015, 01:36 PM
|
6 responses
1,536 views
0 likes
|
Last Post
by giulyko00
Today, 09:16 AM
|
||
Started by Tburg1073, Today, 08:36 AM
|
0 responses
5 views
0 likes
|
Last Post
by Tburg1073
Today, 08:36 AM
|
||
Started by alexstox, 10-16-2018, 03:29 PM
|
10 responses
333 views
0 likes
|
Last Post
by Tburg1073
Today, 08:32 AM
|
||
Started by smartromain, 03-13-2024, 01:42 AM
|
6 responses
98 views
0 likes
|
Last Post
by smartromain
Today, 08:30 AM
|
Comment