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!
See more
See less

Partner 728x90

Collapse

Market replay price process understanding.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    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?
    Click image for larger version

Name:	NT7Filling.png
Views:	1
Size:	345.8 KB
ID:	907395

    #2
    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.
    JesseNinjaTrader Customer Service

    Comment


      #3
      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.

      Comment


        #4
        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.
        JesseNinjaTrader Customer Service

        Comment


          #5
          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 Files

          Comment


            #6
            Can anybody help me?

            Comment


              #7
              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:
              [FONT=Courier New]    /// <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;[/FONT]
              [FONT=Courier New][B]            Add(PeriodType.Tick, 1);[/B]
              [/FONT]
              [FONT=Courier New]        }
              
                      /// <summary>
                      /// Called on each bar update event (incoming tick)
                      /// </summary>
                      protected override void OnBarUpdate()
                      {[/FONT]
              [FONT=Courier New]            [B]// make sure we are using the primary series[/B][/FONT]
              [FONT=Courier New][B]            if (BarsInProgress != 0) return;[/B][/FONT]
              [FONT=Courier New]
              [/FONT]
              [FONT=Courier New]            // Condition set 1
                          if (Close[0] <= MyInput0
                              && !entered)
                          {
                              entered = true;[/FONT]
              [FONT=Courier New]                Print("[B]OnBarUpdate: [/B]Time = " + Time[B]s[1][/B][0][/FONT][FONT=Courier New][FONT=Courier New][B].ToString("[/B][/FONT][FONT=Courier New][B]dd MMM yyyy HH:mm:ss.ffff")[/B][/FONT] + " / Close = " + Close[0]);
                              SubmitOrder(0, OrderAction.Sell, OrderType.Limit, 1, 50.12, 0, null, "Entry");
                          }
                      }[/FONT]
              
              
              [FONT=Courier New] [B]       // This gets triggered once a trade is placed[/B][/FONT][B]
              [FONT=Courier New]        protected override void OnExecution(IExecution execution)[/FONT]
              [FONT=Courier New]        {[/FONT]
              [FONT=Courier New]                Print(String.Format("OnExecution: Time = {0:[/FONT][FONT=Courier New][FONT=Courier New]dd MMM yyyy HH:mm:ss.ffff}[/FONT][/FONT][FONT=Courier New][FONT=Courier New][FONT=Courier New] / Close = {1:C}[/FONT][/FONT]",  execution.Time,[/FONT][FONT=Courier New] execution.Price));[/FONT]
              [FONT=Courier New]        }[/FONT][/B]
              
              [FONT=Courier New]
              [/FONT]
              [FONT=Courier New]        #region Properties
                      [Description("")]
                      [GridCategory("Parameters")]
                      public double MyInput0
                      {
                          get { return myInput0; }
                          set { myInput0 = Math.Max(1, value); }
                      }
                      #endregion
                  }[/FONT]
              Jessica P.NinjaTrader Customer Service

              Comment


                #8
                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 Files

                Comment


                  #9
                  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.
                  Jessica P.NinjaTrader Customer Service

                  Comment


                    #10
                    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).

                    Comment


                      #11
                      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:
                      [FONT=Courier New]
                      if(FirstTickOfBar)
                      {
                          // Your code here
                      }[/FONT]
                      Jessica P.NinjaTrader Customer Service

                      Comment


                        #12
                        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.

                        Comment


                          #13
                          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.

                          Comment


                            #14
                            Hello, Patrick.

                            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!

                            Comment


                              #15
                              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.



                              If we review your picture in your first post, we can see that 50.12 and 50.11 both happen at 8:39:50 .
                              Jessica P.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by elderan, Yesterday, 08:03 PM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_BrandonH  
                              Started by samish18, Yesterday, 08:57 AM
                              8 responses
                              25 views
                              0 likes
                              Last Post samish18  
                              Started by DJ888, 04-16-2024, 06:09 PM
                              3 responses
                              10 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by RookieTrader, Today, 07:41 AM
                              0 responses
                              3 views
                              0 likes
                              Last Post RookieTrader  
                              Started by maybeimnotrader, Yesterday, 05:46 PM
                              1 response
                              19 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X