• If this is your first visit, you will have to register before you can post. To view messages, please scroll below and select the forum that you would like to visits. Questions? Be sure to check out the Forum FAQ.

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 thgamey, Yesterday, 08:38 PM
        1 response
        9 views
        0 likes
        Last Post NinjaTrader_Marco  
        Started by stredtity, Today, 01:21 AM
        0 responses
        4 views
        0 likes
        Last Post stredtity  
        Started by superg3, Yesterday, 10:12 PM
        0 responses
        8 views
        0 likes
        Last Post superg3
        by superg3
         
        Started by johnnybegoode, Yesterday, 07:02 PM
        0 responses
        10 views
        0 likes
        Last Post johnnybegoode  
        Started by YevhenShynkarenko, Yesterday, 05:02 PM
        1 response
        15 views
        0 likes
        Last Post YevhenShynkarenko  
        Working...
        X