Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Sync a DataSeries with a secondary timeframe

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

    Sync a DataSeries with a secondary timeframe

    Hi,
    I am trying to add a second timeframe and sync a new DataSeries with it. So far, no luck.
    I have added the following code:

    protected override void Initialize()
    {
    //Added a secondary timeframe
    Add(PeriodType.Minute, 15);
    myDataSeries = new DataSeries(this);
    }

    protected override void OnBarUpdate()

    myDataSeries.Set(Closes[1][0]);

    Is this conceptually ok??
    because it does not work for me!!
    Thanks!!
    Juan Rivera

    #2
    Not sure I follow. Why would you need this code?
    myDataSeries = new DataSeries(this);

    Please check out the SampleMultiTimeframe strategy and the docs provided: http://www.ninjatrader-support.com/H...struments.html

    Comment


      #3
      Hi,

      Actually I do not know why I need the code
      myDataSeries = new DataSeries(this);

      I added because it said so in the custom indicator examples. I have no idea what it does.

      Apart from that, is it ok to write:

      ¿myDataSeries.Set(Closes[1][0]);?

      Thanks!!

      Juan Rivera

      Comment


        #4
        Please try to compile. If it does, then the code is syntactically correct.

        Comment


          #5
          Hi again,

          If i remove that line, it compiles ok but does not print out myDataSeries to the OUTPUT.

          However, if I keep that line, myDataSeries takes the same values as the Closes[1][0] which I can see in the Output window. So far so good.

          However, if I pass the Closes[1][0] into an indicator like SMA and also pass myDataSeries into the same indicator, the results are totally different!!!!! The output of SMA(myDataSeries, 2)[0] is wrong!!!!

          Any ideas what is happening?

          Thanks!!

          Juan Rivera

          Comment


            #6
            Not sure what you are trying to achieve but if you want to run e.g. a 15 period SMA in the 2nd close series then why not try something like:
            Code:
            Print(SMA(Closes[1], 15)[0]);

            Comment


              #7
              I want to achive a DataSeries that has the same closing values as my secondary timeframe. I am that far already simply by writing:

              myDataSeries.Set(Closes[1][0]);

              Now, myDataSeries and Closes[1][0] have the same values but...
              a 15 period SMA in the 2nd close series and a 15 period SMA in the myDataSeries won´t give the same results. In fact, any indicator using those aparently identical inputs will provide different results...

              Why?

              Aparently, there are both the same array but...

              Comment


                #8
                Please make sure you understand the BarsRequired concept: http://www.ninjatrader-support.com/H...Required1.html

                In addition you always can print out the values of your dataseries and compare it with Close[1].

                Comment


                  #9
                  I print out in two columns Closes[1][0] and myDataSeries, the figures are identical. (see picture attached)

                  However, the calculation of the 5-period EMA using Closes[1][0] and myDataSeries are not...

                  I do not get why...
                  Attached Files

                  Comment


                    #10
                    Please see my post below on BarsRequired: OnBarUpdate is triggered first time CurrentBar=20.

                    Comment


                      #11
                      I have set the number of bar required to 900...

                      i do not get why should that affect the EMA calculations...

                      Both arrays are identical, but the indicator is not...

                      Comment


                        #12
                        Just compare the first 900 data points on both series the first time OnBarUpdate is triggered and you'll see.

                        Comment


                          #13
                          Sorry, I do not get it.

                          The strategy is applied on a 1min bar chart and a 30min bar second timeframe is added.

                          In order to calculate a 5-period SMA of the secondary timeframe, I need at least 150 1min bars...

                          Should I set the number of bars required to 150??

                          Comment


                            #14
                            >> In order to calculate a 5-period SMA of the secondary timeframe
                            Try SMA(Closes[1], 5)[0].

                            Comment


                              #15
                              Well,

                              I give up. I cannot make myself understood.

                              Thanks anyway for your help.

                              /Juan Rivera

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by CarlTrading, 03-31-2026, 09:41 PM
                              1 response
                              57 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by CarlTrading, 04-01-2026, 02:41 AM
                              0 responses
                              30 views
                              0 likes
                              Last Post CarlTrading  
                              Started by CaptainJack, 03-31-2026, 11:44 PM
                              0 responses
                              41 views
                              1 like
                              Last Post CaptainJack  
                              Started by CarlTrading, 03-30-2026, 11:51 AM
                              0 responses
                              58 views
                              0 likes
                              Last Post CarlTrading  
                              Started by CarlTrading, 03-30-2026, 11:48 AM
                              0 responses
                              47 views
                              0 likes
                              Last Post CarlTrading  
                              Working...
                              X