Draw Outputs from Indicator

Indicators have an ability to draw all or some of their outputs. In order to do so the following steps must be taken:

  1. Outputs that should be drawn by the indicator must have drawnByIndicator attribute set to true.
  2. Indicator must implement IDrawingIndicator interface and overide its method - public void drawOutput(Graphics g, int outputIdx, Object valuesArr, Color color, IIndicatorDrawingSupport indicatorDrawingSupport, List shapes, Map> handles). This method is called for every output drawn by the indicator whenever a chart surface needs to be redrawn.

drawOutput method

Method drawOutput is used to draw indicator output on the chart. The method accepts the following parameters:

  • g - graphical object of the surface where outputs should be displayed.
  • outputIdx - index of the output.
  • valuesArr - array of outputs. Depending on the output type it can be double[], int[] or Object[].
  • color - color that the user selected for this output.
  • stroke - stroke that the user selected for this output. Can be null if output is not a line.
  • indicatorDrawingSupport - object that contains information about candles on the chart.
  • shapes - list that contains graphical shapes of the output. These shapes will be used to detect if user clicked on the output of the indicator.
  • handles - list that contains graphical points that are not visible by default but become visible if user hovers over one of the outputs of the indicator.


IIndicatorDrawingSupport interface provides various useful methods that return information about candles visible on the chart.

  • getCandles - Returns array of candles where each candle corresponds to the value with the same index in the array of values for the current output.
  • getNumberOfCandlesOnScreen - returns the number of candles visible on the screen.
  • getIndexOfFirstCandleOnScreen - index in the array of values and candles. Points to the first candle that is visible on the screen. Depending on type of the output (simple line for example) it may be a good idea to draw only the values that start from the candle before the first visible candle and to the candle after the last visible candle.
  • getCandleWidthInPixels - returns the width of the candle in pixels.
  • getSpaceBetweenCandlesInPixels - returns space between two neighbor candles in pixels.
  • getMiddleOfCandle - returns x coordinate of the middle of the candle. X coordinate can be outside the visible area.
  • getYForValue - returns Y coordinate for the specified value. Calculation depends on minimum and maximum values for indicator.
  • isLastCandleInProgress - returns true if array returned by this getCandles method includes latest "in-progress" candle.
  • getChartWidth - returns width of the visible area. Can be used to avoid drawing outside the visible area.
  • getChartHeight - returns height of the visible area. Can be used to avoid drawing outside the visible area.
The information on this web site is provided only as general information, which may be incomplete or outdated. Click here for full disclaimer.