自定義指標函數(shù) [Custom Indicator Functions]
void IndicatorBuffers(int count) 設(shè)置自定義指標緩存數(shù)
:: 輸入?yún)?shù) count - 緩存數(shù)量
示例:
#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() 返回緩存數(shù)量 示例:
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) 設(shè)置指標精確度
:: 輸入?yún)?shù) digits - 小數(shù)點后的小數(shù)位數(shù)
示例:
#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) 設(shè)置指標的簡稱
:: 輸入?yún)?shù) 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) 在指標上設(shè)置一個箭頭符號
:: 輸入?yún)?shù) index - 第幾根指標線 0-7 code - 符號的編碼,,參照 Wingdings 字體
示例:
bool SetIndexBuffer( int index, double array[]) 設(shè)置指標線的緩存數(shù)組
:: 輸入?yún)?shù) index - 第幾根指標線 0-7 array[] - 緩存的數(shù)組
示例:
double ExtBufferSilver[]; int init() { SetIndexBuffer(0, ExtBufferSilver); // set buffer for first line // ... }
void SetIndexDrawBegin( int index, int begin) 設(shè)置劃線的開始點
:: 輸入?yún)?shù) 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) 設(shè)置劃線的空值,,空值不劃在和出現(xiàn)在數(shù)據(jù)窗口
:: 輸入?yún)?shù) index - 第幾根指標線 0-7 value - 新的空值
示例:
SetIndexEmptyValue(6,0.0001);
void SetIndexLabel( int index, string text) 設(shè)置指標線的名稱
:: 輸入?yún)?shù) index - 第幾根指標線 0-7 text - 線的名稱,,Null不會顯示在數(shù)據(jù)窗口中
示例:
//+------------------------------------------------------------------+ //| 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) 設(shè)置指標線的位移數(shù)
:: 輸入?yún)?shù) 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); 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); }
void SetIndexStyle( int index, int type, int style=EMPTY, int width=EMPTY, color clr=CLR_NONE) 設(shè)置指標線的樣式
:: 輸入?yún)?shù) index - 第幾根指標線 0-7 type - 線形狀的種類,,詳見線條種類 style - 劃線的樣式 width - 顯得寬度(1,2,3,4,5) clr - 線的顏色
示例:
SetIndexStyle(3, DRAW_LINE, EMPTY, 2, Red);
|