myeatrade

MQL4 Reference

MQL4 Custom indicators (2)

A group of functions used at producing of custom indicators.

These functions cannot be used in experts and scripts.

 

SetIndexDrawBegin()

void SetIndexDrawBegin(int index, int begin)

Sets the bar number (from the data beginning) from which the drawing of the given indicator line must start. The indicators are drawn from left to right. The indicator array values that are to the left of the given bar will not be shown in the chart or in the DataWindow. 0 will be set as default, and all data will be drawn.

Parameters:

index - Line index. Must lie between 0 and 7.
begin - First drawing bar position number.

Sample:

int init()
  {
//---- 2 additional buffers are used for counting.
   IndicatorBuffers(3);
//---- drawing settings
   SetIndexStyle(0,DRAW_HISTOGRAM,STYLE_SOLID,3);
   SetIndexDrawBegin(0,SignalSMA);
   IndicatorDigits(MarketInfo(Symbol(),MODE_DIGITS)+2);
//---- 3 indicator buffers mapping
   SetIndexBuffer(0,ind_buffer1);
   SetIndexBuffer(1,ind_buffer2);
   SetIndexBuffer(2,ind_buffer3);
//---- name for DataWindow and indicator subwindow label
   IndicatorShortName("OsMA("+FastEMA+","+SlowEMA+","+SignalSMA+")");
//---- initialization done
   return(0);
  }

SetIndexEmptyValue()

void SetIndexEmptyValue(int index, double value)

Sets drawing line empty value. Empty values are not drawn or shown in the DataWindow. By default, empty value is EMPTY_VALUE.

Parameters:

index - Line index. Must lie between 0 and 7.
value - New "empty" value.

Sample:

int init()
  {
//---- 2 allocated indicator buffers
    SetIndexBuffer(0,ExtUppperBuffer);
    SetIndexBuffer(1,ExtLowerBuffer);
//---- drawing parameters setting
    SetIndexStyle(0,DRAW_ARROW);
    SetIndexArrow(0,217);
    SetIndexStyle(1,DRAW_ARROW);
    SetIndexArrow(1,218);
//---- 0 value will not be displayed
    SetIndexEmptyValue(0,0.0);
    SetIndexEmptyValue(1,0.0);
//---- displaying in DataWindow
    SetIndexLabel(0,"Fractal Up");
    SetIndexLabel(1,"Fractal Down");
//---- initialization done
   return(0);
  }

SetIndexLabel()

void SetIndexLabel(int index, string text)

Sets drawing line description for showing in the DataWindow and in the tooltip.

Parameters:

index - Line index. Must lie between 0 and 7.
text  - Label text. NULL means that index value is not shown in the DataWindow.

Sample:

//+------------------------------------------------------------------+
//| Ichimoku Kinko Hyo initialization function                       |
//+------------------------------------------------------------------+
int init()
  {
//----
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Tenkan_Buffer);
   SetIndexDrawBegin(0,Tenkan-1);
   SetIndexLabel(0,"Tenkan Sen");
//----
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,Kijun_Buffer);
   SetIndexDrawBegin(1,Kijun-1);
   SetIndexLabel(1,"Kijun Sen");
//----
   a_begin=Kijun; if(a_begin<Tenkan) a_begin=Tenkan;
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_DOT);
   SetIndexBuffer(2,SpanA_Buffer);
   SetIndexDrawBegin(2,Kijun+a_begin-1);
   SetIndexShift(2,Kijun);
//---- Up Kumo bounding line does not show in the DataWindow
   SetIndexLabel(2,NULL);
   SetIndexStyle(5,DRAW_LINE,STYLE_DOT);
   SetIndexBuffer(5,SpanA2_Buffer);
   SetIndexDrawBegin(5,Kijun+a_begin-1);
   SetIndexShift(5,Kijun);
   SetIndexLabel(5,"Senkou Span A");
//----
   SetIndexStyle(3,DRAW_HISTOGRAM,STYLE_DOT);
   SetIndexBuffer(3,SpanB_Buffer);
   SetIndexDrawBegin(3,Kijun+Senkou-1);
   SetIndexShift(3,Kijun);
//---- Down Kumo bounding line does not show in the DataWindow
   SetIndexLabel(3,NULL);
//----
   SetIndexStyle(6,DRAW_LINE,STYLE_DOT);
   SetIndexBuffer(6,SpanB2_Buffer);
   SetIndexDrawBegin(6,Kijun+Senkou-1);
   SetIndexShift(6,Kijun);
   SetIndexLabel(6,"Senkou Span B");
//----
   SetIndexStyle(4,DRAW_LINE);
   SetIndexBuffer(4,Chinkou_Buffer);
   SetIndexShift(4,-Kijun);
   SetIndexLabel(4,"Chinkou Span");
//----
   return(0);
  }

SetIndexShift()

void SetIndexShift(int index, int shift)

Sets offset for the drawing line. For positive values, the line drawing will be shifted to the right, otherwise it will be shifted to the left. I.e., the value calculated on the current bar will be drawn shifted relatively to the current bar.

Parameters:

index - Line index. Must lie between 0 and 7.
shift - Shitf value in bars.

Sample:

//+------------------------------------------------------------------+
//| Alligator initialization function                                |
//+------------------------------------------------------------------+
int init()
  {
//---- line shifts when drawing
   SetIndexShift(0,JawsShift);
   SetIndexShift(1,TeethShift);
   SetIndexShift(2,LipsShift);
//---- first positions skipped when drawing
   SetIndexDrawBegin(0,JawsShift+JawsPeriod);
   SetIndexDrawBegin(1,TeethShift+TeethPeriod);
   SetIndexDrawBegin(2,LipsShift+LipsPeriod);
//---- 3 indicator buffers mapping
   SetIndexBuffer(0,ExtBlueBuffer);
   SetIndexBuffer(1,ExtRedBuffer);
   SetIndexBuffer(2,ExtLimeBuffer);
//---- drawing settings
   SetIndexStyle(0,DRAW_LINE);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexStyle(2,DRAW_LINE);
//---- index labels
   SetIndexLabel(0,"Gator Jaws");
   SetIndexLabel(1,"Gator Teeth");
   SetIndexLabel(2,"Gator Lips");
//---- initialization done
   return(0);
  }

SetIndexStyle()

void SetIndexStyle(int index, int type, int style=EMPTY, 
                   int width=EMPTY, color clr=CLR_NONE)

Sets offset for the drawing line. For positive values, the line drawing will be shifted to the right, otherwise it will be shifted to the left. I.e., the value calculated on the current bar will be drawn shifted relatively to the current bar.

Parameters:

index - Line index. Must lie between 0 and 7. 
type  - Shape style. Can be one of Drawing shape styles listed. 
style - Drawing style. It is used for one-pixel thick lines. 
        It can be one of the Drawing shape styles listed. 
        EMPTY value means that the style will not be changed. 
width - Line width. Valid values are: 1,2,3,4,5. 
        EMPTY value means that width will not be changed. 
clr   - Line color. Absence of this parameter means that the color will not be changed. 

Sample:

  SetIndexStyle(3, DRAW_LINE, EMPTY, 2, Red);

SetLevelStyle()

void SetLevelStyle(int draw_style, int line_width, color clr=CLR_NONE)

The function sets a new style, width and color of horizontal levels of indicator to be output in a separate window.

Parameters:

draw_style - Drawing style. Can be one of the Drawing shape styles listed. 
             EMPTY value means that the style will not be changed. 
line_width - Line width. Valid values are 1,2,3,4,5. 
             EMPTY value indicates that the width will not be changed. 
clr        - Line color. Empty value CLR_NONE means that the color will not be changed. 

Sample:

//---- show levels as thick red lines
   SetLevelStyle(STYLE_SOLID,2,Red);

SetLevelValue()

void SetLevelValue(int level, double value)

The function sets a value for a given horizontal level of the indicator to be output in a separate window.

Parameters:

level - Level index (0-31). 
value - Value for the given indicator level. 

Sample:

SetLevelValue(1,3.14);
This article url: http://www.myeatrade.com/440/

Please login to post comment, if you haven't account you can register free