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

    #16
    Originally posted by eDanny View Post
    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,

    Somehow I missed your post? Your code snippet worked like a charm! Using it I can pick and choose which plots to include.
    Thanks, Woody.

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

    if(Plots[4].PlotStyle == PlotStyle.Bar)
    {
    Plots[4].Width = (float) (chartControl.GetBarPaintWidth(ChartBars));
    }
    if(Plots[5].PlotStyle == PlotStyle.Bar)
    {

    Plots[5].Width = (float) (chartControl.GetBarPaintWidth(ChartBars));
    }
    }

    Comment


      #17
      Hello Woody,

      With your new code you are now comparing each plot individually.

      The short hand would work with your loop. (I've tested my end)

      foreach (Plot plot in Plots)
      {
      if (plot.PlotStyle == PlotStyle.Bar)
      {
      // execute code
      }
      }
      Chelsea B.NinjaTrader Customer Service

      Comment


        #18
        Originally posted by NinjaTrader_ChelseaB View Post
        Hello Woody,

        With your new code you are now comparing each plot individually.

        The short hand would work with your loop. (I've tested my end)

        foreach (Plot plot in Plots)
        {
        if (plot.PlotStyle == PlotStyle.Bar)
        {
        // execute code
        }
        }
        Chelsea,
        Yes! Exactly what I was looking for. Thanks for being patient with me. Slowly Learning!
        Thanks, Woody.

        Comment


          #19
          This is another way, works when zomming in/out chart too:

          Code:
                  protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
                  {
                      Plots[0].Width = (float) (chartControl.GetBarPaintWidth(ChartBars));
                  }
          Last edited by ttodua; 02-05-2019, 08:40 AM.

          Comment


            #20
            Hello TazoTadoa,

            You may use the AutoWidth property of the plot and you will not have to use OnRender().

            Code:
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Name                                        = "AutoWidthTest";
            
                    AddPlot(new Stroke(Brushes.Lime), PlotStyle.Bar, "MyPlot");
                    Plots[0].AutoWidth = true;
                }
            }
            
            protected override void OnBarUpdate()
            {
                Values[0][0] = Close[0];
            }
            Please let us know if you have any questions.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by Geovanny Suaza, 02-11-2026, 06:32 PM
            0 responses
            636 views
            0 likes
            Last Post Geovanny Suaza  
            Started by Geovanny Suaza, 02-11-2026, 05:51 PM
            0 responses
            366 views
            1 like
            Last Post Geovanny Suaza  
            Started by Mindset, 02-09-2026, 11:44 AM
            0 responses
            107 views
            0 likes
            Last Post Mindset
            by Mindset
             
            Started by Geovanny Suaza, 02-02-2026, 12:30 PM
            0 responses
            568 views
            1 like
            Last Post Geovanny Suaza  
            Started by RFrosty, 01-28-2026, 06:49 PM
            0 responses
            571 views
            1 like
            Last Post RFrosty
            by RFrosty
             
            Working...
            X