- Create an empty indicator.
- Write only your lines adjusting code.
- Load the indicator on a chart.
- Save the chart as the Default Template.
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Set Right Margin Horizontal Gridlines via NinjaScript
Collapse
X
-
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.Originally posted by koganam View Post- Create an empty indicator.
- Write only your lines adjusting code.
- Load the indicator on a chart.
- Save the chart as the Default Template.
Thanks for your help.
Take care,
Aventeren
Comment
-
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:
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).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 } }
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
-
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:
Please use this with cautionCode:protected override void OnStartUp() { ChartControl.HorizontalGridLines = true; PanelData panels = new Gui.Chart.PanelData(); panels.HorizontalGridLinesIntervalRight = Convert.ToInt32(ValueGrid/(Instrument.MasterInstrument.TickSize * Instrument.MasterInstrument.PointValue)); }MatthewNinjaTrader Product Management
Comment
-
Good suggestion, thanks Matthew. I tried it, however, to no avail.Originally posted by NinjaTrader_Matthew View PostThis 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:
Please use this with cautionCode:protected override void OnStartUp() { ChartControl.HorizontalGridLines = true; PanelData panels = new Gui.Chart.PanelData(); panels.HorizontalGridLinesIntervalRight = Convert.ToInt32(ValueGrid/(Instrument.MasterInstrument.TickSize * Instrument.MasterInstrument.PointValue)); }
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
-
Your picture is barely legible. You might have to change your colors so that we can more clearly see what you are describing.Originally posted by aventeren View PostQuick 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:
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).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 } }
[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
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 Geovanny Suaza, 02-11-2026, 06:32 PM
|
0 responses
582 views
0 likes
|
Last Post
|
||
|
Started by Geovanny Suaza, 02-11-2026, 05:51 PM
|
0 responses
338 views
1 like
|
Last Post
|
||
|
Started by Mindset, 02-09-2026, 11:44 AM
|
0 responses
103 views
0 likes
|
Last Post
by Mindset
02-09-2026, 11:44 AM
|
||
|
Started by Geovanny Suaza, 02-02-2026, 12:30 PM
|
0 responses
554 views
1 like
|
Last Post
|
||
|
Started by RFrosty, 01-28-2026, 06:49 PM
|
0 responses
552 views
1 like
|
Last Post
by RFrosty
01-28-2026, 06:49 PM
|

Comment