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

MultiInstrument; second dataserie 'sticky'.

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

    MultiInstrument; second dataserie 'sticky'.

    Hi,

    Following the 'SampleMultiInstrument' Strategy example I coded a few lines which print Time, Close of my first datastream and Close of the second datastream.

    The 1st datastream is 1 minute DAX index, 2nd datastream is 1 minute STOXX index.

    Code:
    protected override void Initialize()
            {
                CalculateOnBarClose = true;
                Add("^STOXX",PeriodType.Minute,1);
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                if (BarsInProgress!=0) return;
                
                Print(ToTime(Time[0]).ToString() + "  " + Closes[0][0].ToString() + "  " + Closes[1][0].ToString());
    The Output Window shows the correct values for Time[0] and Closes[0][0].

    However, Closes[1][0] sometimes has the correct value and sometimes actually shows Closes[1][1], the Close of the previous Bar. So sometimes it updates, sometimes it sticks to the previous bars Close.

    Please see the attachement: screenshot of chart and Output Window.

    What could be the problem in my code, and what would be the solution?

    Thanks!

    Nick
    Attached Files
    Last edited by Nick88; 03-31-2014, 04:27 AM.

    #2
    Nick, I would expect that since you print both from BarsInProgress == 0, your primary series. NinjaTrader is completely event based, so while the first bar update might have triggered, the secondary would not have to be and thus this bar would stick until that is the case. If you print each Closes from it's BarsInProgress (so whenever the OnBarUpdate is called for that instrument / series) should be more what you expect.
    BertrandNinjaTrader Customer Service

    Comment


      #3
      Hi Bertrand,

      The second dataserie in case is the DJ Eurostoxx 50 index which updates every 15 seconds.

      So, in my 1 minute chart I see it update to a new value 4 time per minute. Still, the Output Window often shows the Close of the previous bar, 1 minute ago. It should give me the at least a value for the index not older than about 15 seconds if I'm correct.
      Last edited by Nick88; 03-31-2014, 05:05 AM.

      Comment


        #4
        Nick, how the OnBarUpdate() would update would depend on your CalculateOnBarClose setting for the script - http://www.ninjatrader.com/support/h...onbarclose.htm

        If set to 'true' as would be the default, no intrabar updates would be considered.
        BertrandNinjaTrader Customer Service

        Comment


          #5
          I am a bit confused by the difference in output between the Output Window and the DataBox.

          But I reckon that when CalculateOnBarClose is set to false, I get the 'snapshot' behaviour I am looking for; after each close of the primary bar I want to see the current value of the secondary bar.

          Thank you for your swift response!
          Last edited by Nick88; 03-31-2014, 05:44 AM.

          Comment


            #6
            Correct, as otherwise you are always working off the last completed bar only.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Hi Bertrand and others, a follow up question.

              I have:

              Data 1: fast updating Tick data for ^DAX, updates about once a second.
              Data 2: slow updating Tick data for ^STOXX, updates once per 15 seconds.

              When I get a new Tick for Data 2 I take a 'snapshot' of the data, calculate the Difference between Data 1 and Data 2 and put the result in a DataSerie for further use. I print all values to check if they are correct.

              Code:
              #region Variables
              
              private DataSeries Diff;
              
              #endregion
              
              protectedoverridevoid Initialize()
              
              {
              CalculateOnBarClose = false;
              ExitOnClose=false;
              Add("^STOXX",PeriodType.Tick,1);
              Diff = new DataSeries(this);
              BarsRequired =0;
              }
              
              protectedoverridevoid OnBarUpdate()
              
              {
              if (CurrentBars[0]<BarsRequired || CurrentBars[1]<BarsRequired) return;
              
              if (Historical) return;
              
              if (BarsInProgress == 1)
              {
              
              if (FirstTickOfBar)
              {
              Diff.Set(Closes[0][0]-Closes[1][0]);
              
              Print(Time[0].ToString() + " " + Closes[0][0].ToString("0.00") + " " + Closes[1][0].ToString("0.00") + " " + Diff[0].ToString("0.00") + " " + Diff[1].ToString("0.00")); 
              }
              
              }
              }
              I get correct values for Closes[0][0] , Closes[1][0] and Diff[0], but for Diff[1] I get "0" or incorrect values as a result.

              8-4-2014 12:19:30 9445,05 3166,52 6278,53 0,00

              If I calculate for BarsInProgress == 0 everything works as expected. But obviousely, that is not what I want in this case.

              What goes wrong?

              Thanks!
              Last edited by Nick88; 04-08-2014, 05:17 AM.

              Comment


                #8
                Nick, I would expect that outcome as per default your DataSeries object will be synched to the primary series only, you could though set the sync as desired to make this work as you expect for the second series as well, here's a sample showing the approach - http://www.ninjatrader.com/support/f...ead.php?t=3572
                BertrandNinjaTrader Customer Service

                Comment


                  #9
                  "as per default your DataSeries object will be synched to the primary series only"

                  Thanks, I wasn't aware of that! I have it working now.

                  Cheers

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by arvidvanstaey, Today, 02:19 PM
                  0 responses
                  0 views
                  0 likes
                  Last Post arvidvanstaey  
                  Started by mmckinnm, Today, 01:34 PM
                  3 responses
                  5 views
                  0 likes
                  Last Post NinjaTrader_ChelseaB  
                  Started by f.saeidi, Today, 01:32 PM
                  2 responses
                  5 views
                  0 likes
                  Last Post f.saeidi  
                  Started by alifarahani, 04-19-2024, 09:40 AM
                  9 responses
                  55 views
                  0 likes
                  Last Post NinjaTrader_Jesse  
                  Started by Conceptzx, 10-11-2022, 06:38 AM
                  3 responses
                  60 views
                  0 likes
                  Last Post NinjaTrader_SeanH  
                  Working...
                  X