Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Autoscale question

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

    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?

    --EV

    #2
    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

    Comment


      #3
      Originally posted by NinjaTrader_Matthew View Post
      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;
      }
      Yes, I am seeing something different, bu I do not understand it well enough to discuss. For example, it was showing the issue on my chart. I turned away and did some Internet reading. When I looked back the lines were no longer visible (values below the panel bottom). I have no idea what changed.

      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


        #4
        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 DJ888, 04-16-2024, 06:09 PM
        4 responses
        11 views
        0 likes
        Last Post DJ888
        by DJ888
         
        Started by terofs, Today, 04:18 PM
        0 responses
        5 views
        0 likes
        Last Post terofs
        by terofs
         
        Started by nandhumca, Today, 03:41 PM
        0 responses
        5 views
        0 likes
        Last Post nandhumca  
        Started by The_Sec, Today, 03:37 PM
        0 responses
        3 views
        0 likes
        Last Post The_Sec
        by The_Sec
         
        Started by GwFutures1988, Today, 02:48 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Working...
        X