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

Wrong data

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

    Wrong data

    Hi,

    I am running a simple strategy on 100 Range chart using Market Replay.
    I output the data from Lows, Highs and Times and it seems that the data is 3 bars late.
    for example, when i output Lows[0][0] i get the data from the fourth bar and not the first.

    Please help

    #2
    kiss,

    This shouldn't be the case, but I would need to see more code. Could you possible post more of your code here?
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your reply.
      I attached code+print screen.
      Attached Files

      Comment


        #4
        kiss,

        I'll have to test on my end here, however I can see what you are pointing at.

        This is market replay correct? Do you download this data from the market replay servers or record it from your data provider?
        Adam P.NinjaTrader Customer Service

        Comment


          #5
          Hi,

          I downloaded the data for the market replay. My data provider ad broker is MBTrading.

          I now tried it on live (demo) and same error accord only this time more than 3 bars difference.
          When i connected today, NT downloaded missing data. I think (and it's just an idea) that the script recognize the first bar BEFORE the new data download as the first bar in the chart (although new bars are now shown after the download).
          Last edited by kiss987; 09-06-2012, 04:48 AM.

          Comment


            #6
            I did some more testing and the problem still remain, but i dont think it has to do with my connection time.

            Also i added the following line:
            Print(DateTime.Now.ToString() + " " + Time.ToString());
            which gave:
            9/6/2012 15:28:46 9/5/2012 0:03:22
            9/6/2012 15:28:46 is the correct local date and time (I live in Israel).
            i don't know why Time.ToString is printing 9/5/2012 0:03:22.

            when i changed the output to 1 minute bars i got:
            i= 0 LowsBid= 1.25637 9/5/2012 0:03:00
            i= 1 LowsBid= 1.25641 9/5/2012 0:02:00
            i= 2 LowsBid= 1.25631 9/4/2012 23:59:00
            i= 3 LowsBid= 1.25638 9/4/2012 23:58:00
            i= 4 LowsBid= 1.25638 9/4/2012 23:57:00

            Maybe it's something with local time and server time...
            i changed my session from UTC-06 to UTC+2 but it didnt change much...
            btw, i trade forex if it changes anything.
            i also deleted my db cache data but no luck.
            Last edited by kiss987; 09-06-2012, 06:45 AM.

            Comment


              #7
              Where did you add this new print statement? Was this OnStartUp()?

              If you change the number of "Days to load", does it output different date/time?
              MatthewNinjaTrader Product Management

              Comment


                #8
                Yes, OnStartUp.
                "Days to load" on the chart? i changed it but it doesn't help. i dont execute the strategy from a chart, but from the strategies tab->new srtategy

                Comment


                  #9
                  Does the value change if you change the number of bars to load from the strategy tab then?
                  MatthewNinjaTrader Product Management

                  Comment


                    #10
                    no, it doesnt...
                    I just ran the script on a different computer and the problem happens on it as well.
                    were u able to restore the problem?
                    Last edited by kiss987; 09-06-2012, 01:47 PM.

                    Comment


                      #11
                      Hello,

                      OnStartUp is only ran on the first bar on the chart. So when you're printing DateTime.Now and Time[0], you're getting the current time, and the time of the first bar of the chart.

                      You're also going to have to move the for loop to OnBarUpdate() in order to start on the most current bar on the chart

                      Code:
                      		protected override void OnBarUpdate()
                      		{
                      			Print("OnBarUpdate");
                      			Print("Time : " + Time.ToString());
                      			if(CurrentBar<10)return;
                      
                      				
                      			for(int i = 0; i < 10 ; i++)
                      			{
                      				Print("i= " + i + " LowsBid= " + Lows[0][i] + " " + Times[0][i]);
                      			}
                      		
                      		}
                      When I run this, I get the correct lows:

                      Time : 9/6/2012 3:29:00 PM
                      i= 0 LowsBid= 1432.75 9/6/2012 3:29:00 PM
                      i= 1 LowsBid= 1432.25 9/6/2012 3:28:00 PM
                      i= 2 LowsBid= 1432.25 9/6/2012 3:27:00 PM
                      i= 3 LowsBid= 1432.25 9/6/2012 3:26:00 PM
                      i= 4 LowsBid= 1432.25 9/6/2012 3:25:00 PM
                      i= 5 LowsBid= 1432.25 9/6/2012 3:24:00 PM
                      i= 6 LowsBid= 1432.25 9/6/2012 3:23:00 PM
                      i= 7 LowsBid= 1432.5 9/6/2012 3:22:00 PM
                      i= 8 LowsBid= 1432.5 9/6/2012 3:21:00 PM
                      i= 9 LowsBid= 1432.5 9/6/2012 3:20:00 PM
                      Please let me know if that does not produce the results or behavior you're seeking.
                      MatthewNinjaTrader Product Management

                      Comment


                        #12
                        Thank you for your relpy,

                        I tried your new code and what happened is that the log wrote data of thousands bars ago until the current bar (most right). it seems the OnBarUpdate is called not only for the most right bar but starting with many bars ago until the right bar.

                        I changed the code to the following:

                        if(Count-CurrentBar > 5)return;

                        ClearOutputWindow();
                        Print("OnBarUpdate");
                        Print("Time : " + Time.ToString() + " DateTime : " + DateTime.Now.ToString());



                        for(int i = 0; i < 3 ; i++)
                        {
                        Print("Count= " + Count + " CurrentBar= " + CurrentBar + " i= " + i + " LowsBid= " + Lows[0][i] + " " + Times[0][i]);
                        }
                        This code got me the data from the last few bars only which is what i wanted.

                        My new question is: Is this the correct behavior? does the OnBarUpdate should refer to historical bars and not just new ticks from after the strategy start?

                        Comment


                          #13
                          OnBarUpdate will run on each bar on historical data first starting on bar 0, and then will continue to update on the current bar, depending on your COBC settings - when set to True, it will update when each new bar closes, and when set to false it will update with each incoming tick.
                          MatthewNinjaTrader Product Management

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by warreng86, 11-10-2020, 02:04 PM
                          5 responses
                          1,357 views
                          0 likes
                          Last Post NinjaTrader_Manfred  
                          Started by Perr0Grande, Today, 08:16 PM
                          0 responses
                          3 views
                          0 likes
                          Last Post Perr0Grande  
                          Started by elderan, Today, 08:03 PM
                          0 responses
                          5 views
                          0 likes
                          Last Post elderan
                          by elderan
                           
                          Started by algospoke, Today, 06:40 PM
                          0 responses
                          10 views
                          0 likes
                          Last Post algospoke  
                          Started by maybeimnotrader, Today, 05:46 PM
                          0 responses
                          12 views
                          0 likes
                          Last Post maybeimnotrader  
                          Working...
                          X