Skip to content

Drawing Styles

Drawing Styles

When creating a custom indicator, you can specify one of 18 types of graphical plotting (as displayed in the main chart window or a chart subwindow), whose values are specified in the ENUM_DRAW_TYPE enumeration.

In one custom indicator, it is permissible to use any indicator building/drawing types. Each construction type requires specification of one to five global arrays for storing data necessary for drawing. These data arrays must be bound with indicator buffers using the SetIndexBuffer() function. The type of data from ENUM_INDEXBUFFER_TYPE should be specified for each buffer.

Depending on the drawing style, you may need one to four value buffers (marked as INDICATOR_DATA). If a style admits dynamic alternation of colors (all styles contain COLOR in their names), then you’ll need one more buffer of color (indicated type INDICATOR_COLOR_INDEX). The color buffers are always bound after value buffers corresponding to the style.

ENUM_DRAW_TYPE

IDDescriptionData buffersColor buffers
DRAW_NONENot drawn10
DRAW_LINELine10
DRAW_SECTIONSection10
DRAW_HISTOGRAMHistogram from the zero line10
DRAW_HISTOGRAM2Histogram of the two indicator buffers20
DRAW_ARROWDrawing arrows10
DRAW_ZIGZAGStyle Zigzag allows vertical section on the bar20
DRAW_FILLINGColor fill between the two levels20
DRAW_BARSDisplay as a sequence of bars40
DRAW_CANDLESDisplay as a sequence of candlesticks40
DRAW_COLOR_LINEMulticolored line11
DRAW_COLOR_SECTIONMulticolored section11
DRAW_COLOR_HISTOGRAMMulticolored histogram from the zero line11
DRAW_COLOR_HISTOGRAM2Multicolored histogram of the two indicator buffers21
DRAW_COLOR_ARROWDrawing multicolored arrows11
DRAW_COLOR_ZIGZAGMulticolored ZigZag21
DRAW_COLOR_BARSMulticolored bars41
DRAW_COLOR_CANDLESMulticolored candlesticks41

To refine the display of the selected drawing type identifiers listed in ENUM_PLOT_PROPERTY are used.

For functions PlotIndexSetInteger() and PlotIndexGetInteger()

ENUM_PLOT_PROPERTY_INTEGER

IDDescriptionProperty type
PLOT_ARROWArrow code for style DRAW_ARROWuchar
PLOT_ARROW_SHIFTVertical shift of arrows for style DRAW_ARROWint
PLOT_DRAW_BEGINNumber of initial bars without drawing and values in the DataWindowint
PLOT_DRAW_TYPEType of graphical constructionENUM_DRAW_TYPE
PLOT_SHOW_DATASign of display of construction values in the DataWindowbool
PLOT_SHIFTShift of indicator plotting along the time axis in barsint
PLOT_LINE_STYLEDrawing line styleENUM_LINE_STYLE
PLOT_LINE_WIDTHThe thickness of the drawing lineint
PLOT_COLOR_INDEXESThe number of colorsint
PLOT_LINE_COLORThe index of a buffer containing the drawing colorcolor modifier = index number of colors

For the function PlotIndexSetDouble()

ENUM_PLOT_PROPERTY_DOUBLE

IDDescriptionProperty type
PLOT_EMPTY_VALUEAn empty value for plotting, for which there is no drawingdouble

For the function PlotIndexSetString()

ENUM_PLOT_PROPERTY_STRING

IDDescriptionProperty type
PLOT_LABELThe name of the indicator graphical series to display in the DataWindow. When working with complex graphical styles requiring several indicator buffers for display, the names for each buffer can be specified using “;” as a separator. Sample code is shown in DRAW_CANDLESstring

5 styles can be used for drawing lines in custom indicators. They are valid only for the line thickness 0 or 1.

ENUM_LINE_STYLE

IDDescription
STYLE_SOLIDSolid line
STYLE_DASHBroken line
STYLE_DOTDotted line
STYLE_DASHDOTDash-dot line
STYLE_DASHDOTDOTDash - two points

To set the line drawing style and the type of drawing, the PlotIndexSetInteger() function is used. For the Fibonacci extensions the thickness and drawing style of levels can be indicated using the ObjectSetInteger() function.

Example:

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
//--- indicator buffers
double         MABuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void OnInit()
  {
//--- Bind the Array to the indicator buffer with index 0
   SetIndexBuffer(0,MABuffer,INDICATOR_DATA);
//--- Set the line drawing
   PlotIndexSetInteger(0,PLOT_DRAW_TYPE,DRAW_LINE);
//--- Set the style line
   PlotIndexSetInteger(0,PLOT_LINE_STYLE,STYLE_DOT);
//--- Set line color
   PlotIndexSetInteger(0,PLOT_LINE_COLOR,clrRed);
//--- Set line thickness
   PlotIndexSetInteger(0,PLOT_LINE_WIDTH,1);
//--- Set labels for the line
   PlotIndexSetString(0,PLOT_LABEL,"Moving Average");
//---
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                 const int prev_calculated,
                 const datetime &time[],
                 const double &open[],
                 const double &high[],
                 const double &low[],
                 const double &close[],
                 const long &tick_volume[],
                 const long &volume[],
                 const int &spread[])
  {
//---
   for(int i=prev_calculated;i<rates_total;i++)
     {
      MABuffer[i]=close[i];
     }
//--- return value of prev_calculated for next call
   return(rates_total);
  }
Last updated on