• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.


No announcement yet.

Partner 728x90


total number of bars onrender and period

  • Filter
  • Time
  • Show
Clear All
new posts

    total number of bars onrender and period


    I am confuse does substract 631 bars from

    for(int barIndex = (ChartBars.ToIndex) - 631; barIndex <= (ChartBars.ToIndex); barIndex++)

    means barIndex start at bar 631 to currentBar or the opposite ?

    I am trying to get all the bars in the chart from exemple barIndex 631 ------> CurrentBar right side of the chart.

    Now i want to replace 631 by period and set a period in indicators proprieties so i can change the number in the indicator without having to compile every time, is it possible?

    Hello frankduc,

    The ChartBars.ToIndex is the last visible bar on the chart.
    The ChartBars.FromIndex is the first visible on the chart.

    This allows you to only render within the viewable space on the chart with the range of visible bars..

    With ChartBars.ToIndex - 631 this would be a hard coded 631 bars to the left of the last visible bar on the chart. If this was more bars than on the chart, the coordinates may be outside of the chart.

    The 631st bar that is hard coded before the last bar on the chart could be an input public input if you would like.

    Chelsea B.NinjaTrader Customer Service


      Sorry i dont get it.

      Like i said i want
      to get all the bars in the chart from barIndex 631 of 2100 to last bar right side of the chart.

      I want my barindex to represent 1471 bars included between 631 and 2100.

      I dont need the viewable thing.

      Last edited by frankduc; 07-10-2019, 11:42 AM.


        Hello frankduc,

        I'm not certain what you are wanting, but if you would like to render over bars of the chart, the bar indexes would likely need to be the visible bar indexes for rendering..

        But if you are just wanting to trigger actions for certain bar numbers, likely the ChartBars ToIndex or FromIndex wouldn't be needed.
        Chelsea B.NinjaTrader Customer Service


          I want the barIndex to include the bars from 631 to 2100 which is the last bar of the chart (right side of the chart currentbar)

          For exemple this include all the bars between : cursorPointX and

          for(int barIndex = ChartBars.GetBarIdxByX(chartControl, cursorPointX); barIndex <= ChartBars.ToIndex; barIndex++)

          bars 631 begin 300 bars before cursorPointX

          Its simple its the barIndex in the data box 631 of 2100 i want the barIndex to includes bars from 631 to 2100


            Hello frankduc,

            What if bar 631 isn't in view?

            Are you wanting to do things with bars that are not in view?
            Chelsea B.NinjaTrader Customer Service


              That's something that never came to my mind. Are you saying that in
              for(int barIndex = ChartBars.GetBarIdxByX(chartControl, cursorPointX); barIndex <= ChartBars.ToIndex; barIndex++) if the part from cursorPointX is not in view it will not include the bars out of the chart in the for loop?

              You know its ok because i always keep enough bars in the chart to make sure the for loop includes all the bars. If i cant see the bars in the chart how will i be able to make my calculation works. I am building a new cumulative moving average.

              So as long as i got barIndex 631 to 2100 its ok.


                Hello frankduc,

                If you aren't doing rendering stuff, then you probably don't need to worry about the visible bars on the chart.
                Chelsea B.NinjaTrader Customer Service


                  I think you are the one who introduce me to the file

                  Would it be possible to transfer a part of the script and use it to draw a blue dot at a specific position using the same methods?

                  The way i see it i need:

                  private System.Windows.Media.Brush ellipseBrush;
                  private SharpDX.Direct2D1.Brush ellipseBrushDX;

                  ellipseBrush = Brushes.Blue.Clone();


                  SharpDX.Vector2 ellipseVector = clickPoint.ToVector2();
                  newEllipses.Add(new SharpDX.Direct2D1.Ellipse(ellipseVector, 10f, 10f));

                  I suppose the (=) part lead to the positioning of the object but i wonder if its possible to use the x and y to position the dot?



                    Hello frankduc,

                    The MouseXYtoBarTimePriceExample script is generally meant to demonstrate how to translate a mouse click into a time and price. ClickDraw is meant to convert mouse coordinates to drawing coordinates.

                    Are you trying to draw a dot on bar 631? You need to check first that bar 631 is a visible bar on the chart.

                    The RolloverIndications saves a few bar numbers for drawing a lines on them. This may be similar.

                    The NinjaTrader Ecosystem website is for educational and informational purposes only and should not be considered a solicitation to buy or sell a futures contract or make any other type of investment decision. The add-ons listed on this website are not to be considered a recommendation and it is the reader's responsibility to evaluate any product, service, or company. NinjaTrader Ecosystem LLC is not responsible for the accuracy or content of any product, service or company linked to on this website.
                    Chelsea B.NinjaTrader Customer Service


                      Well my variable returns a bar number so it can be 631 or any visible bar on the chart.

                      I am not very competent with c# nor with SharpDX which seems to be a c# thing more than a Ninjatrader component.

                      If i could find something similar that i could copy or easily adapt that would save me learning time. It doesn't have to be a dot it could be an arrow, etc.

                      Its like clickPoint.X = ChartingExtensions.ConvertToHorizontalPixels(e.Get Position(ChartControl as IInputElement).X, ChartControl.PresentationSource);
                      need to be adapt or change for the bar position?

                      I suppose by the


                        Hello frankduc,

                        I don't understand what you are wanting to do.

                        Are you trying to get the mouse position and draw a dot where the mouse is clicked?
                        Chelsea B.NinjaTrader Customer Service



                          Point clickPoint = chartControl.MouseDownPoint;
                          clickPoint.X = ChartingExtensions.ConvertToHorizontalPixels(click Point.X, chartControl.PresentationSource);

                          for(int barIndex = ChartBars.GetBarIdxByX(chartControl, (int)clickPoint.X); barIndex <= ChartBars.ToIndex; barIndex--)
                          sumOfVolumes4 += Bars.GetVolume(barIndex);
                          if (sumOfVolumes4 >= sumvolfibo)
                          foundIndex = barIndex;


                          I want to draw a dot at the position returned by foundIndex

                          foundIndex returns a bar (631 ex). I want my dot on that bar.


                            Hello frankduc,

                            May I confirm that the line rendered on specific bars in the Rollover indications indicator is not demonstrating exactly what you are wanting only with a line instead of a dot?

                            Can you clarify why the code in the Rollover indicator is not a sufficient example?

                            The code you are suggesting at the top is for mouse clicks. If you aren't interested in capturing mouse clicks, then that suggested code is not going to be helpful.
                            Any conditions for choosing which bars have objects rendered on them should be done in OnBarUpdate (just like in the Rollover indications indicator).
                            Then for the chosen bars you can render objects using the bars information if the bar is visible on the chart (which is demonstrated in the Rollover indications indicator)
                            Chelsea B.NinjaTrader Customer Service


                              Its not clear to me what does the
                              Rollover indications indicator.

                              I will need to study that indicator to understand how it can help me, cause right now i dont see how.

                              At first i wanted to draw a vertical line at the spot of the bar. I thought clickdraw would of been easier but looks like i am wrong.

                              My indicator is built onRender. I try to move it to OBU but it ask to much conversion. I wish it was possible to send foundIndex result to OBU to use drawverticalline. But its not possible without rewriting the script in OBU.


                              Latest Posts


                              Topics Statistics Last Post
                              Started by ttodua, Today, 01:12 AM
                              2 responses
                              Last Post ttodua
                              by ttodua
                              Started by kujista, Today, 02:57 PM
                              1 response
                              Last Post NinjaTrader_Kate  
                              Started by henord, Today, 02:40 PM
                              6 responses
                              Last Post NinjaTrader_RyanS  
                              Started by Johnny Santiago, Today, 01:57 PM
                              1 response
                              Last Post NinjaTrader_RyanS  
                              Started by Bigbear57, Today, 01:37 PM
                              1 response
                              Last Post NinjaTrader_RyanS