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

Multi-series Data Synchronization

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

    Multi-series Data Synchronization

    Hello Ninja Support Team,

    I am trying to develop an indicator that uses multi-series data. My primary bars object is a tick chart and I have added three minute charts, 1, 3 and 9 minute, to create a multi-series environment. I have created several conditions using data from both the primary and secondary objects. I use these conditions to control the background color of the primary bars object, the tick chart and issue an alert.

    I followed the data synchronization guidelines shown in the SampleDataSeries, strategy folder/section I found in Ninja support forum. Do these guidelines also work for indicators? I must use an indicator for this because I use Chart Trader.

    I tested my indicator on real time replay data. It does not execute correctly on real time data. But, if I pause the replay, re-apply the indicator, the code correctly colors the history bar where the conditions were met.

    What must I do to get this code to execute correctly on real time data? Or, does the data synchronization only work in strategies?

    Sincerely,
    Steve

    #2
    Hello steveobowen,

    You can use that synchronization method inside of an Indicator as well yes.

    Let us know if we can be of further assistance.
    JCNinjaTrader Customer Service

    Comment


      #3
      Multi-Series Data Synchronization

      HI JC,

      Any suggestions why the indicator is correct on static history data but not on real time data? In the secondary bars objects I have CalculateOnBarClose = true and in the primary bars object I have CalculateOnBarClose = false.

      Steve

      Comment


        #4
        Hello stevenobowen,

        You will not be able to set the CalculateOnBarClose setting for the secondary data series only the primary Data Series.

        With that said, I would use some Print() statements to be able to see how your code is executing to make sure it is how you are expecting it to. The following link will go over how to use the Print() statement to be able to see who your code is executing.
        http://www.ninjatrader.com/support/f...ead.php?t=3418
        JCNinjaTrader Customer Service

        Comment


          #5
          Hi JC,
          I am troubleshooting a multi-series environment indicator. I have 1 minute, 3 minute and 9 minute charts in my workspace. On each of these charts, I have a trend indicator that determines the trend direction. I put the trend status into a data series. I set the value = 1 when the trend is up, = -1 when the trend is down, and = 0 when there is no trend.
          The multi-series indicator that I am troubleshooting plots the trend agreement status of the trends from the multi-series environment. I followed the synchronization guidelines and synchronized the trend status data from the 1, 3, and 9 minute charts. I will apply this indicator to the 1 minute chart.
          Here is that code:
          private DataSeries tsTrend_1M;
          private DataSeries tsTrend_3M;
          private DataSeries tsTrend_9M;
          .
          Initizlize()
          Add(new Plot(Color.FromKnownColor(KnownColor.Black), PlotStyle.Dot, "TrendAgree"));
          tsTrend_1M = new DataSeries(this); //sync tsTrend_1M with 1 minute chart
          Add(PeriodType.Minute, 3);
          Add(PeriodType.Minute, 9);
          OnBarUpdate()
          if ( BarsInProgress == 0 ) //set primary object variables
          tsTrend_1M.Set(TradeSafeTrend(Color.MistyRose, Color.PaleGreen).TsTrend[0]);
          if ( tsTrend_3M == null ) //sync tsTrend_3M with 3 minute chart
          tsTrend_3M = new DataSeries(SMA(BarsArray[1],50)); //choose any indicator to sync the object

          if ( BarsInProgress == 1 ) //set secondary object variable
          tsTrend_3M.Set(TradeSafeTrend(Color.MistyRose,Colo r.PaleGreen).TsTrend[0]);

          Then the same sync for the 9 minute data.
          Then the plot set code. If the 1 min and 3 min agree up and the 9 minute does not, set a value of 1.
          if (BarsInProgress != 0)
          return;
          if ( tsTrend_1M[0] == 1
          &&tsTrend_3M[0] == 1
          &&tsTrend_9M[0] != 1
          )
          TrendAgree.Set(1);
          And so on with the rest of the plot set code.
          The error, invalid values for the trend agreement, occur when the 3 minute bar closes or the 9 minute bar closes or when the trend changes on either the 9 minute or 3 minute chart. But, there are periods when the plot is good. These invalid values occur with either static history or real time code..

          What do I have to do to sync these data series better or eliminate the occurrence of the invalid trend agreement values at the 3 minute or 9 minute bar closures or trend changes?

          Is what I am trying to do with this indicator illegal?
          Steve

          Comment


            #6
            Hello steveobowen,

            I do not see anything wrong with your snippets of code so far. I would recommend putting a Print() statement in the beginning of OnBarUpdate() to check that the BarsInProgress is being processed as you would expect. For example:

            Code:
            protected override void OnBarUpdate()
            {
                  Print("BarsInProgress = " + BarsInProgress + " Time = "+Time[0]);
            
            (...)
            }
            Also, are you checking your conditions in which you are setting your trend agreement to make sure they are the values you expect?

            Happy to be of further assistance.
            JCNinjaTrader Customer Service

            Comment


              #7
              Hi JC,

              I have plots of the trend status variables on the 1, 3 and 9 minute charts. They look good. These are the values that I AND together in the trend agreement indicator applied to the 1 minute chart. This is how I observed the invalid values plotted. It appears there is a "race" condition with my synchronized data. The values are invalid at the time when either or both the 9 minute and 3 minute charts have a bar closure. The plot is good for the 1 minute bar closures.

              I am thinking I should insert a delay inside at the beginning of the BarsInProgress == 0 code. This will give enough time for the other BarsInProgress objects to finish. I should have stable values to AND together in the 1 minute indicator.

              Does this sound OK.

              Steve

              Comment


                #8
                Hello steveobowen,

                That may work. Let us know the results.
                JCNinjaTrader Customer Service

                Comment


                  #9
                  Hello JC,

                  Thanks for the suggestion to use Print statements to trouble shoot my problem. The good news is that I have found the problem. The bad news, it looks like it might be an issue with the NT7 platform.

                  My observation from the prints in the Output Window are the values of my variables, tsTrend_3M and tsTrend_9M get changed to invalid values when BarsInProgress = 0 runs and the time stamp is when either the 3M or 9M bar is about to close or has closed . These variables are not set when BarsInProgress = 0. At this same time stamp when BarsInProgress = 1 or BarsInProgress = 2 run, the variables get set back to their correct value.

                  How do I fix this runtime error?
                  Steve

                  Comment


                    #10
                    Hello steveobowen,

                    Can you send a toy* NinjaScript code replicating the behavior and steps to be able to reproduce this so that I may look into this. You can either Export it as a Source File using the step from our Help Guide at the link below or just send the ".cs" file that is going to be located in the (My) Documents -> NinjaTrader 7 -> bin -> Custom -> Strategy folder.
                    http://www.ninjatrader.com/support/h...tml?export.htm


                    You can send the file and steps to support [at] ninjatrader [dot] com, with the subject line of "ATTN: JC" and in the body "http://www.ninjatrader.com/support/forum/showthread.php?t=52950".

                    Happy to be of further assistance.

                    *Toy - basically a stripped down version of code that isn't necessarily the whole logic; making it easier to identify lines of code.
                    JCNinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by kaywai, Today, 06:26 AM
                    1 response
                    6 views
                    0 likes
                    Last Post kaywai
                    by kaywai
                     
                    Started by ct, 05-07-2023, 12:31 PM
                    6 responses
                    205 views
                    0 likes
                    Last Post wisconsinpat  
                    Started by kevinenergy, 02-17-2023, 12:42 PM
                    118 responses
                    2,780 views
                    1 like
                    Last Post kevinenergy  
                    Started by briansaul, Today, 05:31 AM
                    0 responses
                    10 views
                    0 likes
                    Last Post briansaul  
                    Started by traderqz, Yesterday, 12:06 AM
                    11 responses
                    28 views
                    0 likes
                    Last Post NinjaTrader_Gaby  
                    Working...
                    X