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

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.
            JimNinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by wzgy0920, 04-20-2024, 06:09 PM
            2 responses
            26 views
            0 likes
            Last Post wzgy0920  
            Started by wzgy0920, 02-22-2024, 01:11 AM
            5 responses
            32 views
            0 likes
            Last Post wzgy0920  
            Started by wzgy0920, Yesterday, 09:53 PM
            2 responses
            49 views
            0 likes
            Last Post wzgy0920  
            Started by Kensonprib, 04-28-2021, 10:11 AM
            5 responses
            192 views
            0 likes
            Last Post Hasadafa  
            Started by GussJ, 03-04-2020, 03:11 PM
            11 responses
            3,234 views
            0 likes
            Last Post xiinteractive  
            Working...
            X