//+------------------------------------------------------------------+
//|                                    CCI-Current-Divergence-v1.mq4 |
//|                                 Copyright © 2011, Carl Rodriguez |
//|                                   http://www.marketcycle-360.com |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2011, Carl Rodriguez"
#property link      "http://www.marketcycle-360.com"

#property indicator_chart_window

// To-Do:
// 
// improve arrow routine into a single subroutine to handle all timeframes
// improve alart routine into a single subroutine to handle all timeframes
//
// (arrows sometimes seem random, especially during slow market hours: possible filters below)
//
// add triangular-ma envelope filter for arrows
// add option to only look for CCI divergences (price divergences seem useless)
// add CCp routine to look for currency strength divergences
// add option to include CCp strength in filtering arrows
//
double cci1, cci5, cci15,cci30,cci60,cci240,cci1440,cciw,ccim;
double cci1p, cci5p, cci15p, cci30p, cci60p, cci240p, cci1440p,cciwp, ccimp;
int color1, color5, color15, color30, color60, color240, color1440, colorw, colorm;
string status1;
datetime alert1,alert5,alert15,alert30,alert60,alert240,alert1440,alertw, alertm;
datetime arr1,arr5,arr15,arr30,arr60,arr240,arr1440,arrw,arrm;
datetime PorAlert1, PorAlert2, PorAlert3;
double point;
string Porfirio1, Porfirio2, Porfirio3;

extern string Set_CCI_Parameter ="";
extern int ccip = 14;
extern string Porfirio_Strategy = "";
extern bool WatchForPorfirio = true;
extern string Set_TimeFrame_Alarms = "";
extern bool Alarm_1m = false;
extern bool Alarm_5m = true;
extern bool Alarm_15m = true;
extern bool Alarm_30m = false;
extern bool Alarm_1h = false;
extern bool Alarm_4h = false;
extern bool Alarm_1d = false;
extern bool Alarm_1w = false;
extern bool Alarm_m1 = false;
extern string Set_TimeFrame_Arrows = "";
extern bool Arrow_1m = true;
extern bool Arrow_5m = true;
extern bool Arrow_15m = true;
extern bool Arrow_30m = true;
extern bool Arrow_1h = true;
extern bool Arrow_4h = true;
extern bool Arrow_1d = true;
extern bool Arrow_1w = true;
extern bool Arrow_m1 = true;
extern string Text_Color = "";
extern color TextColor = Yellow;
extern color HeaderColor = Yellow;
extern color Up_CCI_Color = Green;
extern color Down_CCI_Color = Red;

int init()
  {
   if(Digits==3 || Digits==5) point = Point * 10;
   else point = Point;
   
      DrawText("EU",10,12,TextColor,10,"Ariel",StringConcatenate(Symbol()," - ",TimeLeft()),true);
      DrawText("EU1",10,30,TextColor,10,"Ariel","1-min",true);
      DrawText("EU5",10,50,TextColor,10,"Ariel","5-min",true);
      DrawText("EU15",10,70,TextColor,10,"Ariel","15-min",true);
      DrawText("EU30",10,90,TextColor,10,"Ariel","30-min",true);
      DrawText("EU60",10,110,TextColor,10,"Ariel","1-Hr",true);
      DrawText("EU4H",10,130,TextColor,10,"Ariel","4-Hr",true);
      DrawText("EU1D",10,150,TextColor,10,"Ariel","1-Day",true);
      DrawText("EU1W",10,170,TextColor,10,"Ariel","1-Wk",true);
      DrawText("EU1M",10,190,TextColor,10,"Ariel","1-Mo",true);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//---- Nothing here yet.
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int x = 60; // for position of text
   
   header();
   
   DrawText("S1",x+55,30,TextColor,10,"Ariel",PriceDiv(1),true); // 1-min price divergence status
   DrawText("S5",x+55,50,TextColor,10,"Ariel",PriceDiv(5),true); // 5-min price divergence status
   DrawText("S15",x+55,70,TextColor,10,"Ariel",PriceDiv(15),true);  // 15-min price divergence status
   DrawText("S30",x+55,90,TextColor,10,"Ariel",PriceDiv(30),true); // 30-min
   DrawText("S60",x+55,110,TextColor,10,"Ariel",PriceDiv(60),true);  // 60-min
   DrawText("S240",x+55,130,TextColor,10,"Ariel",PriceDiv(240),true);  // 4-hr
   DrawText("S1440",x+55,150,TextColor,10,"Ariel",PriceDiv(1440),true); // 1-day
   DrawText("S1w",x+55,170,TextColor,10,"Ariel",PriceDiv(PERIOD_W1),true); // 1-wk
   DrawText("S1m",x+55,190,TextColor,10,"Ariel",PriceDiv(PERIOD_MN1),true); // 1-mo
   
   DrawText("C1",x+255,30,TextColor,10,"Ariel",CCIDiv(1),true); // 1-min CCI divergence
   DrawText("C5",x+255,50,TextColor,10,"Ariel",CCIDiv(5),true); // 5-min CCI divergence
   DrawText("C15",x+255,70,TextColor,10,"Ariel",CCIDiv(15),true); // 15-min
   DrawText("C30",x+255,90,TextColor,10,"Ariel",CCIDiv(30),true); // 30-min
   DrawText("C60",x+255,110,TextColor,10,"Ariel",CCIDiv(60),true); // 60-min
   DrawText("C240",x+255,130,TextColor,10,"Ariel",CCIDiv(240),true); // 4-hr
   DrawText("C1440",x+255,150,TextColor,10,"Ariel",CCIDiv(1440),true); // 1-day
   DrawText("C1w",x+255,170,TextColor,10,"Ariel",CCIDiv(PERIOD_W1),true); // 1-wk
   DrawText("C1m",x+255,190,TextColor,10,"Ariel",CCIDiv(PERIOD_MN1),true); // 1-mo
   
   if(Alarm_1m == true) Alarm1(); // check for alarms if allowed
   if(Alarm_5m == true) Alarm5();
   if(Alarm_15m == true) Alarm15();
   
   if(Arrow_1m == true) Arrow1(); // draw arrows in each timeframe if allowed
   if(Arrow_5m == true) Arrow5();
   if(Arrow_15m == true) Arrow15();
   if(Arrow_30m == true) Arrow30();
   if(Arrow_1h == true) Arrow60();
   if(Arrow_4h == true) Arrow240();
   if(Arrow_1d == true) Arrow1440();
   if(Arrow_1w == true) Arrow1w();
   if(Arrow_m1 == true) Arrow1m();

// ----------------------------------------------------  Porfirio logic
   if(WatchForPorfirio==true) {
      Porfirio1 = " "; Porfirio2 = " "; Porfirio3 = " ";
      if(cci15>=0 && cci5<-100) {
         Porfirio1 = Symbol()+"-Porfirio Buy Setup m15-m5-m1: Watch m1 for Divergence"; 
         if(PorAlert1 != iTime(NULL,15,0)) {
            Alert(Porfirio1); PorAlert1 = iTime(NULL,15,0); 
            }
         }
      if(cci15<=0 && cci5>100) {
         Porfirio1 = Symbol()+"-Porfirio Sell Setup m15-m5-m1: Watch m1 for Divergence"; 
         if(PorAlert1 != iTime(NULL,15,0)) {
            Alert(Porfirio1); PorAlert1 = iTime(NULL,15,0);
            }
         }
         
      if(cci60>=0 && cci15<-100) {
         Porfirio2 = Symbol()+"-Porfirio Buy Setup H1-m15-m5: Watch m5 for Divergence"; 
         if(PorAlert2 != iTime(NULL,15,0)) {
            Alert(Porfirio2); PorAlert2 = iTime(NULL,15,0);
            }
         }
      if(cci60<=0 && cci15>100) {
         Porfirio2 = Symbol()+"-Porfirio Sell Setup H1-m15-m5: Watch m5 for Divergence"; 
         if(PorAlert2 != iTime(NULL,15,0)) {
            Alert(Porfirio2); PorAlert2 = iTime(NULL,15,0);
            }
         }
         
      if(cci240>=0 && cci60<-100) {
         Porfirio3 = Symbol()+"-Porfirio Buy Setup H4-H1-m15: Watch m15 for Divergence"; 
         if(PorAlert3 != iTime(NULL,15,0)) {
            Alert(Porfirio3); PorAlert3 = iTime(NULL,15,0);
            }
         }
      if(cci240<=0 && cci60>100) {
         Porfirio3 = Symbol()+"-Porfirio Sell Setup H4-H1-m15: Watch m15 for Divergence"; 
         if(PorAlert3 != iTime(NULL,15,0)) {
            Alert(Porfirio3); PorAlert3 = iTime(NULL,15,0);
            }
         }
      
      DrawText("PCCI15",10,230,TextColor,10,"Ariel",Porfirio1,true);
      DrawText("PCCIH",10,250,TextColor,10,"Ariel",Porfirio2,true);
      DrawText("PCCI4H",10,270,TextColor,10,"Ariel",Porfirio3,true);
      
      }
      
   return(0);
  }
//+---------------------------------------------- Find last low from idx bar 
int LastZZLow(int timframe, int idx)
{
   for(int g=idx; g<500; g++){
      if(iLow(NULL,timframe,g-1) > iLow(NULL,timframe,g) && iLow(NULL,timframe,g)<iLow(NULL,timframe,g+1)) {
         return(g);
         }
      }
   return(0);
}
//----------------------------------------------- Find last high from idx bar
int LastZZHigh(int timframe, int idx)
{
   for(int h=idx; h<100; h++){
      if(iHigh(NULL,timframe,h-1) < iHigh(NULL,timframe,h) && iHigh(NULL,timframe,h)>iHigh(NULL,timframe,h+1)) {
         return(h);
         }
      }
   return(0);
}
//------------------------------------------------ Find last CCI low trough from idx
int CCILastZZLow(int timeframe, int idx)
{
   for(int g=idx; g<500; g++) {
      if(iCCI(NULL,timeframe,ccip,PRICE_TYPICAL,g-1)>iCCI(NULL,timeframe,ccip,PRICE_TYPICAL,g) && iCCI(NULL,timeframe,ccip,PRICE_TYPICAL,g)<iCCI(NULL,timeframe,ccip,PRICE_TYPICAL,g+1)) {
         return(g);
         }
      }
   return(0);
}
//-------------------------------------------------- Find last CCI high peak from idx
int CCILastZZHigh(int timeframe, int idx)
{
   for(int g=idx; g<500; g++) {
      if(iCCI(NULL,timeframe,ccip,PRICE_TYPICAL,g-1)<iCCI(NULL,timeframe,ccip,PRICE_TYPICAL,g) && iCCI(NULL,timeframe,ccip,PRICE_TYPICAL,g)>iCCI(NULL,timeframe,ccip,PRICE_TYPICAL,g+1)) {
         return(g);
         }
      }
   return(0);
}
//---------------------------------------------------- Draw text routine
void DrawText(string oname, int x, int y, color Color, int fontSize, string font, string text, bool shadow)
{
   
   string name = oname+".";
   ObjectDelete(name);
   ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
   ObjectSet(name, OBJPROP_XDISTANCE, x);
   ObjectSet(name, OBJPROP_YDISTANCE, y);
   ObjectSet(name, OBJPROP_COLOR, Color);
   ObjectSet(name, OBJPROP_BACK, false);
   ObjectSetText(name,text,fontSize,font);
      
   name = oname;
   ObjectDelete(name);
   
   if (!shadow) return;
   
   ObjectCreate(name, OBJ_LABEL, 0, 0, 0);
   ObjectSet(name, OBJPROP_XDISTANCE, x+1);
   ObjectSet(name, OBJPROP_YDISTANCE, y+1);
   ObjectSet(name, OBJPROP_COLOR, Black);
   ObjectSet(name, OBJPROP_BACK, false);
   ObjectSetText(name,text,fontSize,font);
}
//----------------------------------------------------- Time left in current bar for header 
string TimeLeft()
{
   string tl;
	double i;
   int m,s,k;
   m=Time[0]+Period()*60-CurTime();
   i=m/60.0;
   s=m%60;
   m=(m-m%60)/60;
   tl=StringConcatenate(m," minutes ",s," seconds left to bar end");
   
   return(tl);
}
//------------------------------------------------------- Draw all CCI numbers for all timeframs
void header()
{
   int x = 60;
   
   DrawText("EU",10,12,HeaderColor,10,"Ariel",StringConcatenate(Symbol()," - ",TimeLeft()),true);
   
   cci1 = iCCI(NULL,1, ccip, PRICE_TYPICAL,0);
   cci1p = iCCI(NULL,1, ccip, PRICE_TYPICAL,1);
   if(cci1p>cci1) color1 = Down_CCI_Color;
   else color1 = Up_CCI_Color;
   DrawText("CCI1",x,30,color1,10,"Ariel",DoubleToStr(cci1,2),true);
   
   cci5 = iCCI(NULL,5, ccip, PRICE_TYPICAL,0);
   cci5p = iCCI(NULL,5, ccip, PRICE_TYPICAL,1);
   if(cci5p>cci5) color5 = Down_CCI_Color;
   else color5 = Up_CCI_Color;
   DrawText("CCI5",x,50,color5,10,"Ariel",DoubleToStr(cci5,2),true);
   
   cci15 = iCCI(NULL,15, ccip, PRICE_TYPICAL,0);
   cci15p = iCCI(NULL,15, ccip, PRICE_TYPICAL,1);
   if(cci15p>cci15) color15 = Down_CCI_Color;
   else color15 = Up_CCI_Color;
   DrawText("CCI15",x,70,color15,10,"Ariel",DoubleToStr(cci15,2),true);   

   cci30 = iCCI(NULL,30, ccip, PRICE_TYPICAL,0);
   cci30p = iCCI(NULL,30, ccip, PRICE_TYPICAL,1);
   if(cci30p>cci30) color30 = Down_CCI_Color;
   else color30 = Up_CCI_Color;
   DrawText("CCI30",x,90,color30,10,"Ariel",DoubleToStr(cci30,2),true);   

   cci60 = iCCI(NULL,60, ccip, PRICE_TYPICAL,0);
   cci60p = iCCI(NULL,60, ccip, PRICE_TYPICAL,1);
   if(cci60p>cci60) color60 = Down_CCI_Color;
   else color60 = Up_CCI_Color;
   DrawText("CCI60",x,110,color60,10,"Ariel",DoubleToStr(cci60,2),true);

   cci240 = iCCI(NULL,240, ccip, PRICE_TYPICAL,0);
   cci240p = iCCI(NULL,240, ccip, PRICE_TYPICAL,1);
   if(cci240p>cci240) color240 = Down_CCI_Color;
   else color240 = Up_CCI_Color;
   DrawText("CCI240",x,130,color240,10,"Ariel",DoubleToStr(cci240,2),true);
   
   cci1440 = iCCI(NULL,1440, ccip, PRICE_TYPICAL,0);
   cci1440p = iCCI(NULL,1440, ccip, PRICE_TYPICAL,1);
   if(cci1440p>cci1440) color1440 = Down_CCI_Color;
   else color1440 = Up_CCI_Color;
   DrawText("CCI1440",x,150,color1440,10,"Ariel",DoubleToStr(cci1440,2),true);
   
   cciw = iCCI(NULL,PERIOD_W1,ccip,PRICE_TYPICAL,0);
   cciwp = iCCI(NULL,PERIOD_MN1,ccip,PRICE_TYPICAL,1);
   if(cciwp>cciw) colorw = Down_CCI_Color;
   else colorw = Up_CCI_Color;
   DrawText("CCIw",x,170,colorw,10,"Ariel",DoubleToStr(cciw,2),true);
   
   ccim = iCCI(NULL, PERIOD_MN1, ccip,PRICE_TYPICAL,0);
   ccimp = iCCI(NULL,PERIOD_MN1, ccip,PRICE_TYPICAL,1);
   if(ccimp>ccim) colorm = Down_CCI_Color;
   else colorm = Up_CCI_Color;
   DrawText("CCIm",x,190,colorm,10,"Ariel",DoubleToStr(ccim,2),true);
   
   return(0);
}
//--------------------------------------------------------------- Check for price divergence with CCI (commented out hidden divergence)
string PriceDiv(int timeframe)
{
   int lw1 = LastZZLow(timeframe,2);
   int h1 = LastZZHigh(timeframe,2);
   status1 = StringConcatenate("NPD (L",lw1,", H",h1,")");

   double lcci1 = iCCI(NULL,timeframe,ccip,PRICE_TYPICAL,lw1);
   double hcci1 = iCCI(NULL,timeframe,ccip,PRICE_TYPICAL,h1);
   double ccinow = iCCI(NULL,timeframe,ccip,PRICE_TYPICAL,0);
   
   if(iLow(NULL,timeframe,0)<iLow(NULL,timeframe,lw1) && ccinow > lcci1) status1 = StringConcatenate("Pending Price Bullish Div. (L",lw1,")");
   if(iHigh(NULL,timeframe,0)>iHigh(NULL,timeframe,h1) && ccinow < hcci1) status1 = StringConcatenate("Pending Price Bearish Div. (H",h1,")");
   //if(Low[0]>iLow(NULL,1,lw1) && cci1 < lcci1) status1 = StringConcatenate("Pending Hidden Bullish Divergence (",lw1,")");
   //if(High[0]<iHigh(NULL,1,h1) && cci1 > lcci1) status1 = StringConcatenate("Pending Hidden Bearish Divergence (",h1,")");
   
   return(status1);
}

//---------------------------------------------------------------- Check for CCI divergence with price
string CCIDiv(int timeframe)
{
   int lw1 = CCILastZZLow(timeframe,2);
   int h1 = CCILastZZHigh(timeframe,2);
   status1 = StringConcatenate("NCD (L",lw1,", H",h1,")");
   
   double lcci1 = iLow(NULL,timeframe,0);
   double hcci1 = iHigh(NULL,timeframe,0);
   double ccinow = iCCI(NULL,timeframe,ccip,PRICE_TYPICAL,0);
   
   if(iCCI(NULL,timeframe,ccip,PRICE_TYPICAL,lw1) < ccinow && lcci1 < iLow(NULL,timeframe,lw1)) status1=StringConcatenate("Pending CCI Bullish Div. (L",lw1,")");
   if(iCCI(NULL,timeframe,ccip,PRICE_TYPICAL,h1) > ccinow && hcci1 > iHigh(NULL,timeframe,h1)) status1=StringConcatenate("Pending CCI Bearish Div. (H",h1,")");
   
   return(status1);
}
//---------------------------------------------- 1-min Arrow
void Arrow1()
{
   int ao = 3;
   int tf = 1;
   string name;
   
   if(arr1 != iTime(NULL,tf,0)) {
      if(StringFind(CCIDiv(tf),"NCD") < 0) {
         arr1 = iTime(NULL,tf,0);
         if(StringFind(CCIDiv(tf),"Bullish") > 0) {
            name = "ArrowBullish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iLow(NULL,tf,0)-(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_M1);
            ObjectSet(name, OBJPROP_COLOR, Green);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         if(StringFind(CCIDiv(tf),"Bearish") > 0) {
            name = "ArrowBearish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iHigh(NULL,tf,0)+(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_M1);
            ObjectSet(name, OBJPROP_COLOR, Red);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         }
      if(StringFind(PriceDiv(tf),"NPD") < 0) {
         arr1 = iTime(NULL,tf,0);
         if(StringFind(PriceDiv(tf),"Bullish") > 0) {
            name = "ArrowBullish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iLow(NULL,tf,0)-(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_M1);
            ObjectSet(name, OBJPROP_COLOR, Green);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         if(StringFind(PriceDiv(tf),"Bearish") > 0) {
            name = "ArrowBearish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iHigh(NULL,tf,0)+(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_M1);
            ObjectSet(name, OBJPROP_COLOR, Red);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         }
      }
   return(0);
}
//--------------------------------------------------------- 5-min arrow
void Arrow5()
{
   int ao = 5;
   int tf = 5;
   string name;
   
   if(arr5 != iTime(NULL,tf,0)) {
      if(StringFind(CCIDiv(tf),"NCD") < 0) {
         arr5 = iTime(NULL,tf,0);
         if(StringFind(CCIDiv(tf),"Bullish") > 0) {
            name = "ArrowBullish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iLow(NULL,tf,0)-(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_M5);
            ObjectSet(name, OBJPROP_COLOR, Green);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         if(StringFind(CCIDiv(tf),"Bearish") > 0) {
            name = "ArrowBearish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iHigh(NULL,tf,0)+(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_M5);
            ObjectSet(name, OBJPROP_COLOR, Red);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         }
      if(StringFind(PriceDiv(tf),"NPD") < 0) {
         arr5 = iTime(NULL,tf,0);
         if(StringFind(PriceDiv(tf),"Bullish") > 0) {
            name = "ArrowBullish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iLow(NULL,tf,0)-(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_M5);
            ObjectSet(name, OBJPROP_COLOR, Green);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         if(StringFind(PriceDiv(tf),"Bearish") > 0) {
            name = "ArrowBearish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iHigh(NULL,tf,0)+(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_M5);
            ObjectSet(name, OBJPROP_COLOR, Red);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         }
      }
   return(0);

}
//--------------------------------------------------------- 15-min arrow
void Arrow15()
{
   int ao = 8;
   int tf = 15;
   string name;
   
   if(arr15 != iTime(NULL,tf,0)) {
      if(StringFind(CCIDiv(tf),"NCD") < 0) {
         arr15 = iTime(NULL,tf,0);
         if(StringFind(CCIDiv(tf),"Bullish") > 0) {
            name = "ArrowBullish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iLow(NULL,tf,0)-(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_M15);
            ObjectSet(name, OBJPROP_COLOR, Green);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         if(StringFind(CCIDiv(tf),"Bearish") > 0) {
            name = "ArrowBearish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iHigh(NULL,tf,0)+(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_M15);
            ObjectSet(name, OBJPROP_COLOR, Red);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         }
      if(StringFind(PriceDiv(tf),"NPD") < 0) {
         arr15 = iTime(NULL,tf,0);
         if(StringFind(PriceDiv(tf),"Bullish") > 0) {
            name = "ArrowBullish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iLow(NULL,tf,0)-(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_M15);
            ObjectSet(name, OBJPROP_COLOR, Green);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         if(StringFind(PriceDiv(tf),"Bearish") > 0) {
            name = "ArrowBearish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iHigh(NULL,tf,0)+(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_M15);
            ObjectSet(name, OBJPROP_COLOR, Red);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         }
      }
   return(0);
}
//--------------------------------------------------------- 30-min arrow
void Arrow30()
{
   int ao = 10;
   int tf = 30;
   string name;
   
   if(arr30 != iTime(NULL,tf,0)) {
      if(StringFind(CCIDiv(tf),"NCD") < 0) {
         arr30 = iTime(NULL,tf,0);
         if(StringFind(CCIDiv(tf),"Bullish") > 0) {
            name = "ArrowBullish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iLow(NULL,tf,0)-(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_M30);
            ObjectSet(name, OBJPROP_COLOR, Green);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         if(StringFind(CCIDiv(tf),"Bearish") > 0) {
            name = "ArrowBearish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iHigh(NULL,tf,0)+(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_M30);
            ObjectSet(name, OBJPROP_COLOR, Red);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         }
      if(StringFind(PriceDiv(tf),"NPD") < 0) {
         arr30 = iTime(NULL,tf,0);
         if(StringFind(PriceDiv(tf),"Bullish") > 0) {
            name = "ArrowBullish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iLow(NULL,tf,0)-(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_M30);
            ObjectSet(name, OBJPROP_COLOR, Green);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         if(StringFind(PriceDiv(tf),"Bearish") > 0) {
            name = "ArrowBearish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iHigh(NULL,tf,0)+(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_M30);
            ObjectSet(name, OBJPROP_COLOR, Red);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         }
      }
   return(0);
}
//--------------------------------------------------------- 60-min arrow
void Arrow60()
{
   int ao = 13;
   int tf = 60;
   string name;
   
   if(arr60 != iTime(NULL,tf,0)) {
      if(StringFind(CCIDiv(tf),"NCD") < 0) {
         arr60 = iTime(NULL,tf,0);
         if(StringFind(CCIDiv(tf),"Bullish") > 0) {
            name = "ArrowBullish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iLow(NULL,tf,0)-(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_H1);
            ObjectSet(name, OBJPROP_COLOR, Green);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         if(StringFind(CCIDiv(tf),"Bearish") > 0) {
            name = "ArrowBearish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iHigh(NULL,tf,0)+(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_H1);
            ObjectSet(name, OBJPROP_COLOR, Red);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         }
      if(StringFind(PriceDiv(tf),"NPD") < 0) {
         arr60 = iTime(NULL,tf,0);
         if(StringFind(PriceDiv(tf),"Bullish") > 0) {
            name = "ArrowBullish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iLow(NULL,tf,0)-(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_H1);
            ObjectSet(name, OBJPROP_COLOR, Green);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         if(StringFind(PriceDiv(tf),"Bearish") > 0) {
            name = "ArrowBearish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iHigh(NULL,tf,0)+(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_H1);
            ObjectSet(name, OBJPROP_COLOR, Red);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         }
      }
   return(0);
}
//--------------------------------------------------------- 4-Hr arrow
void Arrow240()
{
   int ao = 18;
   int tf = 240;
   string name;
   
   if(arr240 != iTime(NULL,tf,0)) {
      if(StringFind(CCIDiv(tf),"NCD") < 0) {
         arr240 = iTime(NULL,tf,0);
         if(StringFind(CCIDiv(tf),"Bullish") > 0) {
            name = "ArrowBullish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iLow(NULL,tf,0)-(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_H4);
            ObjectSet(name, OBJPROP_COLOR, Green);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         if(StringFind(CCIDiv(tf),"Bearish") > 0) {
            name = "ArrowBearish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iHigh(NULL,tf,0)+(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_H4);
            ObjectSet(name, OBJPROP_COLOR, Red);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         }
      if(StringFind(PriceDiv(tf),"NPD") < 0) {
         arr240 = iTime(NULL,tf,0);
         if(StringFind(PriceDiv(tf),"Bullish") > 0) {
            name = "ArrowBullish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iLow(NULL,tf,0)-(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_H4);
            ObjectSet(name, OBJPROP_COLOR, Green);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         if(StringFind(PriceDiv(tf),"Bearish") > 0) {
            name = "ArrowBearish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iHigh(NULL,tf,0)+(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_H4);
            ObjectSet(name, OBJPROP_COLOR, Red);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         }
      }
   return(0);
}
//--------------------------------------------------------- 1-Dy arrow
void Arrow1440()
{
   int ao = 25;
   int tf = 1440;
   string name;
   
   if(arr1440 != iTime(NULL,tf,0)) {
      if(StringFind(CCIDiv(tf),"NCD") < 0) {
         arr1440 = iTime(NULL,tf,0);
         if(StringFind(CCIDiv(tf),"Bullish") > 0) {
            name = "ArrowBullish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iLow(NULL,tf,0)-(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_D1);
            ObjectSet(name, OBJPROP_COLOR, Green);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         if(StringFind(CCIDiv(tf),"Bearish") > 0) {
            name = "ArrowBearish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iHigh(NULL,tf,0)+(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_D1);
            ObjectSet(name, OBJPROP_COLOR, Red);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         }
      if(StringFind(PriceDiv(tf),"NPD") < 0) {
         arr1440 = iTime(NULL,tf,0);
         if(StringFind(PriceDiv(tf),"Bullish") > 0) {
            name = "ArrowBullish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iLow(NULL,tf,0)-(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_D1);
            ObjectSet(name, OBJPROP_COLOR, Green);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         if(StringFind(PriceDiv(tf),"Bearish") > 0) {
            name = "ArrowBearish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iHigh(NULL,tf,0)+(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_D1);
            ObjectSet(name, OBJPROP_COLOR, Red);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         }
      }
   return(0);
}
//--------------------------------------------------------- 1-Wk arrow
void Arrow1w()
{
   int ao = 25;
   int tf = PERIOD_W1;
   string name;
   
   if(arrw != iTime(NULL,tf,0)) {
      if(StringFind(CCIDiv(tf),"NCD") < 0) {
         arrw = iTime(NULL,tf,0);
         if(StringFind(CCIDiv(tf),"Bullish") > 0) {
            name = "ArrowBullish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iLow(NULL,tf,0)-(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_W1);
            ObjectSet(name, OBJPROP_COLOR, Green);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         if(StringFind(CCIDiv(tf),"Bearish") > 0) {
            name = "ArrowBearish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iHigh(NULL,tf,0)+(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_W1);
            ObjectSet(name, OBJPROP_COLOR, Red);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         }
      if(StringFind(PriceDiv(tf),"NPD") < 0) {
         arrw = iTime(NULL,tf,0);
         if(StringFind(PriceDiv(tf),"Bullish") > 0) {
            name = "ArrowBullish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iLow(NULL,tf,0)-(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_W1);
            ObjectSet(name, OBJPROP_COLOR, Green);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         if(StringFind(PriceDiv(tf),"Bearish") > 0) {
            name = "ArrowBearish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iHigh(NULL,tf,0)+(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_W1);
            ObjectSet(name, OBJPROP_COLOR, Red);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         }
      }
   return(0);
}
//--------------------------------------------------------- 1-Month arrow
void Arrow1m()
{
   int ao = 25;
   int tf = PERIOD_MN1;
   string name;
   
   if(arrm != iTime(NULL,tf,0)) {
      if(StringFind(CCIDiv(tf),"NCD") < 0) {
         arrm = iTime(NULL,tf,0);
         if(StringFind(CCIDiv(tf),"Bullish") > 0) {
            name = "ArrowBullish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iLow(NULL,tf,0)-(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_MN1);
            ObjectSet(name, OBJPROP_COLOR, Green);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         if(StringFind(CCIDiv(tf),"Bearish") > 0) {
            name = "ArrowBearish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iHigh(NULL,tf,0)+(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_MN1);
            ObjectSet(name, OBJPROP_COLOR, Red);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         }
      if(StringFind(PriceDiv(tf),"NPD") < 0) {
         arrm = iTime(NULL,tf,0);
         if(StringFind(PriceDiv(tf),"Bullish") > 0) {
            name = "ArrowBullish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iLow(NULL,tf,0)-(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_MN1);
            ObjectSet(name, OBJPROP_COLOR, Green);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         if(StringFind(PriceDiv(tf),"Bearish") > 0) {
            name = "ArrowBearish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
            ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iHigh(NULL,tf,0)+(ao*point));
            ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
            ObjectSet(name, OBJPROP_WIDTH, 2);
            ObjectSet(name, OBJPROP_TIMEFRAMES, OBJ_PERIOD_MN1);
            ObjectSet(name, OBJPROP_COLOR, Red);
            ObjectSet(name, OBJPROP_BACK, false);
            }
         }
      }
   return(0);
}
//--------------------------------------------------- 1-min Alarm
void Alarm1()
{
   int tf = 1;
   
   if(alert1 != iTime(NULL,tf,0)) {
      if(StringFind(CCIDiv(tf),"NCD") < 0) {
         alert1 = iTime(NULL,tf,0);
         Alert(StringConcatenate(Symbol(),"- 1-min - CCI Divergence Alert!"));
         }
      if(StringFind(PriceDiv(tf),"NPD") < 0) {
         alert1 = iTime(NULL,tf,0);
         Alert(StringConcatenate(Symbol(),"- 1-min - Price Divergence Alert!"));
         }
      }
   return(0);
}
//--------------------------------------------------------- 5-min arrow
void Alarm5()
{
   int tf = 5;
   
   if(alert5 != iTime(NULL,tf,0)) {
      if(StringFind(CCIDiv(tf),"NCD") < 0) {
         alert5 = iTime(NULL,tf,0);
         Alert(StringConcatenate(Symbol(),"- 5-min - CCI Divergence Alert!"));
         }
      if(StringFind(PriceDiv(tf),"NPD") < 0) {
         alert5 = iTime(NULL,tf,0);
         Alert(StringConcatenate(Symbol(),"- 5-min - Price Divergence Alert!"));
         }
      }
   return(0);
}
//--------------------------------------------------------- 15-min arrow
void Alarm15()
{
   int tf = 15;
   
   if(alert15 != iTime(NULL,tf,0)) {
      if(StringFind(CCIDiv(tf),"NCD") < 0) {
         alert15 = iTime(NULL,tf,0);
         Alert(StringConcatenate(Symbol(),"- 15-min - CCI Divergence Alert!"));
         }
      if(StringFind(PriceDiv(tf),"NPD") < 0) {
         alert15 = iTime(NULL,tf,0);
         Alert(StringConcatenate(Symbol(),"- 15-min - Price Divergence Alert!"));
         }
      }
   return(0);
}
//--------------------------------------------------- 30-min eval