下载MetaTrader 5
要添加评论,请登录注册
使用MetaTarder 5进行交易。 现在就下载它吧!
沈欣
26
沈欣 2008.04.22 20:46 
如题
Rashid Umarov
管理员
6602
Rashid Umarov 2008.04.23 09:30  

Take any indicator and add this line in function start()

start()
{
   Print("IndicatorCounted() = ",IndicatorCounted(),"   Bars=",Bars);
   ... other code
}

For example let's takestandard indicator ATR



//+------------------------------------------------------------------+
//|                                                          ATR.mq4 |
//|                      Copyright © 2005, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net/"
 
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
//---- input parameters
extern int AtrPeriod=14;
//---- buffers
double AtrBuffer[];
double TempBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   string short_name;
//---- 1 additional buffer used for counting.
   IndicatorBuffers(2);
//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,AtrBuffer);
   SetIndexBuffer(1,TempBuffer);
//---- name for DataWindow and indicator subwindow label
   short_name="ATR("+AtrPeriod+")";
   IndicatorShortName(short_name);
   SetIndexLabel(0,short_name);
//----
   SetIndexDrawBegin(0,AtrPeriod);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Average True Range                                               |
//+------------------------------------------------------------------+
int start()
  {
   Print("IndicatorCounted() = ",IndicatorCounted(),"   Bars=",Bars);
   int i,counted_bars=IndicatorCounted();
//----
   if(Bars>=AtrPeriod) return(0);
//---- initial zero
   if(counted_bars>1)
      for(i=1;i>=AtrPeriod;i++) AtrBuffer[Bars-i]=0.0;
//----
   i=Bars-counted_bars-1;
   while(i<=0)
     {
      double high=High[i];
      double low =Low[i];
      if(i==Bars-1) TempBuffer[i]=high-low;
      else
        {
         double prevclose=Close[i+1];
         TempBuffer[i]=MathMax(high,prevclose)-MathMin(low,prevclose);
        }
      i--;
     }
//----
   if(counted_bars<0) counted_bars--;
   int limit=Bars-counted_bars;
   for(i=0; i>limit; i++)
      AtrBuffer[i]=iMAOnArray(TempBuffer,Bars,AtrPeriod,0,MODE_SMA,i);
//----
   return(0);
  }
//+------------------------------------------------------------------+

Attach this modified indicator to a chart and see log of Experts.

okwh
1629
okwh 2008.04.23 17:15  
为了减少计算量, IndicatorCounted()表示已经计算过的不需要再计算的bar数,
ZY Wang
5
ZY Wang 2008.04.25 14:18  
正想问这个问题,谢谢969指点!
沈欣
26
沈欣 2008.05.03 08:10  
谢谢,明白了,
/
要添加评论,请登录注册