• 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

autoscale & Plotstyle.Bar

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

    autoscale & Plotstyle.Bar

    Hello, I’m looking for a solution to autoscale the Plotstyle.Bar. I have not found anything, and searching on the forum makes me believe this is not possible!
    I know how to set an initial width of the bars, but that width remains no matter the scale of the chart.

    1. Is there a way to set autoscale for Plotstyle.Bar?

    2. If not, and not an supported issue, please give me a hint how to make my own autoscale of Plotstyle.Bar

    Finally. I suggest that NT9 should have autoscale for all plotstyles. Have a look at the attached image, and it is obvious how much more information/knowledge you get from an autoscaled chart.
    Image: (A,B as of today, C,D as I want it)

    Thank you/AndBro
    Attached Files

    #2
    Hello AndBro,

    I want to clarify, that you are not referring to the autoscale in that you want to control the top and bottom of the chart to specific price y values, but instead you are wanting to control the width of the bar or the bar spacing when the chart is loaded, is this correct?

    The autoscale is pretty much only related to the price margin and is not related to the time margin.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hello ChelseaB, yes you are right. Sorry for confusing about autoscale. My intention is exactly the same “scaling” as of an instrument candlestick, when you press Ctrl-arrow up/down.

      Comment


        #4
        Hello AndBro,

        The bar width can be controlled from a Chart Style script. Custom chart styles are not supported in NinjaTrader 7 but are supported in NinjaTrader 8. (Take a look at the @ChartStyles.cs file in NT7 for a reference)

        The bar type script will set the Open, High, Low, and Close and will control the rules for the bar closing and a new bar opening. The chart style does the actual rendering of the bar by drawing rectangles and will use the width that is set the UI. You can set the default setting for this in the constructor for the class. You can also control how large or small the rendered objects are scaled as the bar spacing changes by changing the logic for the x and y values of the rectangles that are being drawn.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Thank you Chelsea B. This code works fine. Is this what you had in mind? or is there a more elegant/robust way of doing it?

          protected override void OnRender(ChartControl chartControl, ChartScale chartScale)

          {
          float barSpace = (float) (0.80*this.ChartControl.Properties.BarDistance);
          barSpace = (barSpace < 1.0) ? 1.0f : barSpace;

          Brush oldBrush = Plots[0].Brush;

          Pen newPen = new Pen(oldBrush, barSpace);
          Plots[0].Pen = newPen;

          base.OnRender(chartControl, chartScale);
          }

          Comment


            #6
            Hello,

            Thank you for the reply.

            That would be the correct concept that Chelsea was explaining, and if the result is as you like that should work.

            I have put a question in to development to see if there is a suggested approach to make the Plot bars exactly the same width as the Chart bars, if I have a better suggestion I will reply back with that.

            I look forward to being of further assistance.
            JesseNinjaTrader Customer Service

            Comment


              #7
              Hello,

              I wanted to reply back on this item.

              It looks like there is a better way to achieve the actual width.

              here is a sample that should match the primary series bars:

              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);
              	}
              }

              http://ninjatrader.com/support/helpG...paintwidth.htm


              I look forward to being of further assistance.
              Last edited by NinjaTrader_Jesse; 08-31-2016, 03:33 PM.
              JesseNinjaTrader Customer Service

              Comment


                #8
                Hello Jesse,
                Yes, this looks like an elegant and general solution. Very few lines and easy to understand what the code is doing. Perfect. I will try this in my script.
                Thank you
                /AndBro

                Comment


                  #9
                  Hello Jesse, your piece of code works so well. I have added a test for plotsyle.bar, so that code only works for that case.
                  However, I want to use this piece of code in all of my indicators. Just do copy and paste to every indicator is not a good solution (future maintenance!).
                  Do you have any recommendations for this issue?
                  Thank you, Anders

                  Comment


                    #10
                    Hello,

                    Because this is an override, you couldn't really take the whole override segment of code, that would be in the case you wanted to copy and paste into a new indicator.

                    You could make a static method to calculate the value, but you would also need to pass a instance the of indicator, ChartControl and ChartBars to that method as it requires all three.

                    One example could be to use an addon for this, you could generate a new addon and then delete the code that is generated. Then replace it with the following:


                    Code:
                    namespace NinjaTrader.MyCustomNamespace
                    {
                    	public static class MyCustomMethods
                    	{
                    		public static void UpdatePlotWidths(IndicatorBase indi, ChartControl cc, ChartBars bars)
                    		{
                    			foreach (Plot plot in indi.Plots)
                    			{
                    		    	plot.Width = (float) cc.GetBarPaintWidth(bars);
                    			}
                    		}
                    	}
                    }
                    Then from an indicator you could use the following:

                    Code:
                    protected override void OnRender(ChartControl chartControl, ChartScale chartScale)
                    {
                    	base.OnRender(chartControl, chartScale);
                    	NinjaTrader.MyCustomNamespace.MyCustomMethods.UpdatePlotWidths(this as IndicatorBase,chartControl, ChartBars);
                    }

                    IndicatorBase is used rather than a specific indicator, this is so it can be generic to be used with any indicator. the IndicatorBase is what the Plots are inherited from in your indicator.


                    I look forward to being of further assistance.
                    JesseNinjaTrader Customer Service

                    Comment


                      #11
                      Thank you Jesse for a very teaching and helpful answer. I will start using it ...

                      Thank you , Anders

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by dpolyakov, Today, 01:13 PM
                      2 responses
                      11 views
                      0 likes
                      Last Post NinjaTrader_PatrickG  
                      Started by tjendra, Today, 12:15 PM
                      3 responses
                      9 views
                      0 likes
                      Last Post tjendra
                      by tjendra
                       
                      Started by lunardiplomacy, Today, 11:46 AM
                      4 responses
                      15 views
                      0 likes
                      Last Post lunardiplomacy  
                      Started by trdninstyle, Today, 10:38 AM
                      2 responses
                      17 views
                      0 likes
                      Last Post trdninstyle  
                      Started by momchi, Yesterday, 09:19 PM
                      2 responses
                      21 views
                      0 likes
                      Last Post NinjaTrader_Jim  
                      Working...
                      X