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

Indicator that calculate in different chartime

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

    Indicator that calculate in different chartime

    Hello,

    I want to create an indicator that show data in a chart but calculate in other charttime different to the time of the chart where is showed.

    For example: Show an indicator lines in a 5 minute chart, but calculate and show the results for 30 minutes charttime


    I coded it in NT7 as:

    (In the Initialize function...)

    Code:
    Add(PeriodType.Minute, 30);
    but doesnt work in last NT7 versions... why?


    Now, I want to code it in NT8. Who could I do it?

    Thank you.




    Last edited by ninjo; 01-27-2019, 12:44 PM.

    #2
    Hello ninjo,

    NinjaTrader 8 uses AddDataSeries().

    Below is a link to the help guide.


    Also below is a link to the reference sample on intra-bar granularity that uses AddDataSeries().


    As well as a link to the code breaking changes where you can search for a method or property that was documented for NinjaTrader 7 to find the NinjaTrader 8 equivalent in the filter results section.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Thank you ChelseaB.

      I programmed and indicator fro NT 7 in 2015 that shows drwas of other charttime in the principal chart. From las 7.0.1000.39 (or earlier,I am not sure) NT 7 version doesnt work correctly.

      Whats happended? Could you restore it in the next update please?




      Last edited by ninjo; 02-11-2019, 05:52 AM.

      Comment


        #4
        Maybe could I download a previous version of NT 7 where it works.
        Have you a website with a historical NT 7 versions links to download ?
        The Setup.exe only install the last NT 7 Version....

        Thank you

        Comment


          #5
          Hello, *ninjo*.
          When You say "but doesnt work in last NT7 versions" - what exactly do You mean?
          Did indicator plot just anything on the chart?
          Do You see any error messages in Output Window or Log tab of control center?
          fx.practic
          NinjaTrader Ecosystem Vendor - fx.practic

          Comment


            #6
            Hello fx.practic,

            My indicator consists in showing some graphical indications based on a time variable sent.
            I declared the next code in Initialize() function for it

            Code:
             Add(PeriodType.Minute, myChartTimeVar);
            Everything worked correctly until I installed the 7.0.1000.39 NT7 update. Neither does it work in the last 7.0.1000.40 NT7 update

            I do not remember which was the last one that worked correctly ... maybe 7.0.1000.37 ? I dont kwno.
            I dont modified the code of my indicator.

            I would like to have a list of release.exes to test which of them works

            Here the release notes. But not the software link....
            https://ninjatrader.com/support/help...ease_notes.htm


            I am not sure, but maybe the problem occurred when fixing this


            NinjaTrader Version 7.0.1000.38 Production Release - March 7, 2018
            Fixed 5080 Indicators Removed 'Plot current value only' from CurrentDayOHL as it is a duplicate function of changing the plots to Horizontal lines

            Thank you
            Last edited by ninjo; 02-11-2019, 08:32 AM.

            Comment


              #7
              Hello ninjo,

              Is there an error message we can assist with resolving?

              Please write an email to platformsupport [at] ninjatrader [dot] com. I can provide you with the installer for 7.0.1000.32 for testing purposes. However, I this would only be for testing to find what has changed in NinjaTrader and would not be to supply you with an unsupported version for use.

              In the email please include a link to this forum thread.
              Chelsea B.NinjaTrader Customer Service

              Comment


                #8
                Its ok ChelseaB. I sent it.

                If you send a list of releases .exes I cant try from the 38 to 32 and find what was the last where works correctly.

                Thank you

                Comment


                  #9
                  Hi ChelseaB. I solved the problem with the NT 7 indicator. Now works correclty. Thak you for your excellent support.


                  Now, I want to use two instances of the EMA indicator with differents times calculations in the same chart.

                  For ex. If the principal time of the chart is 5 minutes, I want to show the 5 EMA calculation, and the 60 chart EMA calculation but in the same 5 minute chart.


                  Could you help me please?

                  Thank you.!


                  Comment


                    #10
                    Hello ninjo,

                    You can do this manually on the chart by adding a series in the Data Series window and using this for the input series of the indicator.


                    Or in code, you can do this by adding a series and supplying the series as the input series parameter to the indicator call.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Hi ChelseaB

                      I am trying and works correctly when I call SMA, EMA, VOL, and others NT indicators, but doesnt work when i call my own indicator and I cant discover my error.

                      The output window launch this message:

                      "Error on calling 'OnBarUpdate' method on bar 1117: Index was outside the bounds of the array."



                      Please, could you help me to understand and solve it?

                      Thank you
                      Last edited by ninjo; 02-18-2019, 05:18 AM.

                      Comment


                        #12
                        Hello ninjo,

                        With the error:
                        "Error on calling 'OnBarUpdate' method on bar 0: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart"

                        This message indicates an invalid index was used.
                        Indexes are the values between brackets '[index]' that are selecting a specific element from a collection.
                        For any index used, the index must be less than the size of the collection.
                        With BarsAgo values, CurrentBar is the size of the collection.

                        As one example, calling Close[1] when CurrentBar is 0 (the very first bar) will cause this error.
                        The reason for this is because there will not be a bar ago; essentially there is not enough data at bar 0 look back one bar.
                        The script will start from the far left of the chart at the very beginning where the CurrentBar will equal 0 and then start working to the right, calling each bar for OnBarUpdate().

                        In this specific example, it would be needed to wait for the second bar to be built, to ensure that you have enough data to call a index 1 bar ago.
                        Code:
                        // CurrentBar is the first bar, bar 0, and there are not at least 2 bars.
                        // Return to prevent index errors when using a barsAgo index of 1
                        if (CurrentBar < 1)
                            return;
                        This is especially important when multiple series are added to a single script as the data for all series may not start at the same time. Each series will need a check that CurrentBars[series index] is greater than the largest barsAgo index used.
                        Code:
                        // add a series that becomes BarsArray[1], BarsInProgress 1, CurrentBars[1], Closes[1], etc
                        AddDataSeries(null, BarsPeriodType.Minute, 1);
                        Code:
                        // neither the primary series or added 1 minute series have at least 2 bars.
                        if (CurrentBars[0] < 1 || CurrentBars[1] < 1)
                            return;
                        Below is a link to the help guide on this specific example of an indexing error.
                        https://ninjatrader.com/support/help...nough_bars.htm

                        Also, below are links to the help guide on CurrentBar and CurrentBars.



                        Indexing errors can also occur when using an invalid index with arrays, collections and with method calls that uses indexes such <string>.Subtring() which uses a string position index, <string>.Format() which uses indexes for format items in the string (placeholders {0}), and Draw methods which use barsAgo indexes.

                        Below are public links to 3rd party educational sites on arrays and index out of range errors.
                        Create and loop over a string array. Access array Length and get elements at indexes.


                        To identify the invalid index, I highly recommend printing the time of the bar, the index being used, and the size of the collection.
                        For a Series barsAgo value, CurrentBar is the size of the collection.
                        For an array or collection, the .Length or .Count() is the size of the collection.

                        What is the exact line of code generating the error?
                        Last edited by NinjaTrader_ChelseaB; 02-02-2023, 10:17 AM.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Yes I understand.
                          I am coding this in both indicators, but the error still..


                          Code:
                          protected override void OnBarUpdate()
                          {
                                  if(CurrentBar < Count-2 ) return;
                          
                          ....}

                          The error line is 1117... but my script only have 176 lines )

                          EDITED: Excused me, the error is in 1117 bar. I am goin to look for

                          Comment


                            #14
                            Hello ninjo,

                            The code you have provided is not the causing the error.

                            If you comment out all other logic in OnBarUpdate except for that one line, does the error still occur?

                            Are you using prints to figure out which line of code has the error?

                            As in, adding prints on every other line to see which print is the last to print before the error occurs?
                            Chelsea B.NinjaTrader Customer Service

                            Comment


                              #15
                              Hi ChelseaB,
                              I attached a simple code in a .cs

                              For example I want to show in my chart, the value of the VOL indicator


                              It returned: "Indicator 'ExampleAddSeries': Error on calling 'OnBarUpdate' method on bar 1952: Index was outside the bounds of the array."
                              Attached Files
                              Last edited by ninjo; 02-19-2019, 10:10 AM.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by jclose, Today, 09:37 PM
                              0 responses
                              5 views
                              0 likes
                              Last Post jclose
                              by jclose
                               
                              Started by WeyldFalcon, 08-07-2020, 06:13 AM
                              10 responses
                              1,414 views
                              0 likes
                              Last Post Traderontheroad  
                              Started by firefoxforum12, Today, 08:53 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post firefoxforum12  
                              Started by stafe, Today, 08:34 PM
                              0 responses
                              11 views
                              0 likes
                              Last Post stafe
                              by stafe
                               
                              Started by sastrades, 01-31-2024, 10:19 PM
                              11 responses
                              169 views
                              0 likes
                              Last Post NinjaTrader_Manfred  
                              Working...
                              X