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 alifarahani, Today, 09:40 AM
            4 responses
            21 views
            0 likes
            Last Post alifarahani  
            Started by gentlebenthebear, Today, 01:30 AM
            3 responses
            16 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by PhillT, Today, 02:16 PM
            2 responses
            7 views
            0 likes
            Last Post PhillT
            by PhillT
             
            Started by Kaledus, Today, 01:29 PM
            3 responses
            11 views
            0 likes
            Last Post NinjaTrader_Jesse  
            Started by frankthearm, Yesterday, 09:08 AM
            14 responses
            47 views
            0 likes
            Last Post NinjaTrader_Clayton  
            Working...
            X