Go Back   NinjaTrader Support Forum > NinjaTrader 7 > Strategy Development

Strategy Development Support for the development of custom automated trading strategies using NinjaScript.

NinjaTrader
Reply
 
Thread Tools Display Modes
Old 04-27-2017, 01:19 AM   #16
Dzammer
Member
 
Join Date: Aug 2014
Posts: 60
Thanks: 1
Thanked 2 times in 2 posts
Default

Quote:
Originally Posted by NinjaTrader_JessicaP View Post
If we review your picture in your first post, we can see that 50.12 and 50.11 both happen at 8:39:50 .
I understand all of this stuffs, but problem is not on where execution is shown, but how NT7 terminal have fill my limit order by price 50.12, if market have no this price after 50.11 (where condition was true)?
Dzammer is offline  
Reply With Quote
Old 04-27-2017, 07:55 AM   #17
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,417
Thanks: 206
Thanked 515 times in 506 posts
Default

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:

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // 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;

            // 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] + " / Current Bar " + CurrentBar);
                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: 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;
        }


// http://ninjatrader.com/support/helpGuides/nt7/onmarketdata.htm
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);
 }
}
If we do this we will be able to see each tick as it comes in after your trade is placed, and we will also know which bar your trade is filled on.
Last edited by NinjaTrader_JessicaP; 04-27-2017 at 07:58 AM.
NinjaTrader_JessicaP is offline  
Reply With Quote
Old 05-01-2017, 01:07 PM   #18
Dzammer
Member
 
Join Date: Aug 2014
Posts: 60
Thanks: 1
Thanked 2 times in 2 posts
Default

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
File Type: txt TestReplayLog.txt (53.1 KB, 1 views)
Dzammer is offline  
Reply With Quote
Old 05-02-2017, 07:51 AM   #19
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,417
Thanks: 206
Thanked 515 times in 506 posts
Default

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 at 08:03 AM.
NinjaTrader_JessicaP is offline  
Reply With Quote
Old 05-03-2017, 07:05 AM   #20
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,417
Thanks: 206
Thanked 515 times in 506 posts
Default

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.
NinjaTrader_JessicaP is offline  
Reply With Quote
Old 05-10-2017, 03:49 AM   #21
Dzammer
Member
 
Join Date: Aug 2014
Posts: 60
Thanks: 1
Thanked 2 times in 2 posts
Default

Quote:
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?
All this params no matter. In really trade I use M60 bars, in the test, that I present for you it 1 tick bars. And we testing only those part where we have price down from 50.12 to 50.11 and less.

Quote:
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?
No. It only for visualizing.

Quote:
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?
This data I received this data from my broker AMP. I have attached file with data and also at this link (because it large).
Attached Files
File Type: zip CL ##-##.zip (219.1 KB, 4 views)
Dzammer is offline  
Reply With Quote
Old 05-10-2017, 12:04 PM   #22
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,417
Thanks: 206
Thanked 515 times in 506 posts
Default

Thank 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.
NinjaTrader_JessicaP is offline  
Reply With Quote
Old 05-11-2017, 03:05 PM   #23
Dzammer
Member
 
Join Date: Aug 2014
Posts: 60
Thanks: 1
Thanked 2 times in 2 posts
Default

Quote:
Originally Posted by NinjaTrader_JessicaP View Post
Thank 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.
I am not understaund what you mean. In real trading, for this day (04.04.17) I have no trades. And it right. But in the same data, on market replay I fave trade that I described. I send you data from my NT7 database. You have script code. You can do this on your computer and see. Write me if I can help you more.
Dzammer is offline  
Reply With Quote
Old 05-12-2017, 11:53 AM   #24
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,417
Thanks: 206
Thanked 515 times in 506 posts
Default

I appreciate your patience. I mentioned in post 17,

Code:

            // 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;
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 . When I test with ES 06-17 Market Replay data I can't see the same thing on my end that you were seeing on yours. Additionally, while I understand you were attempting to make things easier to see, it is impossible for me to find a way to get your strategy to place a trade every bar. This is what I mean by sending us real output; output that you have modified in any way in an attempt to make a description easier will not help us see the same thing on our end that you are seeing on yours.

The line of code from post 17

Code:
if (Historical) return;
Was designed specifically to prevent you using historical data to attempt to reproduce this.

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.
NinjaTrader_JessicaP is offline  
Reply With Quote
Old 05-20-2017, 06:01 AM   #25
Dzammer
Member
 
Join Date: Aug 2014
Posts: 60
Thanks: 1
Thanked 2 times in 2 posts
Default

Quote:
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 .
I gave you all data, other part was at this link



Here link with all "db" folder and script. So you can reproduce problem on you PC.

Quote:
Additionally, while I understand you were attempting to make things easier to see
Not only to see, but for exclude all other things that can influence to the result. And I have same error (now you have all data for reproduce it).

Quote:
Add that line of code to your strategy at the beginning of OnBarUpdate
I done it many time ago.

Quote:
Shut down NinjaTrader 8
I use NT7, that you can see in the screens that I posted.
Attached Images
File Type: png Link.png (131.1 KB, 23 views)
Dzammer is offline  
Reply With Quote
Old 05-20-2017, 09:41 AM   #26
Dzammer
Member
 
Join Date: Aug 2014
Posts: 60
Thanks: 1
Thanked 2 times in 2 posts
Default

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");
            }
Where MyInput0 = 1225.0;
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".
Attached Images
File Type: png NT7ErrorGC.png (101.9 KB, 1 views)
Dzammer is offline  
Reply With Quote
Old 05-22-2017, 08:43 AM   #27
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,417
Thanks: 206
Thanked 515 times in 506 posts
Default

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 Files
File Type: cs Example1687462.cs (1.5 KB, 3 views)
NinjaTrader_JessicaP is offline  
Reply With Quote
Old 05-23-2017, 09:50 AM   #28
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,417
Thanks: 206
Thanked 515 times in 506 posts
Default

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.

http://ninjatrader.com/support/helpG..._are_plott.htm

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.
NinjaTrader_JessicaP is offline  
Reply With Quote
Old 05-24-2017, 05:24 PM   #29
Dzammer
Member
 
Join Date: Aug 2014
Posts: 60
Thanks: 1
Thanked 2 times in 2 posts
Default

Hello.

Quote:
Could you let me know what time zone you are in?
UTC+1

Quote:
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?
Strategy that you attached not working:
1. Because
Code:
public class Example1687462 : Strategy
    {
        private bool entered = false;

        // You not set Unmanaged = true and CalculateOnBarClose = false
        protected override void Initialize()
        {
            Unmanaged = true;
            CalculateOnBarClose = false;
        }

        protected override void OnBarUpdate()
        {
            //You use price 1225, but this is price for GC (Second example)if (Close[0] <= 1225.0 && !entered)
            if (Close[0] <= 50.11 && !entered)
            {
                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);
            }
        }
    }
This code also execute the same error. You can copy&past it.

Quote:
You are correct that the underlying cause of this behavior must be multiple ticks having the same timestamp. This situation is detailed here.
Yes. This situation is the same... But. My question is not "Why NT7 draw entry in first tick", but "WHY NT7 FILLED ORDER IF WE HAVE NOT PRICE 50.12 AFTER 50.11 (where condition become true)???".

So, my question still opened.
Dzammer is offline  
Reply With Quote
Old 05-25-2017, 07:31 AM   #30
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,417
Thanks: 206
Thanked 515 times in 506 posts
Default

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.
NinjaTrader_JessicaP is offline  
Reply With Quote
Reply

Tags
market replay, nt7

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Market Replay Filled Order At Ask Price That Did Not Exist Matheyas5 Platform Technical Support 30 05-02-2016 03:21 PM
Strategy fills above market price for Market Replay anyaM Strategy Development 9 10-24-2012 11:51 AM
Understanding fill price rocketman75 Strategy Development 12 03-19-2012 02:57 PM
Strategy Fills at Wrong Price for Market Replay KBJ Strategy Development 6 07-07-2011 08:53 PM


All times are GMT -6. The time now is 04:45 AM.

Futures, foreign currency and options trading contains substantial risk and is not for every investor. An investor could potentially lose all or more than the initial investment. Risk capital is money that can be lost without jeopardizing ones financial security or lifestyle. Only risk capital should be used for trading and only those with sufficient risk capital should consider trading. Past performance is not necessarily indicative of future results. View Full Risk Disclosure.

CFTC Rules 4.41 - Hypothetical or Simulated performance results have certain limitations, unlike an actual performance record, simulated results do not represent actual trading. Also, since the trades have not been executed, the results may have under-or-over compensated for the impact, if any, of certain market factors, such as lack of liquidity. Simulated trading programs in general are also subject to the fact that they are designed with the benefit of hindsight. No representation is being made that any account will or is likely to achieve profit or losses similar to those shown.

This website is hosted and operated by NinjaTrader, LLC (“NT”), a software development company which owns and supports all proprietary technology relating to and including the NinjaTrader trading platform. NT is an affiliated company to NinjaTrader Brokerage (“NTB”), which is a NFA registered introducing broker (NFA #0339976) providing brokerage services to traders of futures and foreign exchange products. This website is intended for educational and informational purposes only and should not be viewed as a solicitation or recommendation of any product, service or trading strategy. No offer or solicitation to buy or sell securities, securities derivative or futures products of any kind, or any type of trading or investment advice, recommendation or strategy, is made, given, or in any manner endorsed by any NT affiliate and the information made available on this Web site is not an offer or solicitation of any kind. Specific questions related to a brokerage account should be sent to your broker directly. The content and opinions expressed on this website are those of the authors and do not necessarily reflect the official policy or position of NT or any of its affiliates. 

Vendors along with their websites, products and services, collectively referred to as (“Vendor Content”), are independent persons or companies that are in no manner affiliated with NT or any if its affiliates. NT or any of its affiliates are not responsible for, do not approve, recommend or endorse any Vendor Content referenced on this website and it’s your sole responsibility to evaluate Vendor Content. Please be aware that any performance information provided by a vendor should be considered hypothetical and must contain the disclosures required by NFA Rule 2-29(c). If you are interested in learning more about, or investigating the quality of, any such Vendor Content you must contact the vendor, provider or seller of such Vendor Content. No person employed by, or associated with, NT or any of its affiliates is authorized to provide any information about any such Vendor Content. Visit the CFTC resources for education regarding the industry and signs of fraud.