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-04-2017, 08:10 AM   #1
Dzammer
Member
 
Join Date: Aug 2014
Posts: 60
Thanks: 1
Thanked 2 times in 2 posts
Default Market replay price process understanding.

I work with market replay.
I have some strategy code. When current price (Close[0]) <= 50.11, I send sell limit with limit price = 50.12. But how we can see in the screen, we have no price 50.11 on the chart, but in the code we have it. How it possible?
NT7Filling.png
Dzammer is offline  
Reply With Quote
Old 04-04-2017, 03:31 PM   #2
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 3,709
Thanks: 28
Thanked 961 times in 897 posts
Default

Hello,

Thank you for the post.

I wanted to check, what is the series the strategy is applied to for this test?

If this was the Minute series you pictured, I do see that the building bar had met this price.

The strategies logic had become true to produce the trade, It may be helpful to print the Time when the condition became true to see more details on which specific bar of the primary series the order logic became true on.


I look forward to being of further assistance.
NinjaTrader_Jesse is offline  
Reply With Quote
Old 04-04-2017, 05:17 PM   #3
Dzammer
Member
 
Join Date: Aug 2014
Posts: 60
Thanks: 1
Thanked 2 times in 2 posts
Default

Hello, Jesse.
Strategy use hours bars. I present minute bars and ticks for more details. I can't Print time because I use hours bars. But I print prices before send limit. And how we can see before limit is filled we have no condition price in the chart (50.11), but strategy have it.
Strategy use only 1 DataSeries. It M60. I am show you minute and tick screen for zoom some details.
Dzammer is offline  
Reply With Quote
Old 04-05-2017, 03:28 PM   #4
NinjaTrader_Jesse
NinjaTrader Customer Service
 
NinjaTrader_Jesse's Avatar
 
Join Date: Mar 2014
Location: Denver, CO
Posts: 3,709
Thanks: 28
Thanked 961 times in 897 posts
Default

Hello,

Thank you for the reply.

Would you be able to provide the syntax you had used for this test? Unfortunately, I am unable to see what may have occurred during this time except that your logic became true during this time.

Additionally, I am not sure I understand your comment regarding the prints, you are able to print the Times from any series whether that be a minute or 60 minute series. Prints would help identify at what time your logic became true to find more details on why the order was submitted when it was.

I look forward to being of further assistance.
NinjaTrader_Jesse is offline  
Reply With Quote
Old 04-06-2017, 12:40 PM   #5
Dzammer
Member
 
Join Date: Aug 2014
Posts: 60
Thanks: 1
Thanked 2 times in 2 posts
Default

Hello, Jesse.

Thank you. I have attach screen with error. A can't attach database, because it size 2,1 MB. In the attached screen of error you can see a log window with tick time. I think that problem is in time. How we can see in the screen, all ticks have same time 7:39:50. May be NT7 get all ticks of same time and make virtual bar from them. Then we have Low = 50.11 and e.t.c. But if it true it's very bad news...

Here code of script:
/
Code:
// <summary>
    /// 
    /// </summary>
    [Description("")]
    public class TestReplay : Strategy
    {
        #region Variables
        // Wizard generated variables
        private double myInput0 = 1; // Default setting for MyInput0
		
		private bool entered = false;
        // User defined variables (add any user defined variables below)
        #endregion

        /// <summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        /// </summary>
        protected override void Initialize()
        {
            CalculateOnBarClose = false;
			Unmanaged = true;
        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // Condition set 1
            if (Close[0] <= MyInput0
				&& !entered)
            {
				entered = true;
				Print("Time = " + Time[0] + " / Close = " + Close[0]);
				SubmitOrder(0, OrderAction.Sell, OrderType.Limit, 1, 50.12, 0, null, "Entry");
            }
        }

        #region Properties
        [Description("")]
        [GridCategory("Parameters")]
        public double MyInput0
        {
            get { return myInput0; }
            set { myInput0 = Math.Max(1, value); }
        }
        #endregion
    }
Attached Images
File Type: png NT7Error.png (93.8 KB, 14 views)
Dzammer is offline  
Reply With Quote
Old 04-11-2017, 01:18 AM   #6
Dzammer
Member
 
Join Date: Aug 2014
Posts: 60
Thanks: 1
Thanked 2 times in 2 posts
Default

Can anybody help me?
Dzammer is offline  
Reply With Quote
Old 04-17-2017, 09:24 AM   #7
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,404
Thanks: 206
Thanked 504 times in 496 posts
Default

Thank you for providing this code sample Dzammer. To enable us to print exact times and prices of fills, let's go ahead and add

  • A one tick series (this will not slow your strategy since it will never be processed during OnBarUpdate except for retrieving times)
  • An OnExecution section, which gets triggered exactly when trades are placed
While the OnExecution section by itself would be enough, for this educational sample I would like you to have a method to retrieve exact times that works from OnBarUpdate as well. I will boldface my changes.



Code:
    /// <summary>
    /// 
    /// </summary>
    [Description("")]
    public class TestReplay : Strategy
    {
        #region Variables
        // Wizard generated variables
        private double myInput0 = 1; // Default setting for MyInput0
        
        private bool entered = false;
        // User defined variables (add any user defined variables below)
        #endregion

        /// <summary>
        /// This method is used to configure the strategy and is called once before any strategy method is called.
        /// </summary>
        protected override void Initialize()
        {
            CalculateOnBarClose = false;
            Unmanaged = true;
            Add(PeriodType.Tick, 1);

        }

        /// <summary>
        /// Called on each bar update event (incoming tick)
        /// </summary>
        protected override void OnBarUpdate()
        {
            // 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]);
                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: Time = {0:dd MMM yyyy HH:mm:ss.ffff} / Close = {1:C}",  execution.Time, execution.Price));
        }



        #region Properties
        [Description("")]
        [GridCategory("Parameters")]
        public double MyInput0
        {
            get { return myInput0; }
            set { myInput0 = Math.Max(1, value); }
        }
        #endregion
    }
NinjaTrader_JessicaP is offline  
Reply With Quote
Old 04-18-2017, 03:16 PM   #8
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 for providing this code sample Dzammer. To enable us to print exact times and prices of fills, let's go ahead and add

  • A one tick series (this will not slow your strategy since it will never be processed during OnBarUpdate except for retrieving times)
  • An OnExecution section, which gets triggered exactly when trades are placed
All done. I have attach result.
Attached Images
File Type: png logScreen.png (63.3 KB, 12 views)
Dzammer is offline  
Reply With Quote
Old 04-19-2017, 06:54 AM   #9
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,404
Thanks: 206
Thanked 504 times in 496 posts
Default

Thank you for this additional information. After reviewing the thread I believe I understand what is occurring. You have set CalculateOnBarClose = false; . This means that your OnBarUpdate runs every tick, rather than on every bar close. If you would prefer only being able to detect a price once a bar, you will need to change this setting to true. Please let us know if there are any other ways we can help.
NinjaTrader_JessicaP is offline  
Reply With Quote
Old 04-19-2017, 03:31 PM   #10
Dzammer
Member
 
Join Date: Aug 2014
Posts: 60
Thanks: 1
Thanked 2 times in 2 posts
Default

Jessica, CalcullateOnBarClose = true, not good for me. I need to process all of ticks of each bar. Can you answer my first question? Why conditions is true, if we have no price in the chart? It the chart we see, that after we have 50.12 (where condition is true) we have no price 50.11 (price of our limit).
Dzammer is offline  
Reply With Quote
Old 04-20-2017, 10:18 AM   #11
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,404
Thanks: 206
Thanked 504 times in 496 posts
Default

If setting CalculateOnBarClose = false will not work for you, then you will need to isolate your strategy's logic to a FirstTickOfBar section if you do not want it to have access to intra-bar data when making trade decisions.

Code:

if(FirstTickOfBar)
{
    // Your code here
}
NinjaTrader_JessicaP is offline  
Reply With Quote
Old 04-20-2017, 04:28 PM   #12
Dzammer
Member
 
Join Date: Aug 2014
Posts: 60
Thanks: 1
Thanked 2 times in 2 posts
Default

Jessica, I think you not understand my question correctly. My strategy work on H1 timeframe and check each price changing of this H1 bar. And if price condition is true, strategy send limit order. In my question of first post you can see, that when price equal 50.12 strategy send order limit by price 50.11, but on the few screenshots we can see, that after 50.12 we have no 50.11, but limit was filled. I hope you understand me.
Dzammer is offline  
Reply With Quote
Old 04-21-2017, 07:48 AM   #13
NinjaTrader_PatrickH
NinjaTrader Customer Service
 
NinjaTrader_PatrickH's Avatar
 
Join Date: Jul 2011
Location: Denver, CO
Posts: 10,319
Thanks: 744
Thanked 1,744 times in 1,680 posts
Default

Hello Dzammer,

Thank you for your response.

You submit your order to 50.12:
Code:
SubmitOrder(0, OrderAction.Sell, OrderType.Limit, 1, 50.12, 0, null, "Entry");
Can you detail where the level of 50.11 comes into play in your code?

I look forward to your response.
NinjaTrader_PatrickH is offline  
Reply With Quote
Old 04-24-2017, 03:18 AM   #14
Dzammer
Member
 
Join Date: Aug 2014
Posts: 60
Thanks: 1
Thanked 2 times in 2 posts
Default

Hello, Patrick.

Quote:
Originally Posted by NinjaTrader_PatrickH View Post
Hello Dzammer,

Thank you for your response.

You submit your order to 50.12:
Code:
SubmitOrder(0, OrderAction.Sell, OrderType.Limit, 1, 50.12, 0, null, "Entry");
Can you detail where the level of 50.11 comes into play in your code?

I look forward to your response.
In the post #12 I make some error. Look of all of my code, please.

Code:
if (Close[0] <= MyInput0
                && !entered)
MyInput = 50.11

Main problem described in the first post. When current price = 50.11 strategy send sell limit with price = 50.12, but after condition is true we have no that price (50.12). You can see it on the few screens.

Thank you!
Dzammer is offline  
Reply With Quote
Old 04-25-2017, 12:26 PM   #15
NinjaTrader_JessicaP
NinjaTrader Customer Service
 
NinjaTrader_JessicaP's Avatar
 
Join Date: Dec 2015
Location: Denver, CO
Posts: 2,404
Thanks: 206
Thanked 504 times in 496 posts
Default

Thank you for your explanation Dzammer, I believe I am on the same page as you are now. One thing we should check is to ensure your PC's clock is in sync. Please see "Understanding trade executions and the local PC clock" on this page for more information.

http://ninjatrader.com/support/helpG..._are_plott.htm
Please use the steps below to change/check your Time Zone and sync the PC clock:
  • Shutdown NinjaTrader
  • Right-click the clock in the lower right corner of your desktop
  • Select Adjust date/time
  • For Windows 10 click 'Additional date, time, & regional settings' -> then click 'Set the time and date'
  • Select the 'Internet Time' tab at the top
  • Set the server to time.nist.gov and then click Update.
  • If the message that appears says successful your PC clock should now be updated.
  • If not, select a different server from the Server: drop-down and try again (repeat until one of the servers is successful)
After updating the PC clock, please restart NinjaTrader, then right-click the chart and select Reload All Historical Data.
This said, this can still occur even if your PC's clock is in sync on a tick chart. Please see "Understanding trade executions on charts with tick based intervals" on this page for more information.

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

If we review your picture in your first post, we can see that 50.12 and 50.11 both happen at 8:39:50 .
NinjaTrader_JessicaP is offline  
Reply With Quote
The following user says thank you to NinjaTrader_JessicaP for this post:
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 06:13 PM.

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.