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

Set Right Margin Horizontal Gridlines via NinjaScript

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

    #16
    Originally posted by aventeren View Post
    ...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?
    1. Create an empty indicator.
    2. Write only your lines adjusting code.
    3. Load the indicator on a chart.
    4. Save the chart as the Default Template.

    Comment


      #17
      Originally posted by koganam View Post
      1. Create an empty indicator.
      2. Write only your lines adjusting code.
      3. Load the indicator on a chart.
      4. Save the chart as the Default Template.
      Yeah, that's what I'd been doing on my "manual" grid line indicator. Maybe I'll just make a "Base" indicator that I'll drop many of my standard items into.

      Thanks for your help.

      Take care,

      Aventeren

      Comment


        #18
        Quick Update:

        I created a "Base" indicator that I now plug into all of my charts. I am able to control the horizontal grid lines to a dollar value of my choosing. However, I have been setting up my chart with a monthly data series in panel 1, a weekly data series in panel 2 and a daily data series in panel 3, and I for the life of me can't get all three panels to display the correct grid line intervals.

        My indicator uses the following code to set the gridlines:

        Code:
        #region Using declarations
        using System;
        using System.Diagnostics;
        using System.Drawing;
        using System.Drawing.Drawing2D;
        using System.ComponentModel;
        using System.Xml.Serialization;
        using NinjaTrader.Data;
        using NinjaTrader.Gui.Chart;
        #endregion
        
        namespace NinjaTrader.Indicator
        {
        	[Description("Indicator to hold the base elements for use on all charts.")]
        	public class AventerenBase : Indicator
        	{
        		private double		valueGrid = 500;
        		
        		protected override void Initialize()
                {
        			ClearOutputWindow();
        			Overlay	= true;
        			DrawOnPricePanel = true;
        		}
        
        		protected override void OnStartUp()
        		{
        			ChartControl.HorizontalGridLines = true;
        			ChartControl.HorizontalGridLinesIntervalRight = Convert.ToInt32(ValueGrid/(Instrument.MasterInstrument.TickSize * Instrument.MasterInstrument.PointValue));
        		}
        		
        		protected override void OnBarUpdate()
        		{
        			
        		}
        
        		#region Properties
        		[Description("Period")]
        		[GridCategory("Parameters")]
        		public double ValueGrid
        		{
        			get { return valueGrid; }
        			set { valueGrid = Math.Max(1, value); }
        		}
        		#endregion
        	}
        }
        Pretty simple. But this is what happens when I apply the "Base" indicator to each price panel (i.e., I add the "Base" indicator three times, then specify the Monthly, Weekly, Daily data series Close values and then apply the indicator to the correct panel: panel 1 for Monthly, panel 2 for Weekly, panel 3 for Daily).

        Click image for larger version

Name:	Gridlines.jpg
Views:	1
Size:	87.2 KB
ID:	872547

        So as you can see, the Monthly panel 1 grid lines are correct, as I have the grid value set at 500, so the gridlines would be $500/$12.50/tick = 40 ticks. But panels 2 and 3 are wrong.

        Does anyone have an idea on how I might control the horizontal grid line intervals on panels 2 and 3?

        Thanks,

        Aventeren

        Comment


          #19
          This is untested code so I wouldn't know of any consequences of using such, but you can create a new instance of the data panels and set the value from there:

          Code:
          		protected override void OnStartUp()
          		{			
          			ChartControl.HorizontalGridLines = true;
          			PanelData panels = new Gui.Chart.PanelData();
          			panels.HorizontalGridLinesIntervalRight = Convert.ToInt32(ValueGrid/(Instrument.MasterInstrument.TickSize * Instrument.MasterInstrument.PointValue));			
          
          		}
          Please use this with caution
          MatthewNinjaTrader Product Management

          Comment


            #20
            Originally posted by NinjaTrader_Matthew View Post
            This is untested code so I wouldn't know of any consequences of using such, but you can create a new instance of the data panels and set the value from there:

            Code:
            		protected override void OnStartUp()
            		{			
            			ChartControl.HorizontalGridLines = true;
            			PanelData panels = new Gui.Chart.PanelData();
            			panels.HorizontalGridLinesIntervalRight = Convert.ToInt32(ValueGrid/(Instrument.MasterInstrument.TickSize * Instrument.MasterInstrument.PointValue));			
            
            		}
            Please use this with caution
            Good suggestion, thanks Matthew. I tried it, however, to no avail.

            It's weird, sometimes panel 1 is right and then sometimes panel 1 won't print any grid lines or axis values at all. Same with panels 2 and 3. Sometimes I'll get a combination of 1 and 2 that are right but panel 3 will be wrong. Then I switch instruments (i.e., ES to CL), and gridlines and axis values disappear.

            Let me know if you or anyone else on your Team has any other ideas.

            Thanks,

            Aventeren

            Comment


              #21
              Originally posted by aventeren View Post
              Quick Update:

              I created a "Base" indicator that I now plug into all of my charts. I am able to control the horizontal grid lines to a dollar value of my choosing. However, I have been setting up my chart with a monthly data series in panel 1, a weekly data series in panel 2 and a daily data series in panel 3, and I for the life of me can't get all three panels to display the correct grid line intervals.

              My indicator uses the following code to set the gridlines:

              Code:
              #region Using declarations
              using System;
              using System.Diagnostics;
              using System.Drawing;
              using System.Drawing.Drawing2D;
              using System.ComponentModel;
              using System.Xml.Serialization;
              using NinjaTrader.Data;
              using NinjaTrader.Gui.Chart;
              #endregion
              
              namespace NinjaTrader.Indicator
              {
              	[Description("Indicator to hold the base elements for use on all charts.")]
              	public class AventerenBase : Indicator
              	{
              		private double		valueGrid = 500;
              		
              		protected override void Initialize()
                      {
              			ClearOutputWindow();
              			Overlay	= true;
              			DrawOnPricePanel = true;
              		}
              
              		protected override void OnStartUp()
              		{
              			ChartControl.HorizontalGridLines = true;
              			ChartControl.HorizontalGridLinesIntervalRight = Convert.ToInt32(ValueGrid/(Instrument.MasterInstrument.TickSize * Instrument.MasterInstrument.PointValue));
              		}
              		
              		protected override void OnBarUpdate()
              		{
              			
              		}
              
              		#region Properties
              		[Description("Period")]
              		[GridCategory("Parameters")]
              		public double ValueGrid
              		{
              			get { return valueGrid; }
              			set { valueGrid = Math.Max(1, value); }
              		}
              		#endregion
              	}
              }
              Pretty simple. But this is what happens when I apply the "Base" indicator to each price panel (i.e., I add the "Base" indicator three times, then specify the Monthly, Weekly, Daily data series Close values and then apply the indicator to the correct panel: panel 1 for Monthly, panel 2 for Weekly, panel 3 for Daily).

              [ATTACH]30398[/ATTACH]

              So as you can see, the Monthly panel 1 grid lines are correct, as I have the grid value set at 500, so the gridlines would be $500/$12.50/tick = 40 ticks. But panels 2 and 3 are wrong.

              Does anyone have an idea on how I might control the horizontal grid line intervals on panels 2 and 3?

              Thanks,

              Aventeren
              Your picture is barely legible. You might have to change your colors so that we can more clearly see what you are describing.

              However, for starters, you are using an int for ChartControl.HorizontalGridLinesIntervalRight. It is supposed to be a double. Yes, using an int instead of a double can throw off your calculations.

              Without more precise, detailed information, that is all that I can say for now.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by love2code2trade, 04-17-2024, 01:45 PM
              4 responses
              36 views
              0 likes
              Last Post love2code2trade  
              Started by alifarahani, Today, 09:40 AM
              2 responses
              13 views
              0 likes
              Last Post alifarahani  
              Started by junkone, Today, 11:37 AM
              3 responses
              16 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by pickmyonlineclass, Today, 12:23 PM
              0 responses
              2 views
              0 likes
              Last Post pickmyonlineclass  
              Started by frankthearm, Yesterday, 09:08 AM
              12 responses
              44 views
              0 likes
              Last Post NinjaTrader_Clayton  
              Working...
              X