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

How to use multiple plots in an indicator

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

    How to use multiple plots in an indicator

    Hello,
    I'm trying to add several plots to an indicator in a loop:
    Code:
    protected override void Initialize() {
        ...
        for (int i=0; i<list.Count; i++) {
            Add(new Plot(getColor(i), PlotStyle.Line, "plot"+i));
            Add(new Plot(getColor(i), PlotStyle.Line, "plot"+(i+1)));
        }
        Print("Total Number of plots: " + Plots.Length + ", Values: "+Values.Length);
    }
    Now if my list has a size of 2 it says there are 4 Plots/4 Values in my indicator.
    But if I try to access these I get an array index out of bounds error after the first two:
    Code:
    protected override void OnBarUpdate() {
        ...
        for (int i=0; i<list.Count; i++) {
            Values[i].Set(...);
            Values[i+1].Set(...);
        }
    }
    Can anyone tell me why I cannot access the whole Values/Plots-Array?

    Cody

    #2
    Oh, sorry :-) It seems to work :-) several lines are plotted.

    Now is it possible to add colored labels for each in an upper corner?
    I'd like the labels to display even when scrolling.

    Comment


      #3
      No worries Cody, great you've got it working - you could add labels for example with DrawTextFixed().

      You can also upen up the databox to check the values calc'ed.
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Label Position

        Thanks a lot, Bertrand. That works great :-) the only thing is that if I place the label in the upper left corner, its left half is cut away :-/
        Any idea why?

        I used:
        Code:
        DrawTextFixed("plot"+i, "plot"+i, TextPosition.TopLeft, getColor(i), labelFont, Color.Transparent, Color.Transparent, 1);

        Comment


          #5
          I think you just see multiple DrawTextFixed overlapping, as you create a unqiue one for each Plot by using a unique tag ID.
          BertrandNinjaTrader Customer Service

          Comment


            #6
            You're right, I see my two texts overlapping.. and I can't read the left part of both. It doesn't seem that easy... can I somehow adress a certain pane position, so I can simply draw with an x-/y- offset ?

            Comment


              #7
              Sure, for a custom position you can use the generic DrawText() offering an offset parameter as well.
              BertrandNinjaTrader Customer Service

              Comment


                #8
                Got it ;-)

                Ok thank you Bertrand. Now I managed to draw fixed multi-colored labels with the DrawTextFixed() method. As DrawText() doesn't offer a fixed position, for fixed labels the other one is more useful.

                For all who are interested I post a code snippet how to draw position fixed different colored indicator labels using a man-made offset into the top left of the panel:

                string[] labels = new string[list.Count];
                string labelOffset = "";

                for (int i=0; i < list.Count; i++) {
                labels[i] = labelOffset + list.getLabel(i);
                labelOffset += "\n";

                DrawTextFixed(tagString, labels[i], TextPosition.TopLeft, getColor(i), new Font("Arial", 8), Color.Transparent, Color.Transparent, 1);
                }
                Have a nice day!

                Cody

                Comment


                  #9
                  Great to hear and thanks for sharing the snippet here in our forums - have a good weekend
                  BertrandNinjaTrader Customer Service

                  Comment


                    #10
                    I found this thread looking for a way to create plot in a loop.

                    To take the idea a step further, how could I set the values of the resulting plots with a loop?

                    i.e.

                    How to create a loop of Plot"i".Set statements?

                    Comment


                      #11
                      drmartell, it is not possible to construct a loop that goes through different object names (Plot1, Plot2, Plot3, etc) to change something.

                      However, if these objects were placed into some sort of container, you could possible loop through all objects in the container and do something, like set a plot. Unfortunately this would be unsupported though.

                      Please let us know if you have any other questions.
                      AustinNinjaTrader Customer Service

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by bortz, 11-06-2023, 08:04 AM
                      47 responses
                      1,607 views
                      0 likes
                      Last Post aligator  
                      Started by jaybedreamin, Today, 05:56 PM
                      0 responses
                      9 views
                      0 likes
                      Last Post jaybedreamin  
                      Started by DJ888, 04-16-2024, 06:09 PM
                      6 responses
                      19 views
                      0 likes
                      Last Post DJ888
                      by DJ888
                       
                      Started by Jon17, Today, 04:33 PM
                      0 responses
                      6 views
                      0 likes
                      Last Post Jon17
                      by Jon17
                       
                      Started by Javierw.ok, Today, 04:12 PM
                      0 responses
                      15 views
                      0 likes
                      Last Post Javierw.ok  
                      Working...
                      X