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 Vietanhnguyen2hotmailcom, 05-03-2024, 10:29 AM
                4 responses
                24 views
                0 likes
                Last Post Vietanhnguyen2hotmailcom  
                Started by PhillT, 04-19-2024, 02:16 PM
                4 responses
                36 views
                0 likes
                Last Post PhillT
                by PhillT
                 
                Started by ageeholdings, 05-01-2024, 05:22 AM
                5 responses
                38 views
                0 likes
                Last Post ageeholdings  
                Started by reynoldsn, Yesterday, 02:34 PM
                0 responses
                14 views
                0 likes
                Last Post reynoldsn  
                Started by nightstalker, Yesterday, 02:05 PM
                0 responses
                25 views
                0 likes
                Last Post nightstalker  
                Working...
                X