• 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.

Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Indicator plot width to match Chart Bar width?

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

    Indicator plot width to match Chart Bar width?

    Hi, Could it be possible to modify this code foreach plotstyle.bar, instead of all plots?

    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
    {
    base.OnRender(chartControl, chartScale);

    foreach (Plot plot in Plots)
    {
    // make the plots width match the chart style bar width
    plot.Width = (float) chartControl.GetBarPaintWidth(ChartBars);
    }
    }

    Also, could it also be possible to //make the plots width match the chart style bar width + the chart style bar spacing?

    Thanks,
    Woody

    #2
    Hello Woody,

    I'd like to clarify what you are trying to do.

    You are wanting to change the width of a plot every time a render pass happens. (this would be very very frequently)

    Are you wanting to set the width of a plot once for the entire plot?
    (Do this in OnStateChange when State == State.DataLoaded)

    You can find the PlotStyle of a plot with Plot.PlotStyle..

    if (Plots[0].PlotStyle == PlotStyle.Bar)
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Chelsea, Thanks for the quick response!

      Yes, I would like it to match the ChartBar width OnRender. I want my bar plot width to change in size as I change my ChartBar size by way of hotkey, and or stretching the y axis. So my code works for that. My question is, how can i only include bar style plots and not line plots in my OnRender code.

      protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
      {
      base.OnRender(chartControl, chartScale);

      foreach (Plot plot in Plots)
      {
      // make the plots width match the chart style bar width
      plot.Width = (float) chartControl.GetBarPaintWidth(ChartBars);
      }
      }

      Also, is there a way to also add the ChartBar spacing? Then my bar plot width will match the ChartBars width and spacing.
      Thanks much, Woody

      Comment


        #4
        Hello woodyfox,

        Is the if statement I suggested not working as expected?

        Are line plots still triggering this as true when you tested it?

        The ChartControl.BarWidth contains the bar width.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_ChelseaB View Post
          Hello woodyfox,

          Is the if statement I suggested not working as expected?

          Are line plots still triggering this as true when you tested it?

          The ChartControl.BarWidth contains the bar width.
          Hi Chelsea,

          I must be misunderstanding? If I have three plots (2 bar and 1 line) and I
          use your if statement of: if(Plots[0].PlotStyle == PlotStyle.Bar)

          protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
          {
          base.OnRender(chartControl, chartScale);

          foreach (Plot plot in Plots)

          if (Plots[0].PlotStyle == PlotStyle.Bar)
          {
          // make the plots width match the chart style bar width
          plot.Width = (float) chartControl.GetBarPaintWidth(ChartBars);
          }
          }
          If the statement is true it will Render all plot widths (including the line plot).
          If the statement is false, No plots will Render. I'm trying to exclude the line plot?

          As for the The ChartControl.BarWidth contains the bar width. Thats already in my
          Code. My second question was:
          Also, is there a way to also add the ChartBar spacing? Then my bar plot width will match the ChartBars width and spacing.
          Thanks much, Woody

          Comment


            #6
            Hello woodyfox,

            Just to clarify, the code should be changing the width of a plot but should not be preventing the plot from appearing at all.

            I would expect that if the condition evaluates as true, then that plot would have the width changed.
            I would not expect that if the condition evaluates as false and nothing happens in OnRender() that the plots would not appear at all.

            Do you have any error messages in the Log tab of the Control Center?

            What is the width value when this is called?

            As a heads up, you are only checking that the first plot (with index [0]) is a bar. You are not checking each plot by index, you are only comparing the first plot..


            NT8 can provide the calculated spacing with ChartControl.Properties.BarDistance. Below is a publicly available link to the help guide.
            https://ninjatrader.com/support/help...properties.htm
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by NinjaTrader_ChelseaB View Post
              Hello woodyfox,

              Just to clarify, the code should be changing the width of a plot but should not be preventing the plot from appearing at all.

              I would expect that if the condition evaluates as true, then that plot would have the width changed.
              I would not expect that if the condition evaluates as false and nothing happens in OnRender() that the plots would not appear at all.

              Do you have any error messages in the Log tab of the Control Center?

              What is the width value when this is called?

              As a heads up, you are only checking that the first plot (with index [0]) is a bar. You are not checking each plot by index, you are only comparing the first plot..


              NT8 can provide the calculated spacing with ChartControl.Properties.BarDistance. Below is a publicly available link to the help guide.
              https://ninjatrader.com/support/help...properties.htm
              Chelsea,
              Sorry, Let me clarify.
              A False statement dose not keep anything from plotting, it simple keeps all plot width's from matching my ChartBar width. Or the reverse for a true statement (All plots will match ChartBar width).
              I'm just trying to keep my line style plots from matching my ChartBar width, and allowing the Bar style plots to match the ChartBars using the following
              code:

              protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
              {
              base.OnRender(chartControl, chartScale);

              foreach (Plot plot in Plots)

              {
              // make the plots width match the chart style bar width
              plot.Width = (float) chartControl.GetBarPaintWidth(ChartBars);
              }
              }

              I think the problem is with the foreach (Plot plot in Plots) part of my code?

              I'm not sure how adding your if statement solves my problem?

              Comment


                #8
                Hello woodyfox,

                I'm not clear on the actual issue.

                When you mention "it simple keeps all plot width's from matching my ChartBar width", are you saying that when the first plot is a bar plot, that all of the plots are not set to width?

                First, you are only checking to see if the first plot is a bar plot. If it is, then all of the plots will be set to the width.

                Are you wanting to check each plot individually? If so, instead of using the 0 index, use the index of that plot.
                Chelsea B.NinjaTrader Customer Service

                Comment


                  #9
                  Chelsea,
                  Thanks for pointing me to the chartControl BarDistance Property, it worked nicely for setting the plot width to match the Chart bars width plus its spacing.

                  I'm still confused on how to isolate a plotStyle.line from Rendering with the code below, while using a true false statement?

                  protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
                  {
                  base.OnRender(chartControl, chartScale);

                  foreach (Plot plot in Plots)

                  {
                  // make the plots width match the chart style bar width
                  Bar.Width = (float) (chartControl.Properties.BarDistance);
                  }
                  }

                  I do appreciate your efforts, I just simple don't understand?
                  Thanks, Woody.

                  Comment


                    #10
                    Hello Woody,

                    Are you understanding that as plots are added to the Plots collection that this adds an element and an index to the Plots collection?

                    The first plot added to Plots is Plots[0]. The second added plots is Plots[1]. The third added plot is Plots[2]

                    You would compare the plot's PlotStyle to see if it is PlotStyle.Bar.

                    You can do this by checking each index individually. Or you can loop through the Plots collection and compare the current elements PlotStyle.
                    Chelsea B.NinjaTrader Customer Service

                    Comment


                      #11
                      Originally posted by NinjaTrader_ChelseaB View Post
                      Hello Woody,

                      Are you understanding that as plots are added to the Plots collection that this adds an element and an index to the Plots collection?

                      The first plot added to Plots is Plots[0]. The second added plots is Plots[1]. The third added plot is Plots[2]

                      You would compare the plot's PlotStyle to see if it is PlotStyle.Bar.

                      You can do this by checking each index individually. Or you can loop through the Plots collection and compare the current elements PlotStyle.
                      Yes, I understand that each plot has and index in order of how it was added. So in the code below I have 3 plots Plots[0], Plots[1], Plots[2].

                      AddPlot(new Stroke(Brushes.MediumSlateBlue, 1), PlotStyle.Line, "Avg TV");
                      AddPlot(new Stroke(Brushes.Gray, 1), PlotStyle.Bar, "Avg BV");
                      AddPlot(new Stroke(Brushes.Silver, 1), PlotStyle.Bar, "Avg SV");
                      }
                      else if (State == State.Configure)
                      {

                      protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
                      {
                      base.OnRender(chartControl, chartScale);

                      foreach (Plot plot in Plots)
                      if(Plots[0].PlotStyle == PlotStyle.Bar)
                      {
                      // make the plots width match the chart style bar width
                      plot.Width = (float) (chartControl.GetBarPaintWidth(ChartBars));
                      }
                      }

                      So... in the Code above, since the statement if(Plots[0].PlotStyle == PlotStyle.Bar) is false. All three plots are not Renderd.
                      If I replace the statement with if(Plots[0].PlotStyle == PlotStyle.line), the statement becomes true and all three plots are Rendered.
                      I'm still not sure how to isolate Plots[0] which is a PlotSyle.line?
                      Thanks, Woody.

                      Comment


                        #12
                        Hello Woody,

                        I'm slightly confused.

                        Previously I mentioned in post #6 that the plots should still be rendered.

                        Are you reporting now that they are not being rendered at all?

                        If so, the script is probably hitting an error.

                        Are there any errors in the Log tab of the Control Center?


                        Plots[0] is only the first plot.

                        To check that the second plot is a bar plot you could use
                        if (Plots[1].PlotStyle == PlotStyle.Bar)

                        To check that the third plot is a bar plot you could use
                        if (Plots[2].PlotStyle == PlotStyle.Bar)


                        Or you can use just the plot object from your loop..

                        In other words, change your condition so that its not just comparing the first plot and instead compares each element in the Plots collection one by one. This means you need the index of that plot, or you need to use the plot object from your for loop.
                        Last edited by NinjaTrader_ChelseaB; 12-27-2017, 12:12 PM.
                        Chelsea B.NinjaTrader Customer Service

                        Comment


                          #13
                          Originally posted by NinjaTrader_ChelseaB View Post
                          Hello Woody,

                          Plots[0] is only the first plot.

                          To check that the second plot is a bar plot you could use
                          if (Plots[1].PlotStyle == PlotStyle.Bar)

                          To check that the third plot is a bar plot you could use
                          if (Plots[2].PlotStyle == PlotStyle.Bar)


                          Or you can use just the plot object from your loop..

                          In other words, change your condition so that its not just checking the first plot and instead checks each element in the Plots collection.
                          OK, I did this:

                          AddPlot(new Stroke(Brushes.MediumSlateBlue, 1), PlotStyle.Line, "Avg TV");
                          AddPlot(new Stroke(Brushes.Gray, 1), PlotStyle.Bar, "Avg BV");
                          AddPlot(new Stroke(Brushes.Silver, 1), PlotStyle.Bar, "Avg SV");
                          }
                          else if (State == State.Configure)
                          {

                          protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
                          {
                          base.OnRender(chartControl, chartScale);

                          foreach (Plot plot in Plots)
                          if(Plots[0].PlotStyle == PlotStyle.Bar && Plots[1].PlotStyle == PlotStyle.Bar && Plots[2].PlotStyle == PlotStyle.Bar)
                          {
                          // make the plots width match the chart style bar width
                          plot.Width = (float) (chartControl.GetBarPaintWidth(ChartBars));
                          }
                          }
                          The statement becomes false, because Plot[0] is a PlotStyle.Line and no Plots are Rendered.
                          Does foreach (Plot plot in Plots) need to be changed?
                          Just not getting it?
                          Thanks,

                          Comment


                            #14
                            Try this, not tested:

                            if(Plots[0].PlotStyle == PlotStyle.Bar)
                            Plots[0].Width = (float) (chartControl.GetBarPaintWidth(ChartBars));

                            This will only change the plot you want. Do not cycle through all plots with the foreach loop.
                            eDanny
                            NinjaTrader Ecosystem Vendor - Integrity Traders

                            Comment


                              #15
                              Hello Woody,

                              Your new code requires that all 3 plots be bar plots before any of these will be changed.

                              Code:
                              if(Plots[0].PlotStyle == PlotStyle.Bar && Plots[1].PlotStyle == PlotStyle.Bar && Plots[2].PlotStyle == PlotStyle.Bar)
                              Are you wanting to require all 3 plots to be bar plots before any of the plots width can be changed?

                              This is not looking at each element individually, instead, this is comparing 3 plots all at the same time and using && to require that all 3 have to be true at the same time.

                              I would recommend that you loop and use the plot object that you have created in your loop.

                              Code:
                              foreach (Plot plot in Plots)
                              {
                              Print(plot.PlotStyle.ToString());
                              }
                              Chelsea B.NinjaTrader Customer Service

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Erwin Beckers, Today, 01:23 AM
                              0 responses
                              2 views
                              0 likes
                              Last Post Erwin Beckers  
                              Started by Mark Taylor, Yesterday, 11:36 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post Mark Taylor  
                              Started by Bluebeep, Yesterday, 08:38 PM
                              0 responses
                              10 views
                              0 likes
                              Last Post Bluebeep  
                              Started by stokhastic, Yesterday, 07:08 PM
                              0 responses
                              3 views
                              0 likes
                              Last Post stokhastic  
                              Started by jlkramer16, Yesterday, 04:29 PM
                              1 response
                              5 views
                              0 likes
                              Last Post jlkramer16  
                              Working...
                              X