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

BarsAgo by date from a different data series

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

    BarsAgo by date from a different data series

    I want to get the bars ago value at a specific date, however not from my current chart but from a different data series.
    For example, my strategy runs on a 10 range chart and I want to get the barsAgo value at 05-05-18 10:00:00 on a 200 range chart.

    Thanks

    #2
    Hello kiss987,

    Thank you for your note.

    Attached is an example which loops over a secondary series and prints to the output window how many bars ago a defined Datetime variable was, in this case I used 5-4-2018 10AM.

    The sample uses a 1 minute secondary series, however if you were to use a range series you would need consider that range bars may not close exactly at a time of say 10AM. What you might do is write an if statement which checks if the bar time was between X time and Y time, rather exactly a specified time. This custom if statement would go on line 68 of the sample.

    Please let us know if you need further assistance.
    Attached Files
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Thank you for your reply.

      Although I did understand your solution, I still have a question.
      In the link below, a different approach is used to get the barAgo value (when using a single data series). Is there a way to somehow use the same approach with a multi data series?

      https://ninjatrader.com/support/help...us/?getbar.htm

      Comment


        #4
        Hello kiss987,

        To force the Bars.GetBar method to use the secondary bar series you could use the following if statement,

        if(BarsInProgress==1)
        {
        int barsAgo = CurrentBar - Bars.GetBar(new DateTime(2006, 12, 18, 9, 0, 0));
        }

        Please let us know if you need further assistance.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Hi,

          Is there an easy way of calculating the bar (BarsAgo) in the main data series having its DateTime, but while beeing in a secondary data series???

          My problem is: I want to draw text in all the charts (isGlobal = true), but this is only possible indicating BarsAgo (not DateTime).
          I have to indicate the BarsAgo from the main data series, not the BarsAgo in the secondary data series, but the calculation if I have to show the text or not will be done in the secondary data series.

          So:
          I calculate in DS 1 (or 2, 3, etc) using Bars in 1, but to draw I need the Bars in 0.

          Comment


            #6
            Hello artson,

            Thanks for your note.

            The method in post # 4 could be used to get the barsAgo value of a secondary series.

            Bars.GetBar(): https://ninjatrader.com/support/help...nt8/getbar.htm

            Or, you could consider saving the CurrentBar value to a variable when the condition becomes true. Then, subtract that variable value from the CurrentBar to get the number of bars ago the condition occurred. That value could then be used for the 'barsAgo' parameter when calling Draw.Text().

            See the help guide documentation below for more information.

            CurrentBar: https://ninjatrader.com/support/help...currentbar.htm
            Draw.Text(): https://ninjatrader.com/support/help.../draw_text.htm

            Let me know if I may assist further.
            Brandon H.NinjaTrader Customer Service

            Comment


              #7
              Thanks Brandon,

              The problem is, when drawing, as far as I know, I allways draw in the Main data series (0).

              For example: if my first (main) data series is 5 min, and my secondary is 15 minutes, when I calculate in DS 2 (data series 2) and I want to write a text at 3 bars ago, when I write it on the main DS (0), I should write it 9 bars ago (because 1 bar from DS2 equals 3 bars from DS0).

              Comment


                #8
                Hello artson,

                Thanks for your note.

                Drawing objects are only able to be drawn into the panel owned by the script (primary series), or the price panel.

                You would not be able to draw the object in the secondary series. Added secondary series are not synchronized to Chart Bars.

                You could consider drawing the object on the primary series in a separate panel, or you could draw the object on the price panel of the primary series.​

                I cannot see any way this could be accomplished from the secondary series in relation to the primary as the series may not be identical intervals or time. 10 bars ago to the primary may mean a completely different point in the chart from the secondary series.​

                Let me know if I may assist further.
                Brandon H.NinjaTrader Customer Service

                Comment


                  #9
                  Well, this is the point.

                  I do the calculations in the secondary series.
                  Throug DateTime it is possible to draw correctly into the primary.
                  For most of the things I draw, it is enough, but if you look at Draw.Text, there is not the possibility to draw a "global" text using DateTime, it is only using BarsAgo.
                  With lines it is possible.

                  If it is not possible (or authomatic) to find, from a secondary Data Series, the equivalent BarAgo in the primary, then at least, maybe you could add to the "Draw.Text" more options for using DateTime....


                  Thanks!!!

                  Comment


                    #10
                    Hello artson,

                    Thanks for your note.

                    We are tracking interest for this in an internal feature request ticket and I have added your vote. This request is being tracked under the number SFT-4347.

                    As with all feature requests, interest is tracked before implementation is considered, so we cannot offer an ETA or promise of fulfillment. If implemented, it will be noted in the Release Notes page of the Help Guide.

                    Release Notes — https://ninjatrader.com/support/help...ease_notes.htm

                    Please let us know if we may be of further assistance to you.​
                    Brandon H.NinjaTrader Customer Service

                    Comment

                    Latest Posts

                    Collapse

                    Topics Statistics Last Post
                    Started by DJ888, 04-16-2024, 06:09 PM
                    4 responses
                    12 views
                    0 likes
                    Last Post DJ888
                    by DJ888
                     
                    Started by terofs, Today, 04:18 PM
                    0 responses
                    7 views
                    0 likes
                    Last Post terofs
                    by terofs
                     
                    Started by nandhumca, Today, 03:41 PM
                    0 responses
                    6 views
                    0 likes
                    Last Post nandhumca  
                    Started by The_Sec, Today, 03:37 PM
                    0 responses
                    3 views
                    0 likes
                    Last Post The_Sec
                    by The_Sec
                     
                    Started by GwFutures1988, Today, 02:48 PM
                    1 response
                    9 views
                    0 likes
                    Last Post NinjaTrader_Clayton  
                    Working...
                    X