//+------------------------------------------------------------------+
//|                                                       CCI Helper |
//|                                              CCI_Helper_1.14.mq4 |
//|                                       Copyright © 2008 Tom Balfe |
//|                                                                  |
//|                                                                  |
//| Version: 1.14                                                    |
//|                                                                  |
//| Changelog:                                                       |
//|                                                                  |
//|    1.14  - CCI only, derived from another indicator of mine      |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008 Tom Balfe"
#property link      "redcarsarasota@yahoo.com"
#property indicator_separate_window

//--- spacing
int     scaleX=120,scaleY=20,offsetX=200,offsetY=4,fontSize=8;
//--- arrays for various things
int     TF[]              = {1,5,15,30,60,240};
//--- to adjust periods for each timeframe adjust here, save and compile
int     eCCI[]            = {14,14,6,6,6,6};
int     tCCI[]            = {50,34,14,14,14,14};
//---
string  periodStr[]       = {"1 MIN:","5 MIN:","15 MIN:","30 MIN:","1 HR:","4 HR:"};
string  signalNameStr[]   = {"EntryCCI","TrendCCI"};

//+------------------------------------------------------------------+
//| USER ADJUSTABLE STUFF                                            |
//+------------------------------------------------------------------+

extern  string  My_Symbols            = "=== Wingdings Symbols ===";
extern  int     sBuy                  = 233;
extern  int     sSell                 = 234;
extern  int     sWait                 = 54;
extern  int     sCCIAgainstBuy        = 238;
extern  int     sCCIAgainstSell       = 236;

//+------------------------------------------------------------------+
//| Initialization function                                          |
//+------------------------------------------------------------------+
int init()
  {
    //-- indicator short name
    IndicatorShortName("CCI Helper 1.14 ");

    return(0);
  }
//+------------------------------------------------------------------+
//| Deinitialization function                                        |
//+------------------------------------------------------------------+
int deinit()
  {
   //-- need to delete objects should user remove indicator
   ObjectsDeleteAll(0,OBJ_LABEL);
   
    //-- delete timeframe text labels   
    for(int x=0;x<6;x++)
      for (int y=0;y<2;y++)
      { ObjectDelete("tPs"+x+y); } 
    
    //-- delete indicator text labels
    for(y=0;y<2;y++)
      { ObjectDelete("tInd"+y); }       
    
    //-- delete indicator arrows and text
    for (x=0;x<6;x++)
      for (y=0;y<2;y++)
      { ObjectDelete("dI"+x+y); }
          
    for (x=0;x<6;x++)
      for (y=0;y<2;y++)   
      { ObjectDelete("tI"+x+y); } 
   
   return(0);
  }

//+------------------------------------------------------------------+
//| MAIN LOOP                                                        |
//+------------------------------------------------------------------+

int start()
  {
    //--- create timeframe text labels 
    for (int x=0;x<6;x++)
      for (int y=0;y<2;y++)
      {
        ObjectCreate("tPs"+x+y,OBJ_LABEL,WindowFind("CCI Helper 1.14 "),0,0);
        ObjectSetText("tPs"+x+y,periodStr[x],fontSize,"Arial Bold",LightSteelBlue);
        ObjectSet("tPs"+x+y,OBJPROP_CORNER,0);
        ObjectSet("tPs"+x+y,OBJPROP_XDISTANCE,x*scaleX+offsetX);
        ObjectSet("tPs"+x+y,OBJPROP_YDISTANCE,y*scaleY+offsetY);
      }
    
    //--- create indicator text labels
    for (y=0;y<2;y++)
      {
        ObjectCreate("tInd"+y,OBJ_LABEL,WindowFind("CCI Helper 1.14 "),0,0);
        ObjectSetText("tInd"+y,signalNameStr[y],fontSize,"Arial Bold",PaleGoldenrod);
        ObjectSet("tInd"+y,OBJPROP_CORNER,0);
        ObjectSet("tInd"+y,OBJPROP_XDISTANCE,offsetX-55);
        ObjectSet("tInd"+y,OBJPROP_YDISTANCE,y*scaleY+offsetY);
      }
    
    //--- create blanks for arrows
    for (x=0;x<6;x++)
      for (y=0;y<2;y++)
      {
        ObjectCreate("dI"+x+y,OBJ_LABEL,WindowFind("CCI Helper 1.14 "),0,0);
          ObjectSetText("dI"+x+y," ",10,"Wingdings",Goldenrod);
          ObjectSet("dI"+x+y,OBJPROP_CORNER,0);
          ObjectSet("dI"+x+y,OBJPROP_XDISTANCE,x*scaleX+(offsetX+80)); // scaleX == 120, offsetX == 200
          ObjectSet("dI"+x+y,OBJPROP_YDISTANCE,y*scaleY+offsetY);
      }
    
    //--- create blanks for text
    for (x=0;x<6;x++)
      for (y=0;y<2;y++)
      {
        ObjectCreate("tI"+x+y,OBJ_LABEL,WindowFind("CCI Helper 1.14 "),0,0);
          ObjectSetText("tI"+x+y,"    ",9,"Arial Bold",Goldenrod);
          ObjectSet("tI"+x+y,OBJPROP_CORNER,0);
          ObjectSet("tI"+x+y,OBJPROP_XDISTANCE,x*scaleX+(offsetX+45)); // scaleX == 120, offsetX == 200
          ObjectSet("tI"+x+y,OBJPROP_YDISTANCE,y*scaleY+offsetY);
      }
 
    //--- EntryCCI arrows
    for(x=0;x<6;x++)
    {
      if ((iCCI(NULL,TF[x],eCCI[x],PRICE_TYPICAL,0))>0) // if entry cci above zero
        {                                           
        if ((iCCI(NULL,TF[x],eCCI[x],PRICE_TYPICAL,0))>(iCCI(NULL,TF[x],eCCI[x],PRICE_TYPICAL,1))) 
        ObjectSetText("dI"+x+"0",CharToStr(sBuy),fontSize,"Wingdings",Lime); 
        else ObjectSetText("dI"+x+"0",CharToStr(sCCIAgainstBuy),fontSize,"Wingdings",Red); 
      }
      else if             
        ((iCCI(NULL,TF[x],eCCI[x],PRICE_TYPICAL,0)) <0) // if entry cci below zero
        {
        if ((iCCI(NULL,TF[x],eCCI[x],PRICE_TYPICAL,0)) < (iCCI(NULL,TF[x],eCCI[x],PRICE_TYPICAL,1))) 
        ObjectSetText("dI"+x+"0",CharToStr(sSell),fontSize,"Wingdings",Red);         
        else  ObjectSetText("dI"+x+"0",CharToStr(sCCIAgainstSell),fontSize,"Wingdings",Lime); 
      }
      else
        ObjectSetText("dI"+x+"0",CharToStr(sWait),10,"Wingdings",Khaki); 
    }
        
    //--- EntryCCI text
    for(x=0;x<6;x++)
    {
      if ((iCCI(NULL,TF[x],eCCI[x],PRICE_TYPICAL,0)) >0) // if entry cci above zero
        {
        if ((iCCI(NULL,TF[x],eCCI[x],PRICE_TYPICAL,0))>(iCCI(NULL,TF[x],eCCI[x],PRICE_TYPICAL,1)))
        ObjectSetText("tI"+x+"0"," BUY",9,"Arial Bold",Lime); 
        else ObjectSetText("tI"+x+"0","SELL",9,"Arial Bold",Red); 
      }
      else if             
        ((iCCI(NULL,TF[x],eCCI[x],PRICE_TYPICAL,0)) <0) // if entry cci below zero
        {
        if ((iCCI(NULL,TF[x],eCCI[x],PRICE_TYPICAL,0))<(iCCI(NULL,TF[x],eCCI[x],PRICE_TYPICAL,1)))
        ObjectSetText("tI"+x+"0","SELL",9,"Arial Bold",Red);         
        else ObjectSetText("tI"+x+"0"," BUY",9,"Arial Bold",Lime); 
      }
      else
        ObjectSetText("tI"+x+"0","WAIT",9,"Arial Bold",Khaki); 
    } 
   
    //--- TrendCCI arrows
    for(x=0;x<6;x++)
    {
      if ((iCCI(NULL,TF[x],tCCI[x],PRICE_TYPICAL,0))>0) // if entry cci above zero
        {                                           
        if ((iCCI(NULL,TF[x],tCCI[x],PRICE_TYPICAL,0))>(iCCI(NULL,TF[x],tCCI[x],PRICE_TYPICAL,1))) 
        ObjectSetText("dI"+x+"1",CharToStr(sBuy),fontSize,"Wingdings",Lime); 
        else ObjectSetText("dI"+x+"1",CharToStr(sCCIAgainstBuy),fontSize,"Wingdings",Red); 
      }
      else if             
        ((iCCI(NULL,TF[x],tCCI[x],PRICE_TYPICAL,0)) <0) // if entry cci below zero
        {
        if ((iCCI(NULL,TF[x],tCCI[x],PRICE_TYPICAL,0)) < (iCCI(NULL,TF[x],tCCI[x],PRICE_TYPICAL,1))) 
        ObjectSetText("dI"+x+"1",CharToStr(sSell),fontSize,"Wingdings",Red);         
        else  ObjectSetText("dI"+x+"1",CharToStr(sCCIAgainstSell),fontSize,"Wingdings",Lime); 
      }
      else
        ObjectSetText("dI"+x+"1",CharToStr(sWait),10,"Wingdings",Khaki); 
    }
         
    //--- TrendCCI text
    for(x=0;x<6;x++)
    {
      if ((iCCI(NULL,TF[x],tCCI[x],PRICE_TYPICAL,0)) >0) // if entry cci above zero
        {
        if ((iCCI(NULL,TF[x],tCCI[x],PRICE_TYPICAL,0))>(iCCI(NULL,TF[x],tCCI[x],PRICE_TYPICAL,1)))
        ObjectSetText("tI"+x+"1"," BUY",9,"Arial Bold",Lime); 
        else ObjectSetText("tI"+x+"1","SELL",9,"Arial Bold",Red); 
      }
      else if             
        ((iCCI(NULL,TF[x],tCCI[x],PRICE_TYPICAL,0)) <0) // if entry cci below zero
        {
        if ((iCCI(NULL,TF[x],tCCI[x],PRICE_TYPICAL,0))<(iCCI(NULL,TF[x],tCCI[x],PRICE_TYPICAL,1)))
        ObjectSetText("tI"+x+"1","SELL",9,"Arial Bold",Red);         
        else ObjectSetText("tI"+x+"1"," BUY",9,"Arial Bold",Lime); 
      }
      else
        ObjectSetText("tI"+x+"1","WAIT",9,"Arial Bold",Khaki); 
    } 
     
  return(0);
  }
  //+------------------------------------------------------------------+
  //| END MAIN LOOP                                                    |
  //+------------------------------------------------------------------+
   