namespace NinjaTrader.NinjaScript.Indicators
{
public class BarWidthTest : Indicator
{
protected override void OnStateChange()
{
if (State == State.SetDefaults)
{
Description = @"Displays the Average Volume for a particular time based on N previous days.";
Name = "BarWidthTest";
Calculate = Calculate.OnBarClose;
IsOverlay = false;
DisplayInDataBox = true;
DrawOnPricePanel = true;
DrawHorizontalGridLines = true;
DrawVerticalGridLines = true;
PaintPriceMarkers = true;
ScaleJustification = NinjaTrader.Gui.Chart.ScaleJustification.Right;
//Disable this property if your indicator requires custom values that cumulate with each new market data event.
//See Help Guide for additional information.
IsSuspendedWhileInactive = true;
AddPlot(new Stroke(Brushes.Black), PlotStyle.Bar, "AverageVolume");
AddPlot(new Stroke(Brushes.Red,5), PlotStyle.Bar, "VolumeIndicator");
Plots[0].AutoWidth = true;
}
else if (State == State.DataLoaded)
{
}
else if (State == State.Configure)
{
}
}
protected override void OnBarUpdate()
{
if(CurrentBar < 0) return;
AverageVolume[0] = Volume[0]/2;
VolumeIndicator[0] = Volume[0];
}
protected override void OnRender(ChartControl chartControl, ChartScale chartScale) {
Plots[1].Width = Plots[0].Width - 1;
}
#region Properties
[Browsable(false)]
[XmlIgnore]
public Series<double> VolumeIndicator
{
get { return Values[1]; }
}
[Browsable(false)]
[XmlIgnore]
public Series<double> AverageVolume
{
get { return Values[0]; }
}
#endregion
}
}
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Dynamically updating Plots[0].Width in OnRender
Collapse
X
-
Dynamically updating Plots[0].Width in OnRender
I am trying to get the Width of one of my plots to match the width of another minus 1 pixel. I am trying to confirm that OnRender is the right place to do that and also inquire as to why this isn't working:
Code: -
Hello swcooke,
Thanks for your reply.
Yes, I missed that, thanks.
In OnRender() you would need to use base.OnRender(chartControl, chartScale); See the 2nd tip here: https://ninjatrader.com/support/help.../?onrender.htm
In OnRender you can obtain the current bar width from BarWidth: https://ninjatrader.com/support/help...l_barwidth.htm which is a double so just convert to int type and subtract 1 and set Plots[1].width to that value.
Comment
-
Thank you Paul. Here is the code I went with in case it helps anyone else:
Code:protected override void OnRender(ChartControl chartControl, ChartScale chartScale) { base.OnRender(chartControl, chartScale); Plots[1].Width = Math.Max((float)chartControl.BarWidth - 3,2); }
- Likes 1
Comment
Latest Posts
Collapse
| Topics | Statistics | Last Post | ||
|---|---|---|---|---|
|
Started by charlesugo_1, 05-26-2026, 05:03 PM
|
0 responses
71 views
0 likes
|
Last Post
by charlesugo_1
05-26-2026, 05:03 PM
|
||
|
Started by DannyP96, 05-18-2026, 02:38 PM
|
1 response
152 views
0 likes
|
Last Post
|
||
|
Started by CarlTrading, 05-11-2026, 05:56 AM
|
0 responses
162 views
0 likes
|
Last Post
by CarlTrading
05-11-2026, 05:56 AM
|
||
|
Started by CarlTrading, 05-10-2026, 08:12 PM
|
0 responses
100 views
0 likes
|
Last Post
by CarlTrading
05-10-2026, 08:12 PM
|
||
|
Started by Hwop38, 05-04-2026, 07:02 PM
|
0 responses
288 views
0 likes
|
Last Post
by Hwop38
05-04-2026, 07:02 PM
|

Comment