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

Plot0.Set(Close[0]); vs Plot0.Set(Close[1]);

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

    Plot0.Set(Close[0]); vs Plot0.Set(Close[1]);

    I'm very new to Ninjascripting.. encountered a problem in 1 minute of attempting my first script!

    Why does

    Plot0.Set(Close[
    0]);

    plot a line appopriately but

    Plot0.Set(Close[1]);

    plot nothing at all? Shouldn't the latter plot a line tracing the previous close?

    Thanks!

    #2
    Originally posted by amedhussaini View Post
    I'm very new to Ninjascripting.. encountered a problem in 1 minute of attempting my first script!

    Why does

    Plot0.Set(Close[
    0]);

    plot a line appopriately but

    Plot0.Set(Close[1]);

    plot nothing at all? Shouldn't the latter plot a line tracing the previous close?

    Thanks!
    Add the following line:
    if(CurrentBar == 0) return;

    Comment


      #3
      thank you, makes sense. before, it was stuck waiting for the previous bar before drawing everything?

      Comment


        #4
        ACtually, makes me a bit more confused:

        This works:

        if(CurrentBar == 0) return;
        Plot0.Set( Close[1
        ]);

        but now this doesn't work:

        if(CurrentBar == 0) return;
        Plot0.Set( Close[
        2]);

        Comment


          #5
          Originally posted by amedhussaini View Post
          ACtually, makes me a bit more confused:

          This works:

          if(CurrentBar == 0) return;
          Plot0.Set( Close[1
          ]);

          but now this doesn't work:

          if(CurrentBar == 0) return;
          Plot0.Set( Close[
          2]);
          try
          if (CurrentBar < 2) return;

          you have to make sure you have enough bars before referencing them

          Comment


            #6
            i think i get it now..

            whenever i reference a set number of bars in the past, i have to make sure that i stop trying to calculate it if there aren't enough bars left on the chart before i get to bar[0]...

            otherwise it will hang.. and continually wait for a new bar

            Comment


              #7
              Originally posted by amedhussaini View Post
              i think i get it now..

              whenever i reference a set number of bars in the past, i have to make sure that i stop trying to calculate it if there aren't enough bars left on the chart before i get to bar[0]...

              otherwise it will hang.. and continually wait for a new bar
              Calculation starts from the very first bar on your chart (leftmost).
              If the bar is first on chart, you are trying to access the bar before it which does not exist.

              Comment


                #8
                thanks, makes even more sense now that i'm looking at it starting left to right

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by Carolscogginsi, Yesterday, 10:45 PM
                0 responses
                5 views
                0 likes
                Last Post Carolscogginsi  
                Started by RaddiFX, Yesterday, 10:15 AM
                2 responses
                15 views
                0 likes
                Last Post RaddiFX
                by RaddiFX
                 
                Started by patrickmlee007, Yesterday, 09:33 AM
                2 responses
                18 views
                0 likes
                Last Post patrickmlee007  
                Started by magnatauren, 08-15-2020, 02:12 PM
                5 responses
                208 views
                0 likes
                Last Post RaddiFX
                by RaddiFX
                 
                Started by rene69851, 05-02-2024, 03:25 PM
                1 response
                23 views
                0 likes
                Last Post rene69851  
                Working...
                X