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

Issue with bars sync

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

    Issue with bars sync

    Hello,

    I have a strategy with 7 timeframes:
    Time frame 0 is the chart (usually 1 minute chart ) and then in
    State.Configure I have:
    AddDataSeries(Data.BarsPeriodType.Minute, 1);//1
    AddDataSeries(Data.BarsPeriodType.Minute, 5);//2
    AddDataSeries(Data.BarsPeriodType.Minute, 10);//3
    AddDataSeries(Data.BarsPeriodType.Minute, 15);//4
    AddDataSeries(Data.BarsPeriodType.Minute, 30);//5
    AddDataSeries(Data.BarsPeriodType.Minute, 60);//6

    if I print the sequence of bar times with:

    Print("In progress " + BarsInProgress.ToString() + " Time " + Times[BarsInProgress][0].ToString());

    I see in the output tab:

    In progress 0 Time 10/14/2019 7:37:00 AM
    In progress 1 Time 10/14/2019 7:37:00 AM
    In progress 0 Time 10/14/2019 7:38:00 AM
    In progress 1 Time 10/14/2019 7:38:00 AM
    In progress 0 Time 10/14/2019 7:39:00 AM
    In progress 1 Time 10/14/2019 7:39:00 AM
    In progress 3 Time 10/14/2019 7:45:00 AM
    In progress 4 Time 10/14/2019 7:45:00 AM
    In progress 0 Time 10/14/2019 7:52:00 AM
    In progress 1 Time 10/14/2019 7:52:00 AM
    In progress 1 Time 10/14/2019 7:53:00 AM
    In progress 0 Time 10/14/2019 7:54:00 AM
    In progress 1 Time 10/14/2019 7:54:00 AM
    In progress 0 Time 10/14/2019 8:08:00 AM

    Look please at the bold lines: you can see that are missing several 1 minute bars; these bars are existing in the
    historical data and in the 1 minute chart (please look at the attached image)


    Why this wierd behaviour? Am I missing something?
    Thanks


    #2
    Hello gbulle,

    Thank you for your note.

    I've created a slightly simplified test script - I took out the added 1 minute data series and renumbered them so number 1 is the 5 minute and number 5 is the 60 minute and so on. Just makes it a little easier to follow what's happening.

    Try running this - you should see something similar to this:

    BIP: 0 | CurrentBars[BarsInProgress]: 0 | Time: 10/13/2019 4:01:00 PM
    BIP: 0 | CurrentBars[BarsInProgress]: 1 | Time: 10/13/2019 4:02:00 PM
    BIP: 0 | CurrentBars[BarsInProgress]: 2 | Time: 10/13/2019 4:03:00 PM
    BIP: 0 | CurrentBars[BarsInProgress]: 3 | Time: 10/13/2019 4:04:00 PM
    BIP: 0 | CurrentBars[BarsInProgress]: 4 | Time: 10/13/2019 4:05:00 PM
    BIP: 1 | CurrentBars[BarsInProgress]: 0 | Time: 10/13/2019 4:05:00 PM
    BIP: 0 | CurrentBars[BarsInProgress]: 5 | Time: 10/13/2019 4:06:00 PM
    BIP: 0 | CurrentBars[BarsInProgress]: 6 | Time: 10/13/2019 4:07:00 PM
    BIP: 0 | CurrentBars[BarsInProgress]: 7 | Time: 10/13/2019 4:08:00 PM
    BIP: 0 | CurrentBars[BarsInProgress]: 8 | Time: 10/13/2019 4:09:00 PM
    BIP: 0 | CurrentBars[BarsInProgress]: 9 | Time: 10/13/2019 4:10:00 PM
    BIP: 1 | CurrentBars[BarsInProgress]: 1 | Time: 10/13/2019 4:10:00 PM
    BIP: 2 | CurrentBars[BarsInProgress]: 0 | Time: 10/13/2019 4:10:00 PM
    BIP: 0 | CurrentBars[BarsInProgress]: 10 | Time: 10/13/2019 4:11:00 PM
    BIP: 0 | CurrentBars[BarsInProgress]: 11 | Time: 10/13/2019 4:12:00 PM
    BIP: 0 | CurrentBars[BarsInProgress]: 12 | Time: 10/13/2019 4:13:00 PM
    BIP: 0 | CurrentBars[BarsInProgress]: 13 | Time: 10/13/2019 4:14:00 PM
    BIP: 0 | CurrentBars[BarsInProgress]: 14 | Time: 10/13/2019 4:15:00 PM
    BIP: 1 | CurrentBars[BarsInProgress]: 2 | Time: 10/13/2019 4:15:00 PM
    BIP: 3 | CurrentBars[BarsInProgress]: 0 | Time: 10/13/2019 4:15:00 PM
    As you can see from the above, our primary data series is a 1 minute series. That's triggered 5 times, after which our 1st added series, the 5 minute fires. We then see five more OnBarUpdates run for the 1 minute series, followed by our second update of our 5 minute data series, and the 1st update of our 10 minute data series. I think it's just getting a little confusing when you've got the primary series the same as your secondary series.

    Please let us know if we may be of further assistance to you.
    Attached Files
    Kate W.NinjaTrader Customer Service

    Comment


      #3
      Hi,
      thank you for you answer. I just did what you did
      0=1 minute
      1= 5 minute
      ecc.
      but I still see missing data (please ses below).
      Any suggestion?

      Thanks


      In progress 2 Time 10/14/2019 7:35:00 AM
      In progress 0 Time 10/14/2019 7:36:00 AM
      In progress 0 Time 10/14/2019 7:37:00 AM
      In progress 0 Time 10/14/2019 7:38:00 AM
      In progress 0 Time 10/14/2019 7:39:00 AM ? 7:40 --> 7.45
      In progress 2 Time 10/14/2019 7:45:00 AM
      In progress 3 Time 10/14/2019 7:45:00 AM
      In progress 0 Time 10/14/2019 7:52:00 AM 7.46-> 7.51
      In progress 0 Time 10/14/2019 7:53:00 AM
      In progress 0 Time 10/14/2019 7:54:00 AM
      In progress 0 Time 10/14/2019 8:08:00 AM 7.54-> 8.07
      In progress 0 Time 10/14/2019 8:09:00 AM

      Comment


        #4
        However I must say that a very simple strategy works fine (please see below) so probably I'm doing something wrong in the strategy.
        that affects the bars. Any suggestion?
        TX

        BIP: 0 | CurrentBars[BarsInProgress]: 11381 | Time: 10/14/2019 7:29:00 PM
        BIP: 0 | CurrentBars[BarsInProgress]: 11382 | Time: 10/14/2019 7:30:00 PM
        BIP: 1 | CurrentBars[BarsInProgress]: 2351 | Time: 10/14/2019 7:30:00 PM
        BIP: 3 | CurrentBars[BarsInProgress]: 783 | Time: 10/14/2019 7:30:00 PM
        BIP: 0 | CurrentBars[BarsInProgress]: 11383 | Time: 10/14/2019 7:31:00 PM
        BIP: 0 | CurrentBars[BarsInProgress]: 11384 | Time: 10/14/2019 7:32:00 PM
        BIP: 0 | CurrentBars[BarsInProgress]: 11385 | Time: 10/14/2019 7:33:00 PM
        BIP: 0 | CurrentBars[BarsInProgress]: 11386 | Time: 10/14/2019 7:34:00 PM
        BIP: 0 | CurrentBars[BarsInProgress]: 11387 | Time: 10/14/2019 7:35:00 PM
        BIP: 1 | CurrentBars[BarsInProgress]: 2352 | Time: 10/14/2019 7:35:00 PM
        BIP: 2 | CurrentBars[BarsInProgress]: 1180 | Time: 10/14/2019 7:35:00 PM
        BIP: 0 | CurrentBars[BarsInProgress]: 11388 | Time: 10/14/2019 7:36:00 PM
        BIP: 0 | CurrentBars[BarsInProgress]: 11389 | Time: 10/14/2019 7:37:00 PM
        BIP: 0 | CurrentBars[BarsInProgress]: 11390 | Time: 10/14/2019 7:38:00 PM
        BIP: 0 | CurrentBars[BarsInProgress]: 11391 | Time: 10/14/2019 7:39:00 PM
        BIP: 0 | CurrentBars[BarsInProgress]: 11392 | Time: 10/14/2019 7:40:00 PM
        BIP: 1 | CurrentBars[BarsInProgress]: 2353 | Time: 10/14/2019 7:40:00 PM
        BIP: 0 | CurrentBars[BarsInProgress]: 11393 | Time: 10/14/2019 7:41:00 PM
        BIP: 0 | CurrentBars[BarsInProgress]: 11394 | Time: 10/14/2019 7:42:00 PM
        BIP: 0 | CurrentBars[BarsInProgress]: 11395 | Time: 10/14/2019 7:43:00 PM
        BIP: 0 | CurrentBars[BarsInProgress]: 11396 | Time: 10/14/2019 7:44:00 PM
        BIP: 0 | CurrentBars[BarsInProgress]: 11397 | Time: 10/14/2019 7:45:00 PM

        Comment


          #5
          Hi,

          I found the issue ..but at this moment I don't know how to fix... the mess in the sync of the bars is created by
          if (BarsInProgress == 0){
          my_prep_list.Clear();
          my_signal_list.Clear();
          }
          If I comment the above lines everything is fine.
          The lists are declared as
          private List<My_Prep> my_prep_list = new List<My_Prep>();
          private List<My_Prep> my_signal_list = new List<My_Prep>();

          where My_Prep is a class.

          In the lists I store several infos about the trades generated by the strategy

          Any suggestion? Is better to work with array?
          Thanks



          Comment


            #6
            Hi,
            after having realized that,in a multi time frame strategy, if you decide to store informations into a LIST the clearing (.Clear) of the LIST affects the sync of the bars (thread issue?)
            I replaced List with ConcurrendDictionary and then I decided to logically (not physically) delete the content of the Dictionary; now the sync of the bars is perfect
            Tx

            Comment


              #7
              Hello gbulle,

              Thank you for your note.

              Would you be able to create a simple example strategy that shows the behavior when using/clearing a List? You can exclude any code not needed to replicate. I'd like to test it and see if it's anything we need to bring to the developers' attention or if it's something expected.

              Thanks in advance; I look forward to your reply.
              Kate W.NinjaTrader Customer Service

              Comment


                #8
                Hi,
                I'm still investigating because if I eliminate the code lines of the trading logic everything is fine, so it is not the CLEAR function of the List but something else.
                If i comment the software of the trading looic everything is working fine..i'm confused.....as soon as I have a definitive answer I will reply you again..the error is diabolic
                because I don't see any error in the strategy, just the bars not synchronized
                TX

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by andrewtrades, Today, 04:57 PM
                1 response
                6 views
                0 likes
                Last Post NinjaTrader_Manfred  
                Started by chbruno, Today, 04:10 PM
                0 responses
                5 views
                0 likes
                Last Post chbruno
                by chbruno
                 
                Started by josh18955, 03-25-2023, 11:16 AM
                6 responses
                436 views
                0 likes
                Last Post Delerium  
                Started by FAQtrader, Today, 03:35 PM
                0 responses
                7 views
                0 likes
                Last Post FAQtrader  
                Started by rocketman7, Today, 09:41 AM
                5 responses
                19 views
                0 likes
                Last Post NinjaTrader_Jesse  
                Working...
                X