Timeframe Help - page 2

 
//+------------------------------------------------------------------+
//|                                                          CCi.mq4 |
//|                      Copyright © 2010, MetaQuotes Software Corp. |
//|                                        https://www.metaquotes.net// |
//+------------------------------------------------------------------+
#property  copyright "Copyright © 2005, MetaQuotes Software Corp."
#property  link      "https://www.metaquotes.net//"
//---- indicator settings
#property  indicator_separate_window
#property  indicator_buffers 3
extern int CCIPeriod=14;
extern int TimeFrame=60;  //1=1minute;5=5minutes;15=15minutes;30=30minutes;60=1Hour;240=4Hour;1440=Daily; 
//---- indicator buffers
double     ExtBuffer0[];
double     ExtBuffer1[];
double     ExtBuffer2[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- drawing settings
   SetLevelStyle(STYLE_DOT,1,LightSlateGray); 
   SetLevelValue(0,-100); 
   SetLevelValue(1, 100); 
   SetIndexStyle(0,DRAW_NONE);
   SetIndexStyle(1,DRAW_HISTOGRAM,STYLE_SOLID,2,Green);
   SetIndexStyle(2,DRAW_HISTOGRAM,STYLE_SOLID,2,Red);
   IndicatorDigits(Digits+1);
   SetIndexDrawBegin(0,21);
   SetIndexDrawBegin(1,21);
   SetIndexDrawBegin(2,21);
//---- 3 indicator buffers mapping
   SetIndexBuffer(0,ExtBuffer0);
   SetIndexBuffer(1,ExtBuffer1);
   SetIndexBuffer(2,ExtBuffer2);
//---- name for DataWindow and indicator subwindow label
   switch(TimeFrame)
     {
      case 1 : string TimeFrameStr="Period_M1"; break;
      case 5 : TimeFrameStr="Period_M5"; break;
      case 15 : TimeFrameStr="Period_M15"; break;
      case 30 : TimeFrameStr="Period_M30"; break;
      case 60 : TimeFrameStr="Period_H1"; break;
      case 240 : TimeFrameStr="Period_H4"; break;
      case 1440 : TimeFrameStr="Period_D1"; break;
      case 10080 : TimeFrameStr="Period_W1"; break;
      case 43200 : TimeFrameStr="Period_MN1"; break;
      default : TimeFrameStr="Current Timeframe";
     }
   IndicatorShortName("CCI "+TimeFrameStr+"("+CCIPeriod+")");
   SetIndexLabel(1,ExtBuffer0);
   SetIndexLabel(2,ExtBuffer0);
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Commodity Channel Index                                          |
//+------------------------------------------------------------------+
int start()
  {
   int      i;
   double   prev,current;
   double   Buffer[1000];
   double   CCI   [1000];
//---- last counted bar will be recounted
   int   limit=ArraySize(Buffer);
   ArraySetAsSeries(Buffer,true);
  
   for(i=0; i<limit; i++)
   Buffer[i]=iClose(NULL,TimeFrame,i);   
//---- cci
   for(i=0; i<limit; i++)
   CCI[i]=iCCIOnArray(Buffer,limit,CCIPeriod,i);
//---- dispatch values between 2 buffers
   bool up=true;
   for(i=limit-1; i>=0; i--)
     {
      current=CCI[i];
      prev=CCI[i+1];
      if(current>prev && current>-100) up=true;
      if(current<prev && current<100) up=false;
      if(!up)
        {
         ExtBuffer2[i]=current;
         ExtBuffer1[i]=0.0;
        }
      else
        {
         ExtBuffer1[i]=current;
         ExtBuffer2[i]=0.0;
        }
     }
//---- done
   return(0);
  }
Reason: