基础知识

MT4编程参考四

字号+ 作者: 来源: 12-06 我要评论( )

string Symbol()

返回当前当前通货的名称

示例:

int total=OrdersTotal();

for(int pos=0;pos<TOTAL;POS++)

{

// check selection result becouse order may be closed or deleted at this time!

if(OrderSelect(pos, SELECT_BY_POS)==false) continue;

if(OrderType()>OP_SELL || OrderSymbol()!=Symbol()) continue;

// do some orders processing...

}

int UninitializeReason()

取得程序末初始化的理由

示例:

// this is example

int deinit()

{

switch(UninitializeReason())

{

case REASON_CHARTCLOSE:

case REASON_REMOVE: CleanUp(); break; // clean up and free all expert's resources.

case REASON_RECOMPILE:

case REASON_CHARTCHANGE:

case REASON_PARAMETERS:

case REASON_ACCOUNT: StoreData(); break; // prepare to restart

}

//...

}

自定义指标函数 [Custom Indicator Functions]

void IndicatorBuffers(int count)

设置自定义指标缓存数

:: 输入参数

count - 缓存数量

示例:

#property indicator_separate_window

#property indicator_buffers 1

#property indicator_color1 Silver

//---- indicator parameters

extern int FastEMA=12;

extern int SlowEMA=26;

extern int SignalSMA=9;

//---- indicator buffers

double ind_buffer1[];

double ind_buffer2[];

double ind_buffer3[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

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);

}

int IndicatorCounted()

返回缓存数量

示例:

int start()

{

int limit;

int counted_bars=IndicatorCounted();

//---- check for possible errors

if(counted_bars<0) return(-1);

//---- last counted bar will be recounted

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

//---- main loop

for(int i=0; i

{

//---- ma_shift set to 0 because SetIndexShift called abowe

ExtBlueBuffer[i]=iMA(NULL,0,JawsPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);

ExtRedBuffer[i]=iMA(NULL,0,TeethPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);

ExtLimeBuffer[i]=iMA(NULL,0,LipsPeriod,0,MODE_SMMA,PRICE_MEDIAN,i);

}

//---- done

return(0);

}

void IndicatorDigits( int digits)

设置指标精确度

:: 输入参数

digits - 小数点后的小数位数

示例:

#property indicator_separate_window

#property indicator_buffers 1

#property indicator_color1 Silver

//---- indicator parameters

extern int FastEMA=12;

extern int SlowEMA=26;

extern int SignalSMA=9;

//---- indicator buffers

double ind_buffer1[];

double ind_buffer2[];

double ind_buffer3[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

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);

}

void IndicatorShortName( string name)

设置指标的简称

:: 输入参数

name - 新的简称

示例:

#property indicator_separate_window

#property indicator_buffers 1

#property indicator_color1 Silver

//---- indicator parameters

extern int FastEMA=12;

extern int SlowEMA=26;

extern int SignalSMA=9;

//---- indicator buffers

double ind_buffer1[];

double ind_buffer2[];

double ind_buffer3[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

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);

}

void SetIndexArrow( int index, int code)

在指标上设置一个箭头符号

:: 输入参数

index - 第几根指标线 0-7

code - 符号的编码,参照 Wingdings 字体

示例:

SetIndexArrow(0, 217);

bool SetIndexBuffer( int index, double array[])

设置指标线的缓存数组

:: 输入参数

index - 第几根指标线 0-7

array[] - 缓存的数组

示例:

double ExtBufferSilver[];

int init()

{

SetIndexBuffer(0, ExtBufferSilver); // set buffer for first line

// ...

}

void SetIndexDrawBegin( int index, int begin)

设置划线的开始点

:: 输入参数

index - 第几根指标线 0-7

begin - 划线的开始点

示例:

#property indicator_separate_window

#property indicator_buffers 1

#property indicator_color1 Silver

//---- indicator parameters

extern int FastEMA=12;

extern int SlowEMA=26;

extern int SignalSMA=9;

//---- indicator buffers

double ind_buffer1[];

double ind_buffer2[];

double ind_buffer3[];

//+------------------------------------------------------------------+

//| Custom indicator initialization function |

//+------------------------------------------------------------------+

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);

}

void SetIndexEmptyValue( int index, double value)

设置划线的空值,空值不划在和出现在数据窗口

:: 输入参数

index - 第几根指标线 0-7

value - 新的空值

示例:

SetIndexEmptyValue(6,0.0001);

void SetIndexLabel( int index, string text)

设置指标线的名称

:: 输入参数

index - 第几根指标线 0-7

text - 线的名称,Null不会显示在数据窗口中

示例:

//+------------------------------------------------------------------+

//| 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 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);

}

void SetIndexShift( int index, int shift)

设置指标线的位移数

:: 输入参数

index - 第几根指标线 0-7

shift - 位移多少

示例:

//+------------------------------------------------------------------+

//| 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);

<P class=MsoNormal style="MARGIN

转载请注明出处。

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

{dede:myad name='artice_ad_01'/}
相关文章
  • 第三代移动平均线 MetaTrader 指标

    2016-11-30 15:02

  • Aroon Up & Down指标

    2016-11-30 15:56

  • MetaTrader4指标 BB MACD指标

    2016-11-30 16:00

  • Beginner MetaTrader

    2016-11-30 16:00