Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

H4/240M-Chart: bar compression not understandable

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

    H4/240M-Chart: bar compression not understandable

    After having found some non-understandable behaviour of a system in a backtest I've analysed the trades in detail. Then I found a difference between the data of a 1M-chart and the 240M-chart. I've attached 2 images to illustrate my question.

    What I would have expected by looking at the M1-chart:
    Click image for larger version

Name:	M1.png
Views:	1
Size:	73.5 KB
ID:	897076

    What I get on the H4/240M-chart:
    Click image for larger version

Name:	H4.png
Views:	1
Size:	108.4 KB
ID:	897077

    I thought NT renders 240M-charts with M1-bars as a basis, but it doesn't seem so...
    Any help would be highly appreciated.

    #2
    Ignignokt, the data you have highlighted in the 1M chart would be the data used to build the 20:00 bar, not the 16:00 bar.

    A quick glance at the next 4H bar confirms this.
    AustinNinjaTrader Customer Service

    Comment


      #3
      Ah, thank you Austin. Just for my better understanding: why is the bar, which contains data from 16:00-19:59, stamped as "20:00-bar"? That's uncommon in my eyes.

      Comment


        #4
        I believe the theory is it makes more sense to start building the next bar with present data instead of the other way around (building the present bar with the next set of data). This is just the way NinjaTrader builds bars.
        AustinNinjaTrader Customer Service

        Comment


          #5
          OK, that's a valid point of view. It's just confusing for me, because I haven't found this in any other software so far, as far as I remember.

          However when I run a strategy on a M1-chart which pulls its signals from a H4-chart, the bar-building seems to work the way I thought it does:
          My entry is at 18.11.2009 18:56.00. When I print Times[1][0] at the moment the entry signal occurs, I get 18.11.2009 16:00.00. From what you said earlier I would have expected to get 20:00 o'clock.

          Looks to me like there's a difference in bar building between charting and backtesting.

          Comment


            #6
            Ignignokt, are you using limit orders for your strategies? If so, the entry was probably generated by the 16:00 bar (since the signals are generated by the H4 bar), submitted to the M1 series, and executed on the M1 series at 18:56.

            If that is not the case, could you please post your strategy here so I can take a look at it to explain what is happening?
            AustinNinjaTrader Customer Service

            Comment


              #7
              Posting my strategy wouldn't be necessary. I isolated this issue by creating and running the following strategy:
              Code:
                  public class testStrategy : Strategy
                  {
                      #region Variables
                      // Wizard generated variables
                      // 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()
                      {
                          Add(PeriodType.Minute,240);  //BarsArray[1]
                          
                          CalculateOnBarClose = true;
                      }
              
                      /// <summary>
                      /// Called on each bar update event (incoming tick)
                      /// </summary>
                      protected override void OnBarUpdate()
                      {
                          log(1,"OnBarUpdate()","H4 BarTime="+TimeToString(Times[1][0]));
                      }
              
                      #region Properties
                      #endregion
                  }
              The custom methods one would need to run this code are the following ones:
              Code:
              //Log-Methode
                      public void log(int logLevel, string sourceMethod, string logMessage) {
                          string time=TimeToString(Time[0]);
                          string logStr=time+" ";
                          if (logLevel==0) logStr+="DEBUG  ";
                          if (logLevel==1) logStr+="INFO   ";
                          if (logLevel==2) logStr+="WARNING";
                          if (logLevel==3) logStr+="ERROR   ";
                          if (logLevel==4) logStr+="CRITICAL ERROR";
                          logStr+=base.Bars.Instrument.FullName+" "+sourceMethod+" "+logMessage;
                          
                          Print(logStr);
                          
                          string    path= Cbi.Core.UserDataDir.ToString() + "logfile.txt";
                          //System.IO.File.WriteAllText(path,logStr);
                          using (System.IO.StreamWriter file = new System.IO.StreamWriter(path, true))
                          {
                              try {
                                  file.WriteLine(logStr);
                              }
                              catch {
                                  Print("ERROR while writing to logfile");
                              }
                          } 
                      }
              
              public string TimeToString(DateTime time) {
                          return(time.ToString("dd.MM.yyyy HH:mm.ss"));
                      }
              After running this on a M1-chart I get the following:
              18.11.2009 18:56.00 INFO CL 07-11 OnBarUpdate() H4 BarTime=18.11.2009 16:00.00

              EDIT:
              I don't use limit orders in my strategy, I use market orders.

              Comment


                #8
                Thanks for the code and the test scenario. It does appear the bar building isn't the same.

                If the strategy is run in real-time with CalculateOnBarClose = false, the building is as I explained it earlier, but if you run it with COBC = true, then it is as you explained it.

                This is because when COBC = true, the bar (bar b) doesn't actually close until the first tick of the next bar comes in (bar c). When COBC = false, the new bar (bar b) starts building as soon as the previous one is finished (bar a), but doesn't officially close until the next bar starts (bar c).

                In NinjaTrader, when running COBC = true, the close of the current bar and the open of the next bar are virtually the same exact event.

                If this isn't clear, please let me know and I will do my best to explain it again.
                AustinNinjaTrader Customer Service

                Comment


                  #9
                  OK, thank you. Now I understand the difference between COBC true vs. false even better. I'm still new to NT.

                  Comment


                    #10
                    Sounds good, Ignignokt. We all started somewhere. Feel free to ask us any questions you may have.
                    AustinNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by adeelshahzad, Today, 03:54 AM
                    5 responses
                    31 views
                    0 likes
                    Last Post NinjaTrader_BrandonH  
                    Started by stafe, 04-15-2024, 08:34 PM
                    7 responses
                    31 views
                    0 likes
                    Last Post NinjaTrader_ChelseaB  
                    Started by merzo, 06-25-2023, 02:19 AM
                    10 responses
                    823 views
                    1 like
                    Last Post NinjaTrader_ChristopherJ  
                    Started by frankthearm, Today, 09:08 AM
                    5 responses
                    18 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Started by jeronymite, 04-12-2024, 04:26 PM
                    3 responses
                    43 views
                    0 likes
                    Last Post jeronymite  
                    Working...
                    X