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

Determining which bars are currently on screen

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

    Determining which bars are currently on screen

    Hi guys,

    I'm writing an indicator (NT 8 Beta) which labels the bars with their number, 1 being the first bar of the session.

    I'm using Draw.Text and the indicator works fine - EXCEPT it appears to be consuming too much in the way of resources. Moving the mouse/cursor over a chart becomes very laggy as does performing any manual operation such as scrolling through the chart, using a drawing tool. This is because around 9,000 drawing objects are created (the number of bars in the chart).

    Is there a way of determining which bars are visible on screen so that I could create those drawing objects only on the fly, significantly reducing the number of drawing objects existing at any one time and thus, hopefully, improving performance?

    many thanks

    #2
    Hi trader_rick,

    Thanks for your post.

    One of the improvement over NT7 that we added in NT8 was the ability to see the bars ago and the current bar numbers.

    Please open a "databox" window (Left click on the charts toolbar 6th icon from the left to open the data box). In the databox, right mouse click then select "show bar indexes" and/or "show bars ago". These will add two rows in the databox showing bar index 999 of 9999 and bars ago of 99.
    Paul H.NinjaTrader Customer Service

    Comment


      #3
      Thanks Paul,

      I already played with those features but unfortunately I need the count to reset at the start of the trading session. So the first bar of the day's trading session is always #1 etc.

      However, you've given me an idea. Instead of using Draw.Text, why don't I create an indicator which holds the index number of the current session as its value but doesn't plot anything. Then, I should be able to read the value of the indicator in the Data Box. This should be much more efficient in terms of resources.

      Going to try it now.

      Comment


        #4
        Hi Paul,

        I have the following simple code, but for some reason I can't get it to display even the indicator name in the Data Box. Oddly, if I remove the assignment to Value[0], the indicator's name now appears in the Data Box but obviously no values. Any ideas? Thanks.

        Code:
                protected override void OnBarUpdate()
                {
                    //Reset count at start of each session.
                    if( Bars.IsFirstBarOfSession )
                    {
                        barCount = 0;
                    }
        
                    Value[0] = ++barCount;
                }

        Comment


          #5
          Hello trader_rick,

          Thanks for your post.

          Not sure what to advise as using your code here I see a label and a value in the Databox as well as the mini databox. You might check the "log" tab of the control center for any run time error messages. Are you seeing a plot line? Do you need to scroll down in the databox?

          An alternate code you can use is:

          Value[0] = Bars.BarsSinceNewTradingDay;

          Which will do the same thing: http://ninjatrader.com/support/helpG...tradingday.htm
          Paul H.NinjaTrader Customer Service

          Comment


            #6
            Thanks for the reply Paul.

            In order to show the values in the Data Box, I found out that I needed to add an AddPlot() call, which I didn't do as I don't actually want to see a plot.

            However, there is a problem. In order for the index values to show in the Data Box, the plot needs to be humanly visible in the chart. What I mean by this is that it is pretty meaningless to have a plot of bar index number as this is just a straight rising line, resetting at the start of the trading range. However, if I change the colour of the line to Transparent or set its Visible property to false, the value disappears from the Data Box.

            Any further ideas?

            Thanks

            Comment


              #7
              Hi trader_rick,

              Thanks for your reply.

              Before I forget I need to remind you that we are asking that all NT8 questions be placed in the NT8 beta forum. This is to avoid confusion as all other forums are NT7 related. We can conclude this thread here though.

              You might consider going back to DrawText() but print every 10th bar instead of every bar, that would cut your original resource use by 90%.

              I am probably missing something that you are needing but are you certain that that the databox bars ago and bar index won't meet your needs? The bars ago gives you a value from the right edge and the bars index is from the left side or data start side, I'm not sure what is different between that and drawtext bar numbers. if you are trying to locate something. I guess my assumption is that you are trying to do some diagnostics?
              Paul H.NinjaTrader Customer Service

              Comment


                #8
                Paul,

                I considered posting in the NT8 area - except all I could find were places to download files.
                Please could you give me the link to the correct place to post.

                I need the bar count from the start of the day. Not the start of the data in the chart. I read price action off a 5 minute chart so I'm expecting 81 bars during regular trading hours.

                Also, it seems to me that not showing values in the Data Box for an indicator whose 'colour' is set to Transparent constitutes broken functionality. I could understand if this was the case only if the Visible property was set to false, but why a change of colour?

                regards

                EDIT:
                Also, I need bar numbers to be not too far apart (maximum is 3) so I can rapidly identify bars rather than having to count each time from an index number several bars away. I'm already using a spacing of 2.
                Last edited by trader_rick; 07-18-2016, 02:00 PM.

                Comment


                  #9
                  Hello

                  The correct forum for NT8 in this case would be the "General Discussion" thread: http://ninjatrader.com/support/forum...splay.php?f=59

                  So perhaps an alternative for you would be to use Draw.TextFixed() and tie its input to Bars.BarsSinceNewTradingDay.

                  Regarding the databox I know there has been previous discussions on this and I suspect that the otherside is where someone has a plot set transparent and they don't want to see its value in the databox and they don't want to set invisible because perhaps the indicator has other plots that they do wish to see (Like pivots for example). Does that make sense?
                  Paul H.NinjaTrader Customer Service

                  Comment


                    #10
                    Paul,

                    Thanks for the link.

                    I need to have the index number drawn under the relevant bar otherwise what's the point? Draw.TextFixed plots in pre-defined locations on the chart (corners or centre) so is useless to me.

                    On Transparent removing the display in the databox: I don't buy your argument. If that was your requirement, you could just set the property to not display in the databox.

                    I stand by my assertion that the implementation is illogical. ;-)

                    regards

                    Comment


                      #11
                      Originally posted by trader_rick View Post
                      Paul,

                      Thanks for the link.

                      I need to have the index number drawn under the relevant bar otherwise what's the point? Draw.TextFixed plots in pre-defined locations on the chart (corners or centre) so is useless to me.

                      On Transparent removing the display in the databox: I don't buy your argument. If that was your requirement, you could just set the property to not display in the databox.

                      I stand by my assertion that the implementation is illogical. ;-)

                      regards
                      You want to use Draw.Text() with a tag of Bars.BarsSinceNewTradingDay, or with a counter that is reset at the start of each day. It might also make sense at the start of each day to run a for loop to delete all the text objects.

                      Comment


                        #12
                        Hello trader_rick,

                        Thanks for your reply.

                        Going back to the transparent plot, there is a property that can be set so that you can see the transparent plots value in the databox: ShowTransparentPlotsInDataBox. Here is the helpguide link: http://ninjatrader.com/support/helpG...sindatabox.htm
                        Paul H.NinjaTrader Customer Service

                        Comment


                          #13
                          @Koganam - thanks for your input - but I'm scrolling backwards and forwards through the chart for historical analysis so I always need to know bar numbers, not just for the current trading day.

                          Comment


                            #14
                            Originally posted by NinjaTrader_Paul View Post
                            Hello trader_rick,

                            Thanks for your reply.

                            Going back to the transparent plot, there is a property that can be set so that you can see the transparent plots value in the databox: ShowTransparentPlotsInDataBox. Here is the helpguide link: http://ninjatrader.com/support/helpG...sindatabox.htm
                            That's perfect! Works fine now. Thanks Paul.

                            Comment


                              #15
                              Determining which bars are currently on screen, really.

                              What about the bars that really are displayed at any single time on screen:
                              How can we know the first bar on the left OF THE SCREEN and the Last bar on the right
                              for any given moment ? I mean that's what the original question states and perhaps what other people too are coming to look for here.

                              I appreciate your answers.

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by RookieTrader, Today, 09:37 AM
                              3 responses
                              15 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by kulwinder73, Today, 10:31 AM
                              0 responses
                              8 views
                              0 likes
                              Last Post kulwinder73  
                              Started by terofs, Yesterday, 04:18 PM
                              1 response
                              24 views
                              0 likes
                              Last Post terofs
                              by terofs
                               
                              Started by CommonWhale, Today, 09:55 AM
                              1 response
                              5 views
                              0 likes
                              Last Post NinjaTrader_Erick  
                              Started by Gerik, Today, 09:40 AM
                              2 responses
                              8 views
                              0 likes
                              Last Post Gerik
                              by Gerik
                               
                              Working...
                              X