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

Bar data to dataseries

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

    Bar data to dataseries

    Hello Support,

    I need to calculate ninja indicators i.e ema, sma etc on data of different instruments outside the main indicator class. I have populated bar series for each instrument using GetBar method. Following is the piece of code that I am using to get data bars:

    Code:
    Bars newBars = Data.Bars.GetBars(Cbi.Instrument.GetObject(instrument), new Period(PeriodType.Minute, period, MarketDataType.Last), startTime, endTime, Data.Bars.GetSession(Cbi.Instrument.GetObject(instrument), session), Data.Bars.SplitAdjust, Data.Bars.DividendAdjust);
    My question is how can we compute open, close, high, low dataseries from these bars so that I can use them to generate indicator values? Or is there any way we can directly pass data bars to indicators to compute results?

    Thanks,
    Last edited by Wajeeha; 03-13-2014, 04:40 AM.

    #2
    Hello Wejeena,

    Thank you for your post.

    You should be able to get the price series using the properties for the object.

    newBars.Close

    However, I do believe this method of adding a bars object will not be synced with the primary data series.
    Cal H.NinjaTrader Customer Service

    Comment


      #3
      Bar data to dataseries

      Thank you for your reply.

      I would have done that but I didn't find any such property in intellisense. I also tried this and got following error

      'NinjaTrader.Data.Bars' does not contain a definition for 'Close' and no extension method 'Close' accepting a first argument of type 'NinjaTrader.Data.Bars' could be found (are you missing a using directive or an assembly reference?)
      Please advise.

      Thanks,
      Last edited by Wajeeha; 03-13-2014, 04:41 AM.

      Comment


        #4
        Hello Cal,

        Thank you for your support.

        Just to explain what Wajeeha is looking for, the need here is to be able to calculate indicator values based on the data we get through the GetBars method. We want to be able to run the indicator for different instruments on different time frames which are not added to the indicator code in the initialize method.

        Please shed some light on this.

        Regards
        Umer

        Comment


          #5
          I have attached a .zip that should outline what you are looking to do.

          You will need to download and import this into NinjaTrader
          To Import

          * Download the indicator to your desktop, keep them in the compressed .zip file.
          * From the Control Center window select the menu File> Utilities> Import NinjaScript
          * Select the downloaded .zip file
          * NinjaTrader will then confirm if the import has been successful.


          Critical - Specifically for some indicators, it will prompt that you are running newer versions of @SMA, @EMA, etc. and ask if you want to replace, press 'No'
          Attached Files
          Cal H.NinjaTrader Customer Service

          Comment


            #6
            The code that you have provided will only provide us with the Close (or high, open, low) of a bar at the index we provide. How is that supposed to help us get the indicator values for that BarSeries?

            Please review our problem statement:

            Originally posted by Master.Aurora View Post
            Just to explain what Wajeeha is looking for, the need here is to be able to calculate indicator values based on the data we get through the GetBars method. We want to be able to run the indicator for different instruments on different time frames which are not added to the indicator code in the initialize method.
            And let us know if this is possible and if so how to go about accomplishing this. If not, please do not provide half cooked answers.

            Hoping to get a positive response.

            Regards
            Umer

            Comment


              #7
              Master,

              Yes, this is possible but out of scope for support.

              However, since the GetBars method is asynchronous in loading the data you would need to build an outside method that would help sync this up with the primary series. You could then use this Bars object to pass through an Indicator such as SMA(newBars, 14)

              An example of how this is done would be with the Pivots Indicator under the miscellaneous portion.

              I want to stress that this is just an example how this can be accomplished. I don't have any documentation on how to do this as a basic sample.
              Cal H.NinjaTrader Customer Service

              Comment


                #8
                Cal,

                We appreciate your support so far.

                I have tried you suggested method but retrieving indicators value using this is giving following exception:

                Exception = System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
                Parameter name: index
                at System.Collections.ArrayList.get_Item(Int32 index)
                at NinjaTrader.Data.DataSeries.get_Item(Int32 barsAgo)
                at NinjaTrader.Indicator.IndicatorBase.get_Item(Int32 barsAgo)
                at NinjaTrader.Indicator.Test1.OnBarUpdate() in c:\Users\Wajeeha\Documents\NinjaTrader 7\bin\Custom\Indicator\Test1.cs:line 49
                I am attaching an indicator with piece of code from our indicator which reproduces the approve issue.

                Thanks,
                Wajeeha
                Attached Files

                Comment


                  #9
                  Wajeeha,

                  This is because the Bars Object that you are creating doesn't add to the BarsArray nor does it load synchronously with the primary instrument.

                  My previous post (#7) explains this and what needs to happen.
                  Cal H.NinjaTrader Customer Service

                  Comment


                    #10
                    Hello Cal,

                    This is because the Bars Object that you are creating doesn't add to the BarsArray nor does it load synchronously with the primary instrument.
                    In our application, It is not possible for us to subscribe each bar though Add bar method and that is why we are not adding bar to bars array. I looked into Pivot indicator and I believe you are referring to following line for sync

                    Code:
                    Cbi.Globals.SynchronizeInvoke.AsyncInvoke(new System.Windows.Forms.MethodInvoker(InvalidateNow), null);
                    I tried it as well but problem remained same. I have attached my code for synchronization.

                    Please advise.

                    Thanks,
                    Wajeeha
                    Attached Files

                    Comment


                      #11
                      Hi support,

                      We didn't get any reply after our last message. Just to remind:
                      In our Ninja script we are using GetBar method to load instrument data and it is not possible for us to subscribe all the required instrument through Add method in initialize method. We need method to get indicator value on these bar series outside as well as inside the main indicator class. We have tried all your suggestions so far but weren't been able to get indicator value by any of them. Currently we are facing following exception with your last suggested method:
                      Default Exception = System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
                      Parameter name: index
                      at System.Collections.ArrayList.get_Item(Int32 index)
                      at NinjaTrader.Data.DataSeries.get_Item(Int32 barsAgo)
                      at NinjaTrader.Indicator.IndicatorBase.get_Item(Int32 barsAgo)
                      I have attached the code that I used. Let me know if I am making any mistake in implementing or understanding your point.

                      Hoping to get a positive response.

                      Thanks,
                      Wajeeha
                      Attached Files

                      Comment


                        #12
                        Wajeeha,

                        As I stated before I don't have any documentation on the subject except for what the Pivots Indicator does.

                        You will need to work through this and debug the script as you go along.
                        Cal H.NinjaTrader Customer Service

                        Comment


                          #13
                          Ok, i struggled with out of range exception for quite a while. This error used to appear in trace logs.

                          To resolve this, i created multiple strategies in strategies tab instead of one strategy that adds 20+ instruments.
                          And then i write the output to multiple text files from these strategies.
                          Then i read all the data via a single strategy from all the different text files.

                          In effect, all this is doing is equivalent to adding multiple instruments to a single strategy. Hope this helps.

                          Comment

                          Latest Posts

                          Collapse

                          Topics Statistics Last Post
                          Started by Rapine Heihei, 04-23-2024, 07:51 PM
                          2 responses
                          30 views
                          0 likes
                          Last Post Max238
                          by Max238
                           
                          Started by Shansen, 08-30-2019, 10:18 PM
                          24 responses
                          943 views
                          0 likes
                          Last Post spwizard  
                          Started by Max238, Today, 01:28 AM
                          0 responses
                          9 views
                          0 likes
                          Last Post Max238
                          by Max238
                           
                          Started by rocketman7, Today, 01:00 AM
                          0 responses
                          5 views
                          0 likes
                          Last Post rocketman7  
                          Started by wzgy0920, 04-20-2024, 06:09 PM
                          2 responses
                          28 views
                          0 likes
                          Last Post wzgy0920  
                          Working...
                          X