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

Sync Multiple Time Frames

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

    Sync Multiple Time Frames

    What is the proper way to synchronize multiple time frames in a strategy and return the current value of additional time series?

    I have a strategy using cumulative delta which requires a secondary 1 tick time frame and I have an additional 3 minute time frame...

    else if (State == State.Configure)
    {
    AddDataSeries(Data.BarsPeriodType.Tick, 1);
    AddDataSeries(Data.BarsPeriodType.Minute, 3);
    }

    I need to synchronize them. Part of the logic is the current close is higher than the open of the 3 minute bar. (for longs)

    (Closes[2][0] > Opens[2][0])

    It looks like the values of the previous 3 minute candles are being returned not the current.

    I see under help guide cumulative delta instructions on syncing the 1 tick time frame.

    else if (BarsInProgress == 1)

    {

    // We have to update the secondary series of the hosted indicator to make sure the values we get in BarsInProgress == 0 are in sync

    cumulativeDelta.Update(cumulativeDelta.BarsArray[1].Count - 1, 1);

    }




    #2
    Hello sdauteuil,

    From the description that sounds correct, when using 0 bars ago that would return the last closed bars value. Depending on what series called the Closes[2][0] that would return the last closed 3 minute bar at that time in processing. Only if you are in Realtime and using OnEachTick calculation would the Closes[2][0] represent that series last price.

    The other logic you have shown is needed specifically for the CumulativeDelta indicator because that is required for it to work, that is not something you would need when adding other series or using other indicators.

    Please let me know if I may be of additional assistance.
    JesseNinjaTrader Customer Service

    Comment


      #3
      In real time is it possible to have the primary bar / time frame operate under OnBarUpdate()
      and have the additional time frame (3 minute in this case) operate OnEachTick.

      Basically if I am using OnBarUpdate can I access the current / real time value of the other time series?

      Comment


        #4
        Also I currently do not have the code to sync the 1 tick time frame for cumulative delta.

        Should I add this (code below) under State == State.DataLoaded?


        else if (BarsInProgress == 1)

        {

        // We have to update the secondary series of the hosted indicator to make sure the values we get in BarsInProgress == 0 are in sync

        cumulativeDelta.Update(cumulativeDelta.BarsArray[1].Count - 1, 1);

        }

        Comment


          #5
          Hello sdauteuil,

          In real time is it possible to have the primary bar / time frame operate under OnBarUpdate()
          and have the additional time frame (3 minute in this case) operate OnEachTick.

          Basically if I am using OnBarUpdate can I access the current / real time value of the other time series?
          No however when using OnEachTick you could simulate that by using IsFirstTickOfBar as long as you are using a BarsType which supports that. Basically all bars types except renko.
          https://ninjatrader.com/support/help...FirstTickOfBar

          Also I currently do not have the code to sync the 1 tick time frame for cumulative delta.

          Should I add this (code below) under State == State.DataLoaded?
          Yes but that would go in OnBarUpdate just like the sample shows, that is required for this indicator.

          Please let me know if I may be of additional assistance.
          JesseNinjaTrader Customer Service

          Comment


            #6
            Which is the proper use of if and else if in this instance? Use If and else if OR Use 2 if statements

            protected override void OnBarUpdate()
            {
            if (BarsInProgress == 1)
            cumulativeDelta.Update(cumulativeDelta.BarsArray[1].Count - 1, 1);

            if (BarsInProgress != 0)
            return;

            if ((CurrentBars[0] < 20)
            || (CurrentBars[1] < 20)
            || (CurrentBars[2] < 20))
            return;

            // Rest of Code

            OR

            protected override void OnBarUpdate()
            {
            if (BarsInProgress == 1)
            cumulativeDelta.Update(cumulativeDelta.BarsArray[1].Count - 1, 1);

            else if (BarsInProgress != 0)
            return;

            if ((CurrentBars[0] < 20)
            || (CurrentBars[1] < 20)
            || (CurrentBars[2] < 20))
            return;

            // Rest of Code

            Comment


              #7
              Hello sdauteuil, thanks for your reply.

              We use the ELSE clause when we want something to happen if the previous condition was explicitly false. The ELSE part will only be evaluated if the above IF is false. In this case you would want to use
              if (BarsInProgress == 1)
              cumulativeDelta.Update(cumulativeDelta.BarsArray[1].Count - 1, 1);

              if (BarsInProgress != 0)
              return;

              Please let me know if I may provide any further information.
              Chris L.NinjaTrader Customer Service

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Barry Milan, Today, 10:35 PM
              0 responses
              2 views
              0 likes
              Last Post Barry Milan  
              Started by DJ888, Yesterday, 06:09 PM
              2 responses
              9 views
              0 likes
              Last Post DJ888
              by DJ888
               
              Started by jeronymite, 04-12-2024, 04:26 PM
              3 responses
              40 views
              0 likes
              Last Post jeronymite  
              Started by bill2023, Today, 08:51 AM
              2 responses
              16 views
              0 likes
              Last Post bill2023  
              Started by sidlercom80, 10-28-2023, 08:49 AM
              167 responses
              2,260 views
              0 likes
              Last Post jeronymite  
              Working...
              X