Navigation:Home > Content >

CHO.mq4

Time: 2015-06-09 | Download file:CHO.mq4

//+------------------------------------------------------------------+
//|                                                          CHO.mq4 |
//|                                                       MetaQuotes |
//|                 http://forum.alpari-idc.ru/viewtopic.php?t=48186 |
//+------------------------------------------------------------------+
#property copyright "MetaQuotes"
#property link      "http://forum.alpari-idc.ru/viewtopic.php?t=48186"

#property  indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 Red
//---- input parameters
extern int       SlowPeriod=10;
extern int       FastPeriod=3;
//---- buffers
double CHO[];
double FastSMA[];
double SlowSMA[];
double VA[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   string name;
   name="Chaikin("+SlowPeriod+","+FastPeriod+")";
   IndicatorBuffers(4);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,CHO);
   SetIndexLabel(0,name);
   SetIndexEmptyValue(0,0.0);
   SetIndexBuffer(1,FastSMA);
   SetIndexEmptyValue(1,0.0);
   SetIndexBuffer(2,SlowSMA);
   SetIndexEmptyValue(2,0.0);
   SetIndexBuffer(3,VA);
   SetIndexEmptyValue(3,0.0);
   IndicatorShortName(name);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int limit,i,m,n;
   double delta;
//----
   if (counted_bars<0) return(-1); // по привычке

   if (counted_bars==0) 
      {
      limit=Bars-1;
      for (i=limit;i>=0;i--)
         {
         delta=High[i]-Low[i];
         if(delta>Point) VA[i]=(2*Close[i]-High[i]-Low[i])/delta*Volume[i]; else VA[i]=0.0;     
         }
      for (m=limit-FastPeriod+1;m>=0;m--)
         {
         FastSMA[m]=iMAOnArray(VA,Bars,FastPeriod,0,MODE_SMA,m);
         }
      for (m=limit-SlowPeriod+1;m>=0;m--)
         {
         SlowSMA[m]=iMAOnArray(VA,Bars,SlowPeriod,0,MODE_SMA,m);
         }
      for(n=limit-SlowPeriod;n>=0;n--)
         {
         CHO[n]=SlowSMA[n]-FastSMA[n];
         }
      }

   if (counted_bars>0) 
      {
      limit=Bars-counted_bars-1;
      for (i=limit;i>=0;i--)
         {
         delta=High[i]-Low[i];
         if(delta>Point) VA[i]=(2*Close[i]-High[i]-Low[i])/delta*Volume[i]; else VA[i]=0.0;     
         }
      for (m=limit;m>=0;m--)
         {
         FastSMA[m]=iMAOnArray(VA,Bars,FastPeriod,0,MODE_SMA,m);
         SlowSMA[m]=iMAOnArray(VA,Bars,SlowPeriod,0,MODE_SMA,m);
         }
      for(n=limit;n>=0;n--)
         {
         CHO[n]=SlowSMA[n]-FastSMA[n];
         }
      }            
//----
   return(0);
  }
//+------------------------------------------------------------------+

Recommend