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

ChartBars.FromIndex and ChartBars.ToIndex

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

    #16
    Hello frankduc,

    It just doesn't make any sense at all to use ChartBars.FromIndex or ToIndex in OnBarUpdate().
    The from and to index are completely visual. It doesn't make sense to put stuff that is visual based in OnBarUpdate().
    But that said, it will work in OnBarUpdate() as demonstrated in the test script I have provided you and the video.

    What about that print won't work?

    Does the time of the bar not match the chart for that bar number?

    Are you getting an error?

    Is this the only line of code in the script?

    Are you certain that is the line causing the issue?
    Chelsea B.NinjaTrader Customer Service

    Comment


      #17
      I just replaced
      ChartBars.FromIndex
      for 0, after all 0 is the first bar on the left.
      Suddenly everything seems to work.

      Thanks for your patience

      Comment


        #18
        Hello frankduc,

        If the chart is not scrolled all the way to the left, bar 0 will not be the first bar on the left.

        Bar 0 is the first historical bar, not the first visible bar.

        You want the first visible bar wherever the chart has been scrolled, as shown in the video I have provided you, is this correct?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #19
          Chelsea,

          I want my for loop to calculate through all the bars of the chart from index till first bar. It doesn't matter if its visible or not.

          I dont understand why i am unable to Print barIndex or
          sumOfVolumes4. FI and sumOfVolumes4 wont even show up in Output Window. Since i replaced
          ChartBars.FromIndex
          for 0 all my other variables and Close.GetValueAt(CurrentBar) are working fine.


          [CODE]
          for(int barIndex = index; barIndex <= 0; barIndex--)
          {
          sumOfVolumes4 += Bars.GetVolume(barIndex);
          Print("sumOfVolumes4" + barIndex);
          if (sumOfVolumes4 >= sumvolfibo)
          {
          foundIndex = barIndex;


          Print("FI" + barIndex);
          Draw.VerticalLine(this, "tag3", foundIndex, Brushes.Green);
          break;
          }
          }
          [CODE]

          You want the first visible bar wherever the chart has been scrolled, as shown in the video I have provided you, is this correct?
          Yes, than if its not zero what is the right code?

          Comment


            #20
            Hello frankduc,

            If you do not care if they are visible you are using the wrong tools.

            ChartBars.FromIndex is the first VISIBLE bar. Not the first historical bar. This means the first bar in view of the chart. The first bar that is rendered.
            ChartBars.ToIndex is the last VISIBLE bar. Not the last bar.

            If you are not trying to loop through the visible bars only, then do not use ChartBars.FromIndex or ChartsBars.ToIndex.

            Below is a link to the help guide.
            https://ninjatrader.com/support/help..._fromindex.htm
            https://ninjatrader.com/support/help...rs_toindex.htm


            The first bar is bar number 0. (The first historical bar is not ChartBars.FromIndex).
            The last bar is CurrentBar. (The last historical bar is not ChartBars.ToIndex)

            To loop through all bars on the chart:
            Code:
            for (int barIndex = 0; barIndex < CurrentBar; barIndex++)
            {
            Print(Time[CurrentBar - barIndex]);
            }
            or
            Code:
            for (int index = CurrentBar; index >= 0; index--)
            Last edited by NinjaTrader_ChelseaB; 10-30-2019, 02:27 PM.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #21
              Hi,

              Is it possible that the Output window show a Print() that is not actually in the script?
              I erased all Prints in the indicator script and there is still a variable call val and another unknown that Print() data.

              Since my NT crash this morning i had strange behaviour. Can also be link to the fact that i reinstall NT last weekend.

              Thanks

              Comment


                #22
                forget about it
                it seems it was the result print of a previous indicator that was sticking in OW

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by kujista, Today, 06:23 AM
                4 responses
                14 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Started by traderqz, Yesterday, 09:06 AM
                2 responses
                16 views
                0 likes
                Last Post traderqz  
                Started by traderqz, Today, 12:06 AM
                3 responses
                6 views
                0 likes
                Last Post NinjaTrader_Gaby  
                Started by RideMe, 04-07-2024, 04:54 PM
                5 responses
                28 views
                0 likes
                Last Post NinjaTrader_BrandonH  
                Started by f.saeidi, Today, 08:13 AM
                1 response
                8 views
                0 likes
                Last Post NinjaTrader_ChelseaB  
                Working...
                X