• 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

Set Right Margin Horizontal Gridlines via NinjaScript

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

    Set Right Margin Horizontal Gridlines via NinjaScript

    Howdy--

    I like to set my charts up with $500 horizontal gridlines, so that I can quickly see risk-reward multiples.

    Is it possible to programmatically set the right axis horizontal gridlines via NinjaScript? If so, how might one access those settings?

    If I was able to access the settings, I would create a switch within Initialize() to look at PointValue and TickSize to set the gridlines.

    Thanks!

    Aventeren

    #2
    Hi aventeren,

    There are no supported methods to control the scroll and range of a chart.

    You may be able to do with unsupported items in ChartControl.ChartPanel. Again that would be unsupported and I would not be able to assist.


    You can draw your own horizontal lines using NinjaScript at any interval you would like using a loop. (this is supported)
    You can also choose to include or not include the horizontal lines with the autoscaling to control the vertical range and scale.

    Below is a link to the help guide on DrawHorizontalLine().
    http://www.ninjatrader.com/support/h...zontalline.htm

    You can find the tick size with Instrument.MasterInstrument.TickSize.

    You can find the point value with Instrument.MasterInstrument.PointValue.
    http://www.ninjatrader.com/support/h...trument_po.htm
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Need Ideas on How to Use ChartControl.ChartPanel to Control Horizontal Grid Lines

      Howdy--

      I was told by NT Support that I could potentially use ChartControl.ChartPanel to access and control the horizontal grid lines value? NT Support indicated this was unsupported, so I am looking to see if anyone has any experience on which values I need to get at to fix my horizontal grid line values.

      My goal is to create horizontal grid lines with a fixed value of $500 so that I can easily see risk : reward relationships. However doing so requires that the grid lines be drawn to account for the tick value. So in the case of the ES with a $12.50/tick, the grid lines would be drawn every $500/$12.50/tick = 40 ticks, whereas the CL with a $10.00/tick the grid lines would be drawn every $500/$10.00/tick = 50 ticks.

      I built an indicator to lay on top of the chart, but it gets annoying to use it because when I click on a zoomed out chart it's nearly impossible not to grab and highlight one of these manually drawn grid lines. Plus, right clicking while the grid lines are compressed (for instance to access Indicators, Data Series, etc) is also difficult because NT wants to grab and highlight the manually drawn grid lines...and then right clicking just gives me the Properties menu for the grid lines. So it's a pain in the butt.

      Ideally I would be able to access the following parameters from the "Chart Panel Properties - Panel 1" dialog box that is accessed via a right click to the right hand margin and selecting "Properties":

      1. Horizontal grid lines interval type
      2. Horizontal grid lines interval value

      Click image for larger version

Name:	Chart Panel Properties - Panel 1.png
Views:	1
Size:	27.7 KB
ID:	872389

      Does anyone know how I might access these two values such that I could set the "interval type" to "ticks" and the "interval value" to be equal to "$500/Instrument.MasterInstrument.TickSize"?

      Thanks,

      Aventeren

      Comment


        #4
        Originally posted by aventeren View Post
        Howdy--

        I was told by NT Support that I could potentially use ChartControl.ChartPanel to access and control the horizontal grid lines value? NT Support indicated this was unsupported, so I am looking to see if anyone has any experience on which values I need to get at to fix my horizontal grid line values.

        My goal is to create horizontal grid lines with a fixed value of $500 so that I can easily see risk : reward relationships. However doing so requires that the grid lines be drawn to account for the tick value. So in the case of the ES with a $12.50/tick, the grid lines would be drawn every $500/$12.50/tick = 40 ticks, whereas the CL with a $10.00/tick the grid lines would be drawn every $500/$10.00/tick = 50 ticks.

        I built an indicator to lay on top of the chart, but it gets annoying to use it because when I click on a zoomed out chart it's nearly impossible not to grab and highlight one of these manually drawn grid lines. Plus, right clicking while the grid lines are compressed (for instance to access Indicators, Data Series, etc) is also difficult because NT wants to grab and highlight the manually drawn grid lines...and then right clicking just gives me the Properties menu for the grid lines. So it's a pain in the butt.

        Ideally I would be able to access the following parameters from the "Chart Panel Properties - Panel 1" dialog box that is accessed via a right click to the right hand margin and selecting "Properties":

        1. Horizontal grid lines interval type
        2. Horizontal grid lines interval value

        [ATTACH]30136[/ATTACH]

        Does anyone know how I might access these two values such that I could set the "interval type" to "ticks" and the "interval value" to be equal to "$500/Instrument.MasterInstrument.TickSize"?

        Thanks,

        Aventeren
        ChartControl.HorizontalGridLines
        ChartControl.HorizontalGridLinesIntervalLeft
        ChartControl.HorizontalGridLinesIntervalRight
        ChartControl.HorizontalGridLinesIntervalTypeLeft
        ChartControl.HorizontalGridLinesIntervalTypeRight
        Use them as thou wilt.

        Comment


          #5
          Originally posted by koganam View Post
          Use them as thou wilt.
          Well I'll be damned.

          Thanks!

          I'll report back what I learn.

          Comment


            #6
            @koganam--

            Do you have any idea on what the acceptable types are for the "...IntervalType..."?

            For instance, is there an enum list that accompanies these?

            ...and how the heck did you find/discover these? Is there a hidden ninja trick -- and when I mean ninja, I mean like the kind that carries throwing stars and wears black clothes!

            Comment


              #7
              Originally posted by aventeren View Post
              @koganam--

              Do you have any idea on what the acceptable types are for the "...IntervalType..."?

              For instance, is there an enum list that accompanies these?

              ...and how the heck did you find/discover these? Is there a hidden ninja trick -- and when I mean ninja, I mean like the kind that carries throwing stars and wears black clothes!
              Code:
              ChartControl.HorizontalGridLinesIntervalTypeRight = HorizontalGridlinesIntervalType.Ticks; //or
              ChartControl.HorizontalGridLinesIntervalTypeRight = HorizontalGridlinesIntervalType.Points;
              Pay attention to the case: One, the object, says GridLines: the other, the enum, says Gridlines.
              Last edited by koganam; 09-24-2014, 04:47 PM.

              Comment


                #8
                Originally posted by koganam View Post
                Code:
                ChartControl.HorizontalGridLinesIntervalTypeRight = HorizontalGridlinesIntervalType.Ticks; //or
                ChartControl.HorizontalGridLinesIntervalTypeRight = HorizontalGridlinesIntervalType.Points;
                Pay attention to the case: One says GridLines, the other Gridlines.
                Thanks, I'll try this out and report back.

                Where did you learn this? Trial and error? Is there some sort of secret Chart Control documentation source somewhere?

                Comment


                  #9
                  Originally posted by aventeren View Post
                  Thanks, I'll try this out and report back.

                  Where did you learn this? Trial and error? Is there some sort of secret Chart Control documentation source somewhere?
                  Not exactly secret: it is called Intellisense, and is part of the .NET framework, so built-in to NinjaTrader. To all of us the public, ChartControl is essentially undocumented.

                  Comment


                    #10
                    Update:

                    So I tried placing

                    Code:
                    ChartControl.HorizontalGridLinesIntervalRight = 75;
                    into both Intialize() and OnBarUpdate()--no joy.

                    Any hints?

                    Comment


                      #11
                      Originally posted by aventeren View Post
                      Update:

                      So I tried placing

                      Code:
                      ChartControl.HorizontalGridLinesIntervalRight = 75;
                      into both Intialize() and OnBarUpdate()--no joy.

                      Any hints?
                      Look for the errors in your log.

                      Comment


                        #12
                        Originally posted by koganam View Post
                        Look for the errors in your log.
                        No log errors present.

                        Comment


                          #13
                          Originally posted by aventeren View Post
                          No log errors present.
                          Then something else is wrong. If you place that in Initialize(), you should get an error: "Failed to call method 'Initialize' for indicator '...': Object reference not set to an instance of an object."

                          You would put the commands in OnStartUp(), or delimit them in OnBarUpdate() to CurrentBar == 0.

                          That is for correct behavior, otherwise the Initialize() method fails. Even then the adjustment in spacing still occurs correctly on my charts.

                          What are the exact lines of code that you put in?

                          Comment


                            #14
                            Bingo. Thanks.

                            Originally posted by koganam View Post
                            Then something else is wrong. If you place that in Initialize(), you should get an error: "Failed to call method 'Initialize' for indicator '...': Object reference not set to an instance of an object."

                            You would put the commands in OnStartUp(), or delimit them in OnBarUpdate() to CurrentBar == 0.

                            That is for correct behavior, otherwise the Initialize() method fails. Even then the adjustment in spacing still occurs correctly on my charts.

                            What are the exact lines of code that you put in?
                            The OnStartUp() tip was what I needed.

                            I inserted the following code into my indicator, and now I'm good to go.

                            Code:
                            protected override void OnStartUp()
                            {
                            	ChartControl.HorizontalGridLinesIntervalRight = Convert.ToInt32(500/(Instrument.MasterInstrument.TickSize * Instrument.MasterInstrument.PointValue));
                            }
                            Now I have auto scaling horizontal grid lines that are tuned to a currency value as opposed to a tick or points value. Now I can go from chart to chart and see uniform risk-reward.

                            Thanks, koganam. It's always a pleasure working with you.

                            Aventeren

                            Comment


                              #15
                              One Last Question...

                              ...is there a way to have this bit of code universally applied to all charts (like a "Property") without inserting this bit of code into an indicator that must be loaded onto a chart to make it work?

                              Comment

                              Latest Posts

                              Collapse

                              Topics Statistics Last Post
                              Started by Nat11, Today, 04:30 AM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Started by Option Whisperer, Yesterday, 11:50 AM
                              2 responses
                              10 views
                              0 likes
                              Last Post Option Whisperer  
                              Started by TraderJim618, Yesterday, 01:20 PM
                              1 response
                              6 views
                              0 likes
                              Last Post NinjaTrader_ChrisL  
                              Started by drpapp, 01-24-2019, 06:57 AM
                              6 responses
                              72 views
                              1 like
                              Last Post brucerobinson  
                              Started by ttodua, 12-06-2019, 11:40 PM
                              1 response
                              12 views
                              0 likes
                              Last Post NinjaTrader_ChelseaB  
                              Working...
                              X