--EV
Announcement
Collapse
No announcement yet.
Partner 728x90
Collapse
NinjaTrader
Autoscale question
Collapse
X
-
Autoscale question
I would like autoscale to include the indicator's plots, but not its lines. How do I do that, both programmatically and as a chart user?
--EVTags: None
-
The default behavior of IsAutoScale = true of an indicator is to include the plots, but not the lines.. Are you seeing something different?
At any rate, you can override the OnCalculateMinMax() method from an indicator
Code://only called when IsAutoScale is set to true public override void OnCalculateMinMax() { int barsFromIndex = ChartBars.FromIndex; int barsToIndex = ChartBars.ToIndex; double tmpMin = double.MaxValue; double tmpMax = double.MinValue; int loopToIndex = Calculate == Calculate.OnBarClose ? Math.Min(barsToIndex, ChartBars.Count - 2) : barsToIndex; // loop through visible bars on the chart (if desired) for (int barIndex = Math.Max(barsFromIndex, BarsRequiredToPlot + 1); barIndex <= loopToIndex; barIndex++) { // loop through each Plot "Values" foreach (Series<double> valueSeries in Values) { double plotValue = valueSeries.GetValueAt(barIndex); // save a tmp min/max value for each plot tmpMin = Math.Min(tmpMin, plotValue); tmpMax = Math.Max(tmpMax, plotValue); } } // set final max/minvalue MaxValue = tmpMax; MinValue = tmpMin; }
MatthewNinjaTrader Product Management
-
Originally posted by NinjaTrader_Matthew View PostThe default behavior of IsAutoScale = true of an indicator is to include the plots, but not the lines.. Are you seeing something different?
At any rate, you can override the OnCalculateMinMax() method from an indicator
Code://only called when IsAutoScale is set to true public override void OnCalculateMinMax() { int barsFromIndex = ChartBars.FromIndex; int barsToIndex = ChartBars.ToIndex; double tmpMin = double.MaxValue; double tmpMax = double.MinValue; int loopToIndex = Calculate == Calculate.OnBarClose ? Math.Min(barsToIndex, ChartBars.Count - 2) : barsToIndex; // loop through visible bars on the chart (if desired) for (int barIndex = Math.Max(barsFromIndex, BarsRequiredToPlot + 1); barIndex <= loopToIndex; barIndex++) { // loop through each Plot "Values" foreach (Series<double> valueSeries in Values) { double plotValue = valueSeries.GetValueAt(barIndex); // save a tmp min/max value for each plot tmpMin = Math.Min(tmpMin, plotValue); tmpMax = Math.Max(tmpMax, plotValue); } } // set final max/minvalue MaxValue = tmpMax; MinValue = tmpMin; }
This sort of thing is not really new. It happens from time to time, but not usually. I do not know how to characterize when it happens. If I get something substantial I'll update this. For now, what you said is fine and I'll just keep an eye on it.
--EV
Comment
-
Just happened again, but still not enough info to be helpful to you. I brought up a chart and the lines were included in the autoscale. I double clicked the indicator to bring up the Indicators dialog and now the chart is autoscaling the indicator on just the plots, as it should.
I do not know whether my clicks fixed it, or whether they were coincidence and it is just time-based as has sometimes seemed the case in the past.
I do not know enough to reproduce it, but I doubt it is random. Probably something more like an initial state issue, or perhaps an uninitialized variable. I'm assuming this is another NT bug, because I have no idea what the indicator itself could be doing to cause that behavior.
--EV
Comment
Latest Posts
Collapse
Topics | Statistics | Last Post | ||
---|---|---|---|---|
Started by kevinenergy, 02-17-2023, 12:42 PM
|
117 responses
2,764 views
1 like
|
Last Post
by jculp
Today, 12:59 PM
|
||
Started by Mongo, Today, 11:05 AM
|
5 responses
15 views
0 likes
|
Last Post Today, 12:58 PM | ||
Started by SightCareAubetter, Today, 12:55 PM
|
0 responses
3 views
0 likes
|
Last Post Today, 12:55 PM | ||
Started by traderqz, Today, 12:06 AM
|
8 responses
16 views
0 likes
|
Last Post
by traderqz
Today, 12:51 PM
|
||
Started by SightCareAubetter, Today, 12:50 PM
|
0 responses
2 views
0 likes
|
Last Post Today, 12:50 PM |
Comment