TRUE Forex

Просмотр кода форекс индикатора !CCI-Divergence-Master-v13c.mq4

//+------------------------------------------------------------------+
//|                                    CCI-Divergence-Master-vxx.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:
// 
// DONE-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)
//
// DONE-add triangular-ma envelope filter for arrows
// DONE-add option to only look for CCI divergences (price divergences seem useless)(Removed price divergence check)
// DONE-added 3 levels of pending cci divergence (lookback of previous 3 peaks/troughs)
// DONE-add option for # of levels of pending cci divergence (more lookback = more signals, not neccessarily a good thing)
// DONE-add report lvl of divergence and combination of divergence (bull AND bear)
// DONE-add TriangularMA calculations and report overbough/oversold for filtering.
// DONE-add option to filter arrows (divergence) using the TriangularMA filter.
// DONE-add CCp routine to look for currency strength divergences
// DONE-add Grid.
// DONE-Remove TMA.
// DONE-add currency strength "strength" meter
// DONE-add extreme cci hook alert - when current bar close is higher but cci is lower
// DONE-add option to include CCp strength in filtering arrows
// DONE-re-enable Porfirio strategy with optional alarm or just printed
// Done-add alarm options for divergences
// DONE-add proper timeframe labeling for alerts
// DONE-add combo divergence alarm
// DONE-bug fix CCI divergence alarm and logic
// DONE-add super combo
//
// v5 - Remove TMA - Not needed.
// v7 - Currency Strength Divergence
// v8 - CCI extreme hook
// v9 - All timeframes coded in. Arrows only on divergence of CC
// v10 - Re-enable Porfirio strategy w/alarm.
// v11 - Mod Extreme Hook No Alarm
// v12 - Added combo divergence alarm. Combo arrows modified.  Arrow bug fix.
// v13 - Add Super Combo Alarm - 2 back-to-back bullish/bearish combo setups.
//
int timeframes[] = {1,5,15,30,60,240,1440,PERIOD_W1,PERIOD_MN1};
string CCILabel[] = {"cci1","cci5","cci15","cci30","cci60","cci240","cci1440","cciweek","ccimonth"};
string TFlabels[44000];
double cci[44000];
double ccip[44000];
int ccicolor[44000];
int ccipeaks[44000,10]; // timeframe, number of
int ccitroughs[44000,10]; // timeframe, number of
double front[44000];
double back[44000];
double front1[44000];
double back1[44000];
double front2[44000];
double back2[44000];
bool SuperCombo[44000];
bool SCBull[44000];
bool SCBear[44000];

datetime cciTime[44000];
datetime ccpTime[44000];
datetime alertTime[44000];
datetime arrowTime[44000];
datetime hookTime[44000];
datetime comboTime[44000];
datetime SuperComboTime[44000];

string ccistat[44000];
int ao[44000];
double ti[44000];
double CCfront[44000,30];
double CCback[44000,30];
bool alertEnable[44000];
bool arrowEnable[44000];
string frontStat[44000];
string backStat[44000];
string CCIhook[44000];
bool hookAlarm[44000];
bool comboAlarm[44000];
bool comboStat[44000];

double ExtMapBuffer1[44000];

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;
//------------------------------------------------------------------- CCI vars
double lvl1pastfront, lvl1pastback;
double lvl2pastfront, lvl2pastback;
double lvl3pastfront, lvl3pastback;

//--------------------------------------------------------------------
//     CCp Vars
//--------------------------------------------------------------------
int All_Bars = 0;
int Last_Bars = 0;
// for monthly
int mn_per = 12;
int mn_fast = 3;
// for weekly
int w_per = 9;
int w_fast = 3;
// for daily
int d_per = 5;
int d_fast = 3;
// for H4
int h4_per = 18;
int h4_fast = 6;
// for H1
int h1_per = 24;
int h1_fast = 8;
// for M30
int m30_per = 16;
int m30_fast = 2;
// for M15
int m15_per = 16;
int m15_fast = 4;
// for M5
int m5_per = 12;
int m5_fast = 3;
// for M1
int m1_per = 30;
int m1_fast = 10;

//double UpDot[100];
//double DnDot[100];
string sub;
int history=50;
int MA_Method = 3;
int Price = 6;
int Fast = 3;
int Slow = 5;
bool USD = 1;
bool EUR = 1;
bool GBP = 1;
bool CHF = 1;
bool JPY = 1;
bool AUD = 1;
bool CAD = 1;
bool NZD = 1;

double arrUSD[100];
double arrEUR[100];
double arrGBP[100];
double arrCHF[100];
double arrJPY[100];
double arrAUD[100];
double arrCAD[100];
double arrNZD[100];
int ActiveTimeFrame;
string nl = "\n";
string symbolfront, symbolback;
double currentfront, currentback, pastfront, pastback;

//---------------------------------------------------
extern bool FilterWithStrength = true;
extern string Set_CCI_Parameters = "";
extern int cciper = 14;
extern int CCI_Levels = 3;
extern string CC_Strength_Divergence ="How many bars to look back";
extern int lookback = 10;
extern string Porfirio_Strategy = "See forum for setup";
extern bool WatchForPorfirio = false;
extern bool PorfirioAlarms = false;
extern bool SuperComboAlarm = true;
extern bool DrawGridText = false;
//extern bool HookAlarms = true;
extern string Set_CCI_Divergence_Alarms = "Enable/Disable CCI Alarm";
extern bool Alarm_1m = false;
extern bool Alarm_5m = false;
extern bool Alarm_15m = false;
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 = "Potential Divergence Arrows";
extern bool Arrow_1m = false;
extern bool Arrow_5m = false;
extern bool Arrow_15m = false;
extern bool Arrow_30m = false;
extern bool Arrow_1h = false;
extern bool Arrow_4h = false;
extern bool Arrow_1d = false;
extern bool Arrow_1w = false;
extern bool Arrow_m1 = false;
extern string Hook_Alarms = "";
extern bool Hook_Alarm_1m = false;
extern bool Hook_Alarm_5m = false;
extern bool Hook_Alarm_15m = false;
extern bool Hook_Alarm_30m = false;
extern bool Hook_Alarm_H1 = false;
extern bool Hook_Alarm_H4 = false;
extern bool Hook_Alarm_D1 = false;
extern bool Hook_Alarm_W1 = false;
extern bool Hook_Alarm_MN1 = false;
extern string Extreme_Hook_Param = "When to alarm";
extern int ExtremeHookHigh = 100;
extern int ExtremeHookLow = -100;
extern string Combo_Divergence_Alarm = "High Probability Divergence";
extern bool Combo_Alarm_1m = false;
extern bool Combo_Alarm_5m = false;
extern bool Combo_Alarm_15m = false;
extern bool Combo_Alarm_30m = false;
extern bool Combo_Alarm_H1 = false;
extern bool Combo_Alarm_H4 = false;
extern bool Combo_Alarm_D1 = false;
extern bool Combo_Alarm_W1 = false;
extern bool Combo_Alarm_MN1 = false;
extern string Text_Color = "Grid color control";
extern color TextColor = Yellow;
extern color HeaderColor = Yellow;
extern color Up_CCI_Color = Green;
extern color Down_CCI_Color = Red;
extern color GridColor = White;
//----------------------------------------------------------------------------------------
int init()
  {
   ObjectsDeleteAll(0,OBJ_LABEL);

//---- indicator buffers mapping
   SetIndexBuffer(0,ExtMapBuffer1); // Bullish/Bearish signals
   
   int lenstr = StringLen(Symbol())-1;
   if(lenstr > 5){
      sub=StringSubstr(Symbol(),6,lenstr-6);
      }
   symbolfront = StringSubstr(Symbol(),0,3);
   symbolback = StringSubstr(Symbol(),3,3);
   
   string dummy;
   if(Digits==3 || Digits==5) point = Point * 10;
   else point = Point;
   
   int x=30;
      //DrawText("EU",10,12,TextColor,10,"Ariel",StringConcatenate(Symbol()," - ",TimeLeft()),true);
      DrawText("EU0",19,x,GridColor,10,"Ariel","TF",true);
      DrawText("EU0-1",69,x,GridColor,10,"Ariel","CCI",true);
      DrawText("EU0-2",125,x,GridColor,10,"Ariel","CCI-D",true);
      DrawText("EU0-3",192,x,GridColor,10,"Ariel",symbolfront,true);
      DrawText("EU0-4",250,x,GridColor,10,"Ariel",symbolback,true);
      DrawText("EU0-5",300,x,GridColor,10,"Ariel","Extreme Hook",true);
      
      DrawText("EU1",10,x+20,TextColor,10,"Ariel","1-min",true);
      DrawText("EU5",10,x+40,TextColor,10,"Ariel","5-min",true);
      DrawText("EU15",10,x+60,TextColor,10,"Ariel","15-min",true);
      DrawText("EU30",10,x+80,TextColor,10,"Ariel","30-min",true);
      DrawText("EU60",10,x+100,TextColor,10,"Ariel","1-Hr",true);
      DrawText("EU4H",10,x+120,TextColor,10,"Ariel","4-Hr",true);
      DrawText("EU1D",10,x+140,TextColor,10,"Ariel","1-Day",true);
      DrawText("EU1W",10,x+160,TextColor,10,"Ariel","1-Wk",true);
      DrawText("EU1M",10,x+180,TextColor,10,"Ariel","1-Mo",true);
      
      string horiz="_______________________________________________________";
      DrawText("Line1",5,13,GridColor,10,"Ariel",horiz,false);
      DrawText("Line2",5,x+5,GridColor,10,"Ariel",horiz,false);
      DrawText("Line3",5,x+25,GridColor,10,"Ariel",horiz,false);
      DrawText("Line4",5,x+45,GridColor,10,"Ariel",horiz,false);
      DrawText("Line5",5,x+65,GridColor,10,"Ariel",horiz,false);
      DrawText("Line6",5,x+85,GridColor,10,"Ariel",horiz,false);
      DrawText("Line7",5,x+105,GridColor,10,"Ariel",horiz,false);
      DrawText("Line8",5,x+125,GridColor,10,"Ariel",horiz,false);
      DrawText("Line9",5,x+145,GridColor,10,"Ariel",horiz,false);
      DrawText("Line10",5,x+165,GridColor,10,"Ariel",horiz,false);
      DrawText("Line11",5,x+185,GridColor,10,"Ariel",horiz,false);
      
      int colum[]={4,52,108,175,235,290,389};
      for(int h=0; h<7; h++){
         DrawText("Line11-"+h,colum[h],22,GridColor,14,"Ariel","|",false);
         DrawText("Line12-"+h,colum[h],40,GridColor,14,"Ariel","|",false);
         DrawText("Line13-"+h,colum[h],58,GridColor,14,"Ariel","|",false);
         DrawText("Line14-"+h,colum[h],76,GridColor,14,"Ariel","|",false);
         DrawText("Line15-"+h,colum[h],94,GridColor,14,"Ariel","|",false);
         DrawText("Line16-"+h,colum[h],110,GridColor,14,"Ariel","|",false);
         DrawText("Line17-"+h,colum[h],128,GridColor,14,"Ariel","|",false);
         DrawText("Line18-"+h,colum[h],146,GridColor,14,"Ariel","|",false);
         DrawText("Line19-"+h,colum[h]-1,166,GridColor,15,"Ariel","|",false);
         DrawText("Line20-"+h,colum[h]-1,185,GridColor,17,"Ariel","|",false);
         DrawText("Line21-"+h,colum[h]-1,204,GridColor,17,"Ariel","|",false);
         }
      
      for(int n=0; n<9; n++) {
         //TMA(timeframes[n],1);
         ccistat[timeframes[n]]=CCIDiv(timeframes[n],1);
         GetStrengths(timeframes[n],1);
         }
      
      ao[1]=3; ao[5]=5; ao[15]=8; ao[30]=10; ao[60]=13; ao[240]=18; ao[1440]=25; ao[PERIOD_W1]=45; ao[PERIOD_MN1]=65;
      ti[1]=OBJ_PERIOD_M1; ti[5]=OBJ_PERIOD_M5; ti[15]=OBJ_PERIOD_M15; ti[30]=OBJ_PERIOD_M30; ti[60]=OBJ_PERIOD_H1;
      ti[240]=OBJ_PERIOD_H4; ti[1440]=OBJ_PERIOD_D1; ti[PERIOD_W1]=OBJ_PERIOD_W1; ti[PERIOD_MN1]=OBJ_PERIOD_MN1;
      alertEnable[1]=Alarm_1m; alertEnable[5]=Alarm_5m; alertEnable[15]=Alarm_15m; alertEnable[30]=Alarm_30m; alertEnable[60]=Alarm_1h;
      alertEnable[240]=Alarm_4h; alertEnable[1440]=Alarm_1d; alertEnable[PERIOD_W1]=Alarm_1w; alertEnable[PERIOD_MN1]=Alarm_m1;
      arrowEnable[1]=Arrow_1m; arrowEnable[5]=Arrow_5m; arrowEnable[15]=Arrow_15m; arrowEnable[30]=Arrow_30m; arrowEnable[60]=Arrow_1h;
      arrowEnable[240]=Arrow_4h; arrowEnable[1440]=Arrow_1d; arrowEnable[PERIOD_W1]=Arrow_1w; arrowEnable[PERIOD_MN1]=Arrow_m1;
      TFlabels[1]="1-min"; TFlabels[5]="5-min"; TFlabels[15]="15-min"; TFlabels[30]="30-min"; TFlabels[60]="1-Hr";
      TFlabels[240]="4-Hr"; TFlabels[1440]="1-Day"; TFlabels[PERIOD_W1]="1-Week"; TFlabels[PERIOD_MN1]="1-Month";
      hookAlarm[1]=Hook_Alarm_1m; hookAlarm[5]=Hook_Alarm_5m; hookAlarm[15]=Hook_Alarm_15m; hookAlarm[30]=Hook_Alarm_30m; hookAlarm[60]=Hook_Alarm_H1;
      hookAlarm[240]=Hook_Alarm_H4; hookAlarm[1440]=Hook_Alarm_D1; hookAlarm[PERIOD_W1]=Hook_Alarm_W1; hookAlarm[PERIOD_MN1]=Hook_Alarm_MN1;
      comboAlarm[1]=Combo_Alarm_1m; comboAlarm[5]=Combo_Alarm_5m; comboAlarm[15]=Combo_Alarm_15m; comboAlarm[30]=Combo_Alarm_30m;
      comboAlarm[60]=Combo_Alarm_H1; comboAlarm[240]=Combo_Alarm_H4; comboAlarm[1440]=Combo_Alarm_D1; comboAlarm[PERIOD_W1]=Combo_Alarm_W1;
      comboAlarm[PERIOD_MN1]=Combo_Alarm_MN1;
      
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   ObjectsDeleteAll(0,OBJ_LABEL);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int x = 60; // for position of text
   int col = 55; // column 
   header();
   CCIcalcs();
   
   for(int n=0; n<9; n++) {
         //TMA(timeframes[n],0);
         ccistat[timeframes[n]]=CCIDiv(timeframes[n],1);
         GetStrengths(timeframes[n],0);
         CCstatus(timeframes[n]);
         CCIhook(timeframes[n]);
         if(alertEnable[timeframes[n]]==true) Alarm(timeframes[n]);
         if(arrowEnable[timeframes[n]]==true) Arrow(timeframes[n]);
         CCIhookAlarms(timeframes[n]);
         ComboCheck(timeframes[n]);
         SuperComboCheck();
         }
   int v=30;
      
   DrawText("C1",x+col,v+20,TextColor,10,"Ariel",ccistat[1],true); // 1-min CCI divergence
   DrawText("C5",x+col,v+40,TextColor,10,"Ariel",ccistat[5],true); // 5-min CCI divergence
   DrawText("C15",x+col,v+60,TextColor,10,"Ariel",ccistat[15],true); // 15-min CCI divergence
   DrawText("C30",x+col,v+80,TextColor,10,"Ariel",ccistat[30],true); // 30-min CCI divergence
   DrawText("C60",x+col,v+100,TextColor,10,"Ariel",ccistat[60],true); // 60-min CCI divergence
   DrawText("C240",x+col,v+120,TextColor,10,"Ariel",ccistat[240],true); // 4-hr CCI divergence
   DrawText("C1440",x+col,v+140,TextColor,10,"Ariel",ccistat[1440],true); // 1-day CCI divergence
   DrawText("C1w",x+col,v+160,TextColor,10,"Ariel",ccistat[PERIOD_W1],true); // 1-wk CCI divergence
   DrawText("C1m",x+col,v+180,TextColor,10,"Ariel",ccistat[PERIOD_MN1],true); // 1-mo CCI divergence
   
   col = 125;
   DrawText("STR1",x+col,v+20,TextColor,10,"Ariel",frontStat[1],true);
   DrawText("STR5",x+col,v+40,TextColor,10,"Ariel",frontStat[5],true);
   DrawText("STR15",x+col,v+60,TextColor,10,"Ariel",frontStat[15],true);
   DrawText("STR30",x+col,v+80,TextColor,10,"Ariel",frontStat[30],true);
   DrawText("STR60",x+col,v+100,TextColor,10,"Ariel",frontStat[60],true);
   DrawText("STR240",x+col,v+120,TextColor,10,"Ariel",frontStat[240],true);
   DrawText("STR1440",x+col,v+140,TextColor,10,"Ariel",frontStat[1440],true);
   DrawText("STR1w",x+col,v+160,TextColor,10,"Ariel",frontStat[PERIOD_W1],true);
   DrawText("STR1m",x+col,v+180,TextColor,10,"Ariel",frontStat[PERIOD_MN1],true);
   
   col = 185;
   DrawText("STR1-1",x+col,v+20,TextColor,10,"Ariel",backStat[1],true);
   DrawText("STR5-1",x+col,v+40,TextColor,10,"Ariel",backStat[5],true);
   DrawText("STR15-1",x+col,v+60,TextColor,10,"Ariel",backStat[15],true);
   DrawText("STR30-1",x+col,v+80,TextColor,10,"Ariel",backStat[30],true);
   DrawText("STR60-1",x+col,v+100,TextColor,10,"Ariel",backStat[60],true);
   DrawText("STR240-1",x+col,v+120,TextColor,10,"Ariel",backStat[240],true);
   DrawText("STR1440-1",x+col,v+140,TextColor,10,"Ariel",backStat[1440],true);
   DrawText("STR1w-1",x+col,v+160,TextColor,10,"Ariel",backStat[PERIOD_W1],true);
   DrawText("STR1m-1",x+col,v+180,TextColor,10,"Ariel",backStat[PERIOD_MN1],true);
   
   col=270;
   DrawText("hook1",x+col,v+20,TextColor,10,"Ariel",CCIhook[1],true);
   DrawText("hook5",x+col,v+40,TextColor,10,"Ariel",CCIhook[5],true);
   DrawText("hook15",x+col,v+60,TextColor,10,"Ariel",CCIhook[15],true);
   DrawText("hook30",x+col,v+80,TextColor,10,"Ariel",CCIhook[30],true);
   DrawText("hook60",x+col,v+100,TextColor,10,"Ariel",CCIhook[60],true);
   DrawText("hook240",x+col,v+120,TextColor,10,"Ariel",CCIhook[240],true);
   DrawText("hook1440",x+col,v+140,TextColor,10,"Ariel",CCIhook[1440],true);
   DrawText("hook1w",x+col,v+160,TextColor,10,"Ariel",CCIhook[PERIOD_W1],true);
   DrawText("hook1m",x+col,v+180,TextColor,10,"Ariel",CCIhook[PERIOD_MN1],true);
   

// ----------------------------------------------------  Porfirio logic
   if(WatchForPorfirio==true) {
      Porfirio1 = " "; Porfirio2 = " "; Porfirio3 = " ";
      if(cci[15]>=0 && cci[5]<-100) {
         Porfirio1 = Symbol()+"-Porfirio Buy Setup m15-m5-m1: Watch m1 for Divergence"; 
         if(PorAlert1 != iTime(NULL,15,0)) {
            if(PorfirioAlarms==true) Alert(Porfirio1); PorAlert1 = iTime(NULL,15,0); 
            }
         }
      if(cci[15]<=0 && cci[5]>100) {
         Porfirio1 = Symbol()+"-Porfirio Sell Setup m15-m5-m1: Watch m1 for Divergence"; 
         if(PorAlert1 != iTime(NULL,15,0)) {
            if(PorfirioAlarms==true) Alert(Porfirio1); PorAlert1 = iTime(NULL,15,0);
            }
         }
         
      if(cci[60]>=0 && cci[15]<-100) {
         Porfirio2 = Symbol()+"-Porfirio Buy Setup H1-m15-m5: Watch m5 for Divergence"; 
         if(PorAlert2 != iTime(NULL,15,0)) {
            if(PorfirioAlarms==true) Alert(Porfirio2); PorAlert2 = iTime(NULL,15,0);
            }
         }
      if(cci[60]<=0 && cci[15]>100) {
         Porfirio2 = Symbol()+"-Porfirio Sell Setup H1-m15-m5: Watch m5 for Divergence"; 
         if(PorAlert2 != iTime(NULL,15,0)) {
            if(PorfirioAlarms==true) Alert(Porfirio2); PorAlert2 = iTime(NULL,15,0);
            }
         }
         
      if(cci[240]>=0 && cci[60]<-100) {
         Porfirio3 = Symbol()+"-Porfirio Buy Setup H4-H1-m15: Watch m15 for Divergence"; 
         if(PorAlert3 != iTime(NULL,15,0)) {
            if(PorfirioAlarms==true) Alert(Porfirio3); PorAlert3 = iTime(NULL,15,0);
            }
         }
      if(cci[240]<=0 && cci[60]>100) {
         Porfirio3 = Symbol()+"-Porfirio Sell Setup H4-H1-m15: Watch m15 for Divergence"; 
         if(PorAlert3 != iTime(NULL,15,0)) {
            if(PorfirioAlarms==true) 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 CCI low trough from idx
int CCILastZZLow(int timeframe, int idx)
{
   for(int g=idx; g<500; g++) {
      if(iCCI(NULL,timeframe,cciper,PRICE_TYPICAL,g-1)>iCCI(NULL,timeframe,cciper,PRICE_TYPICAL,g) && iCCI(NULL,timeframe,cciper,PRICE_TYPICAL,g)<iCCI(NULL,timeframe,cciper,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,cciper,PRICE_TYPICAL,g-1)<iCCI(NULL,timeframe,cciper,PRICE_TYPICAL,g) && iCCI(NULL,timeframe,cciper,PRICE_TYPICAL,g)>iCCI(NULL,timeframe,cciper,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)
{
   if(DrawGridText==true){
      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 (conversion complete)
void header()
{
   int x = 60;
   int j = 0;
   int y = 50;
   DrawText("EU",10,12,HeaderColor,10,"Ariel",StringConcatenate(Symbol()," - ",TimeLeft()),true);
   
   for(j=0; j<9; j++) {
      cci[timeframes[j]] = iCCI(NULL,timeframes[j],cciper, PRICE_TYPICAL,0);
      ccip[timeframes[j]] = iCCI(NULL,timeframes[j],cciper, PRICE_TYPICAL,1);
      if(ccip[timeframes[j]] > cci[timeframes[j]]) ccicolor[timeframes[j]] = Down_CCI_Color;
      else ccicolor[timeframes[j]] = Up_CCI_Color;
      DrawText(CCILabel[j],x,y,ccicolor[timeframes[j]],10,"Ariel",DoubleToStr(cci[timeframes[j]],2),true);
      y=y+20;
      }

   return(0);
}
//---------------------------------------------------------------- CCI calc peak/trough
void CCIcalcs()
{
   int temph, templ;
   int h = 0;
   int j;
   for(j=0; j<9; j++) {
         h=0;
         ccipeaks[timeframes[j],h] =   CCILastZZHigh(timeframes[j],2); temph = ccipeaks[timeframes[j],h];
         ccitroughs[timeframes[j],h] = CCILastZZLow(timeframes[j],2);  templ = ccitroughs[timeframes[j],h];
         h=h+1;
         ccipeaks[timeframes[j],h] =   CCILastZZHigh(timeframes[j],temph+1); temph = ccipeaks[timeframes[j],h];
         ccitroughs[timeframes[j],h] = CCILastZZLow(timeframes[j],templ+1);  templ = ccitroughs[timeframes[j],h];
         h=h+1;
         ccipeaks[timeframes[j],h] =   CCILastZZHigh(timeframes[j],temph+1); 
         ccitroughs[timeframes[j],h] = CCILastZZLow(timeframes[j],templ+1); 
         }        
   //return(0);
}
//---------------------------------------------------------------- Check for CCI divergence with price
string CCIDiv(int timeframe, int override)
{
string status;

if(cciTime[timeframe]!=iTime(NULL,timeframe,0) || override==1) {
   cciTime[timeframe] = iTime(NULL,timeframe,0);
   
   int lw1, lw2, lw3, h1, h2, h3;
   lw1 = ccitroughs[timeframe,0];
   lw2 = ccitroughs[timeframe,1];
   lw3 = ccitroughs[timeframe,2];
   h1 = ccipeaks[timeframe,0]; 
   h2 = ccipeaks[timeframe,1]; 
   h3 = ccipeaks[timeframe,2]; 
   
   string status1a="";
   string status1b="";
   string status1c="";
   int lvl1bull = 0;
   int lvl2bull = 0;
   int lvl3bull = 0;
   int lvl1bear = 0;
   int lvl2bear = 0;
   int lvl3bear = 0;
   
   double lcci1 = iLow(NULL,timeframe,0);
   double hcci1 = iHigh(NULL,timeframe,0);
   double ccinow = iCCI(NULL,timeframe,cciper,PRICE_TYPICAL,0);

   if(CCI_Levels >= 1){
      if(iCCI(NULL,timeframe,cciper,PRICE_TYPICAL,lw1) < ccinow && lcci1 < iLow(NULL,timeframe,lw1)) {
         lvl1bull=1;
         }
      if(iCCI(NULL,timeframe,cciper,PRICE_TYPICAL,h1) > ccinow && hcci1 > iHigh(NULL,timeframe,h1)) {
         lvl1bear=1;
         }
      }
   if(CCI_Levels >= 2){
      if(iCCI(NULL,timeframe,cciper,PRICE_TYPICAL,lw2) < ccinow && lcci1 < iLow(NULL,timeframe,lw2)) {
         lvl2bull=1;
         }
      if(iCCI(NULL,timeframe,cciper,PRICE_TYPICAL,h2) > ccinow && hcci1 > iHigh(NULL,timeframe,h2)) {
         lvl2bear=1;
         }
      }
   if(CCI_Levels >=3) {
      if(iCCI(NULL,timeframe,cciper,PRICE_TYPICAL,lw3) < ccinow && lcci1 < iLow(NULL,timeframe,lw3)) {
         lvl3bull=1;
         }
      if(iCCI(NULL,timeframe,cciper,PRICE_TYPICAL,h3) > ccinow && hcci1 > iHigh(NULL,timeframe,h3)) {
         lvl3bear=1;
         }
      }
      
   int bull = lvl1bull+lvl2bull+lvl3bull;
   int bear = lvl1bear+lvl2bear+lvl3bear;
   
   status="";
   if(bull>0 && bear>0) status="MixDiv";
   if(bull>0 && bear==0) status="BullDiv"; 
   if(bear>0 && bull==0) status="BearDiv";
   
   return(status);
 }
}
//---------------------------------------------- Arrow
void Arrow(int tf)
{
   string name;

   
   if(arrowTime[tf] != iTime(NULL,tf,0)) {
      if(ccistat[tf] != "") {
         
         arrowTime[tf] = iTime(NULL,tf,0);
         if(ccistat[tf]=="BullDiv") {
            if((FilterWithStrength==true && (StringFind(frontStat[tf],"Bull")>=0 && StringFind(backStat[tf],"Bull")>=0)) || FilterWithStrength==false) {
               //Print(tf+"-found bullish arrow");
               name = "ArrowBullish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
               ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iLow(NULL,tf,0)-(ao[tf]*point));
               ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
               ObjectSet(name, OBJPROP_WIDTH, 2);
               ObjectSet(name, OBJPROP_TIMEFRAMES, ti[tf]);
               ObjectSet(name, OBJPROP_COLOR, Green);
               ObjectSet(name, OBJPROP_BACK, false);
               ExtMapBuffer1[0]=100;
               }
            }
         
         if(ccistat[tf]=="BearDiv") {
            if((FilterWithStrength==true && (StringFind(frontStat[tf],"Bear")>=0 && StringFind(backStat[tf],"Bear")>=0)) || FilterWithStrength==false) {
               //Print(tf+"-found bearish arrow");
               name = "ArrowBearish"+TimeToStr(TimeCurrent(),TIME_SECONDS);
               ObjectCreate(name, OBJ_ARROW, 0, iTime(NULL,tf,0), iHigh(NULL,tf,0)+(ao[tf]*point));
               ObjectSet(name, OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
               ObjectSet(name, OBJPROP_WIDTH, 2);
               ObjectSet(name, OBJPROP_TIMEFRAMES, ti[tf]);
               ObjectSet(name, OBJPROP_COLOR, Red);
               ObjectSet(name, OBJPROP_BACK, false);
               ExtMapBuffer1[0]=-100;
               }
            }
         }

      }
   return(0);
}
//---------------------------------------------------
void Alarm(int tf)
{
   
   if(alertTime[tf] != iTime(NULL,tf,0)) {
      if(StringFind(ccistat[tf],"Div") >= 0) {
         alertTime[tf] = iTime(NULL,tf,0);
         Alert(StringConcatenate(Symbol(),TFlabels[tf]," - ",ccistat[tf]," - ","CCI Divergence Alert!"));
         }
      }
   
   return(0);          
}
//--------------------------------------------------------
void CCIhookAlarms(int tf)
{
   //string whichway = ""
   if(hookAlarm[tf]==true) {
      if(hookTime[tf] != iTime(NULL,tf,0)) {
         if(CCIhook[tf] == "Bull") {
            hookTime[tf] = iTime(NULL,tf,0);
            Alert(StringConcatenate(Symbol()," ",TFlabels[tf]," - Bullish CCI Hook!"));
            }
         if(CCIhook[tf] == "Bear") {
            hookTime[tf] = iTime(NULL,tf,0);
            Alert(StringConcatenate(Symbol()," ",TFlabels[tf]," - Bearish CCI Hook!"));
            }
         }
      }
      
   return(0);          
}
//----------------------------------------------------------------------------------
void GetCC()
{
   switch(ActiveTimeFrame)
     {
       case 1:     Slow = m1_per; Fast = m1_fast;  break;
       case 5:     Slow = m5_per; Fast = m5_fast;  break;
       case 15:    Slow = m15_per;Fast = m15_fast; break;
       case 30:    Slow = m30_per;Fast = m30_fast; break;
       case 60:    Slow = h1_per; Fast = h1_fast;  break;
       case 240:   Slow = h4_per; Fast = h4_fast;  break;
       case 1440:  Slow = d_per;  Fast = d_fast;   break;
       case 10080: Slow = w_per;  Fast = w_fast;   break;
       case 43200: Slow = mn_per; Fast = mn_fast;  break;
     }

for(int i = 0; i < history; i++)
     {
       
       if(EUR)
         {
           double EURUSD_Fast = ma2(StringConcatenate("EURUSD",sub), Fast, MA_Method, Price, i);
           double EURUSD_Slow = ma2(StringConcatenate("EURUSD",sub), Slow, MA_Method, Price, i);
           if (!EURUSD_Fast || !EURUSD_Slow)   
               break;
         }
       if(GBP)
         {
           double GBPUSD_Fast = ma2(StringConcatenate("GBPUSD",sub), Fast, MA_Method, Price, i);
           double GBPUSD_Slow = ma2(StringConcatenate("GBPUSD",sub), Slow, MA_Method, Price, i);
           if(!GBPUSD_Fast || !GBPUSD_Slow)
               break;
         }
       if(AUD)
         {
           double AUDUSD_Fast = ma2(StringConcatenate("AUDUSD",sub), Fast, MA_Method, Price, i);
           double AUDUSD_Slow = ma2(StringConcatenate("AUDUSD",sub), Slow, MA_Method, Price, i);
           if(!AUDUSD_Fast || !AUDUSD_Slow)
               break;
         }
       if(NZD)
         {
           double NZDUSD_Fast = ma2(StringConcatenate("NZDUSD",sub), Fast, MA_Method, Price, i);
           double NZDUSD_Slow = ma2(StringConcatenate("NZDUSD",sub), Slow, MA_Method, Price, i);
           if(!NZDUSD_Fast || !NZDUSD_Slow)
               break;
         }
       if(CAD)
         {
           double USDCAD_Fast = ma2(StringConcatenate("USDCAD",sub), Fast, MA_Method, Price, i);
           double USDCAD_Slow = ma2(StringConcatenate("USDCAD",sub), Slow, MA_Method, Price, i);
           if(!USDCAD_Fast || !USDCAD_Slow)
               break;
         }
       if(CHF)
         {
           double USDCHF_Fast = ma2(StringConcatenate("USDCHF",sub),Fast,MA_Method,Price,i);
           double USDCHF_Slow = ma2(StringConcatenate("USDCHF",sub),Slow,MA_Method,Price,i);
           if(!USDCHF_Fast || !USDCHF_Slow)
               break;
         }
       if(JPY)
         {
           double USDJPY_Fast = ma2(StringConcatenate("USDJPY",sub), Fast, MA_Method, Price, i) / 
                                100;
           double USDJPY_Slow = ma2(StringConcatenate("USDJPY",sub), Slow, MA_Method, Price, i) / 
                                100;
           if(!USDJPY_Fast || !USDJPY_Slow)
               break;
         }

           arrUSD[i] = 0;
           if(EUR) 
               arrUSD[i] += EURUSD_Slow - EURUSD_Fast;
           if(GBP) 
               arrUSD[i] += GBPUSD_Slow - GBPUSD_Fast;
           if(AUD) 
               arrUSD[i] += AUDUSD_Slow - AUDUSD_Fast;
           if(NZD) 
               arrUSD[i] += NZDUSD_Slow - NZDUSD_Fast;
           if(CHF) 
               arrUSD[i] += USDCHF_Fast - USDCHF_Slow;
           if(CAD) 
               arrUSD[i] += USDCAD_Fast - USDCAD_Slow;
           if(JPY) 
               arrUSD[i] += USDJPY_Fast - USDJPY_Slow;
         //}// end if USD
        //if (((ShowOnlyPairOnChart==true) && (StringFind(Symbol(),"EUR",0)!=-1))||((ShowOnlyPairOnChart==false) && (EUR==true)))        
      
         //{
           arrEUR[i] = 0;
           if(USD) 
               arrEUR[i] += EURUSD_Fast - EURUSD_Slow;
           if(GBP) 
               arrEUR[i] += EURUSD_Fast / GBPUSD_Fast - EURUSD_Slow / 
                            GBPUSD_Slow;
           if(AUD) 
               arrEUR[i] += EURUSD_Fast / AUDUSD_Fast - EURUSD_Slow / 
                            AUDUSD_Slow;
           if(NZD) 
               arrEUR[i] += EURUSD_Fast / NZDUSD_Fast - EURUSD_Slow / 
                            NZDUSD_Slow;
           if(CHF) 
               arrEUR[i] += EURUSD_Fast*USDCHF_Fast - 
                            EURUSD_Slow*USDCHF_Slow;
           if(CAD) 
               arrEUR[i] += EURUSD_Fast*USDCAD_Fast - 
                            EURUSD_Slow*USDCAD_Slow;
           if(JPY) 
               arrEUR[i] += EURUSD_Fast*USDJPY_Fast - 
                            EURUSD_Slow*USDJPY_Slow;
         //}// end if EUR
      //if (((ShowOnlyPairOnChart==true) && (StringFind(Symbol(),"GBP",0)!=-1))||((ShowOnlyPairOnChart==false) && (GBP==true)))        
         //{
           arrGBP[i] = 0;
           if(USD) 
               arrGBP[i] += GBPUSD_Fast - GBPUSD_Slow;
           if(EUR) 
               arrGBP[i] += EURUSD_Slow / GBPUSD_Slow - EURUSD_Fast / 
                            GBPUSD_Fast;
           if(AUD) 
               arrGBP[i] += GBPUSD_Fast / AUDUSD_Fast - GBPUSD_Slow / 
                            AUDUSD_Slow;
           if(NZD) 
               arrGBP[i] += GBPUSD_Fast / NZDUSD_Fast - GBPUSD_Slow / 
                            NZDUSD_Slow;
           if(CHF) 
               arrGBP[i] += GBPUSD_Fast*USDCHF_Fast - 
                            GBPUSD_Slow*USDCHF_Slow;
           if(CAD) 
               arrGBP[i] += GBPUSD_Fast*USDCAD_Fast - 
                            GBPUSD_Slow*USDCAD_Slow;
           if(JPY) 
               arrGBP[i] += GBPUSD_Fast*USDJPY_Fast - 
                            GBPUSD_Slow*USDJPY_Slow;
         //}// end if GBP
     //if (((ShowOnlyPairOnChart==true) && (StringFind(Symbol(),"AUD",0)!=-1))||((ShowOnlyPairOnChart==false) && (AUD==true)))        
         //{
           arrAUD[i] = 0;
           if(USD) 
               arrAUD[i] += AUDUSD_Fast - AUDUSD_Slow;
           if(EUR) 
               arrAUD[i] += EURUSD_Slow / AUDUSD_Slow - EURUSD_Fast / 
                            AUDUSD_Fast;
           if(GBP) 
               arrAUD[i] += GBPUSD_Slow / AUDUSD_Slow - GBPUSD_Fast / 
                            AUDUSD_Fast;
           if(NZD) 
               arrAUD[i] += AUDUSD_Fast / NZDUSD_Fast - AUDUSD_Slow / 
                            NZDUSD_Slow;
           if(CHF) 
               arrAUD[i] += AUDUSD_Fast*USDCHF_Fast - 
                            AUDUSD_Slow*USDCHF_Slow;
           if(CAD) 
               arrAUD[i] += AUDUSD_Fast*USDCAD_Fast - 
                            AUDUSD_Slow*USDCAD_Slow;
           if(JPY) 
               arrAUD[i] += AUDUSD_Fast*USDJPY_Fast - 
                            AUDUSD_Slow*USDJPY_Slow;
         //}// end if AUD
     //if (((ShowOnlyPairOnChart==true) && (StringFind(Symbol(),"NZD",0)!=-1))||((ShowOnlyPairOnChart==false) && (NZD==true)))        
       
         //{
           arrNZD[i] = 0;
           if(USD) 
               arrNZD[i] += NZDUSD_Fast - NZDUSD_Slow;
           if(EUR) 
               arrNZD[i] += EURUSD_Slow / NZDUSD_Slow - EURUSD_Fast / 
                            NZDUSD_Fast;
           if(GBP) 
               arrNZD[i] += GBPUSD_Slow / NZDUSD_Slow - GBPUSD_Fast / 
                            NZDUSD_Fast;
           if(AUD) 
               arrNZD[i] += AUDUSD_Slow / NZDUSD_Slow - AUDUSD_Fast / 
                            NZDUSD_Fast;
           if(CHF) 
               arrNZD[i] += NZDUSD_Fast*USDCHF_Fast - 
                            NZDUSD_Slow*USDCHF_Slow;
           if(CAD) 
               arrNZD[i] += NZDUSD_Fast*USDCAD_Fast - 
                            NZDUSD_Slow*USDCAD_Slow;
           if(JPY) 
               arrNZD[i] += NZDUSD_Fast*USDJPY_Fast - 
                            NZDUSD_Slow*USDJPY_Slow;
         //}// end if NZD
     //if (((ShowOnlyPairOnChart==true) && (StringFind(Symbol(),"CAD",0)!=-1))||((ShowOnlyPairOnChart==false) && (CAD==true)))        
         //{
           arrCAD[i] = 0;
           if(USD) 
           arrCAD[i] += USDCAD_Slow - USDCAD_Fast;
           if(EUR) 
           arrCAD[i] += EURUSD_Slow*USDCAD_Slow - 
                        EURUSD_Fast*USDCAD_Fast;
           if(GBP) 
           arrCAD[i] += GBPUSD_Slow*USDCAD_Slow - 
                        GBPUSD_Fast*USDCAD_Fast;
           if(AUD) 
           arrCAD[i] += AUDUSD_Slow*USDCAD_Slow - 
                        AUDUSD_Fast*USDCAD_Fast;
           if(NZD) 
           arrCAD[i] += NZDUSD_Slow*USDCAD_Slow - 
                        NZDUSD_Fast*USDCAD_Fast;
           if(CHF) 
           arrCAD[i] += USDCHF_Fast / USDCAD_Fast - 
                        USDCHF_Slow / USDCAD_Slow;
           if(JPY) 
           arrCAD[i] += USDJPY_Fast / USDCAD_Fast - 
                        USDJPY_Slow / USDCAD_Slow;
         //}// end if CAD
        
       //if (((ShowOnlyPairOnChart==true) && (StringFind(Symbol(),"CHF",0)!=-1))||((ShowOnlyPairOnChart==false) && (CHF==true)))        
         //{
           arrCHF[i] = 0;
           if(USD) 
               arrCHF[i] += USDCHF_Slow - USDCHF_Fast;
           if(EUR) 
               arrCHF[i] += EURUSD_Slow*USDCHF_Slow - 
                            EURUSD_Fast*USDCHF_Fast;
           if(GBP) 
               arrCHF[i] += GBPUSD_Slow*USDCHF_Slow - 
                            GBPUSD_Fast*USDCHF_Fast;
           if(AUD) 
               arrCHF[i] += AUDUSD_Slow*USDCHF_Slow - 
                            AUDUSD_Fast*USDCHF_Fast;
           if(NZD) 
               arrCHF[i] += NZDUSD_Slow*USDCHF_Slow - 
                            NZDUSD_Fast*USDCHF_Fast;
           if(CAD) 
               arrCHF[i] += USDCHF_Slow / USDCAD_Slow - 
                            USDCHF_Fast / USDCAD_Fast;
           if(JPY) 
               arrCHF[i] += USDJPY_Fast / USDCHF_Fast - 
                            USDJPY_Slow / USDCHF_Slow;
         //}// end if CHF
        //if (((ShowOnlyPairOnChart==true) && (StringFind(Symbol(),"JPY",0)!=-1))||((ShowOnlyPairOnChart==false) && (JPY==true)))        
         //{ 
           arrJPY[i] = 0;
           if(USD) 
           arrJPY[i] += USDJPY_Slow - USDJPY_Fast;
           if(EUR) 
           arrJPY[i] += EURUSD_Slow*USDJPY_Slow - 
                        EURUSD_Fast*USDJPY_Fast;
           if(GBP) 
           arrJPY[i] += GBPUSD_Slow*USDJPY_Slow - 
                        GBPUSD_Fast*USDJPY_Fast;
           if(AUD) 
           arrJPY[i] += AUDUSD_Slow*USDJPY_Slow - 
                        AUDUSD_Fast*USDJPY_Fast;
           if(NZD) 
           arrJPY[i] += NZDUSD_Slow*USDJPY_Slow - 
                        NZDUSD_Fast*USDJPY_Fast;
           if(CAD) 
           arrJPY[i] += USDJPY_Slow / USDCAD_Slow - 
                        USDJPY_Fast / USDCAD_Fast;
           if(CHF) 
           arrJPY[i] += USDJPY_Slow / USDCHF_Slow - 
                        USDJPY_Fast / USDCHF_Fast;
         //}// end if JPY
     }//end block for(int i=0; i<limit; i++)
//----
return(0);
}
//----
//-------------------------------------------------------------------
double ma2(string sym, int per, int Mode, int Price, int i)
  {
    return(iMA(sym, ActiveTimeFrame, per, 0, Mode, Price, i));
  }
//-------------------------------------------------------------------
void GetStrengths(int timeframe, int override)
{
   ActiveTimeFrame = timeframe;
   if(ccpTime[timeframe]!=iTime(NULL,timeframe,0) || override==1) {
      GetCC(); ccpTime[timeframe]=iTime(NULL,timeframe,0);

      if(symbolfront=="GBP"){
         currentfront = arrGBP[0]*10000;
         for(int g=0; g<30; g++) {
            CCfront[timeframe,g]= arrGBP[g]*10000;
           }
        }
     if(symbolfront=="USD"){
        currentfront = arrUSD[0]*10000;
        for(g=0; g<30; g++) {
          CCfront[timeframe,g] = arrUSD[g]*10000;
            }
         }
      if(symbolfront=="EUR"){
         currentfront = arrEUR[0]*10000;
         for(g=0; g<30; g++) {
            CCfront[timeframe,g] = arrEUR[g]*10000;
            }
         }
      if(symbolfront=="AUD"){
         currentfront = arrAUD[0]*10000;
         for(g=0; g<30; g++) {
            CCfront[timeframe,g] = arrAUD[g]*10000;
            }
         }
      if(symbolfront=="CAD"){
         currentfront = arrCAD[0]*10000; 
         for(g=0; g<30; g++) {
            CCfront[timeframe,g] = arrCAD[g]*10000;
            }
        }
      if(symbolfront=="NZD"){
         currentfront = arrNZD[0]*10000; 
         for(g=0; g<30; g++) {
            CCfront[timeframe,g] = arrNZD[g]*10000;
           }
         }
//-------------------------------------------------------------------- Symbol Back
     if(symbolback=="JPY"){
         currentback = arrJPY[0]*10000; 
         for(g=0; g<30; g++) {
            CCback[timeframe,g] = arrJPY[g]*10000;
            }
         }
      if(symbolback=="USD"){
         currentback = arrUSD[0]*10000;
         for(g=0; g<30; g++) {
            CCback[timeframe,g] = arrUSD[g]*10000;
            }
        }
      if(symbolback=="CHF"){
         currentback = arrCHF[0]*10000;
         for(g=0; g<30; g++) {
            CCback[timeframe,g] = arrCHF[g]*10000;
            }
         }
      if(symbolback=="CAD"){
         currentback = arrCAD[0]*10000;
         for(g=0; g<30; g++) {
            CCback[timeframe,g] = arrCAD[g]*10000;
            }
         }
      if(symbolback=="GBP"){
         currentback = arrGBP[0]*10000;
         for(g=0; g<30; g++) {
           CCback[timeframe,g] = arrGBP[g]*10000;
           }
        }
   }
   return(0);
}
//----------------------------------------------------------------
void CCstatus(int timeframe)
{
   int diverg = 0;
   int frontbull = 0;
   int backbull = 0;
   int frontbear = 0;
   int backbear = 0;
   
      frontStat[timeframe] = ""; backStat[timeframe] = "";
      for(int c=1; c<lookback; c++) {
         
         if(CCfront[timeframe,c] < CCfront[timeframe,0] && iClose(NULL,timeframe,c) > iClose(NULL,timeframe,0)) frontbull++; // are these accurate?
         if(CCback[timeframe,c] > CCback[timeframe,0] && iClose(NULL,timeframe,c) > iClose(NULL,timeframe,0)) backbull++;
         if(CCfront[timeframe,c] > CCfront[timeframe,0] && iClose(NULL,timeframe,c) < iClose(NULL,timeframe,0)) frontbear++;
         if(CCback[timeframe,c] < CCback[timeframe,0] && iClose(NULL,timeframe,c) < iClose(NULL,timeframe,0)) backbear++;
         }
      if(frontbull>backbull) frontStat[timeframe]=StringConcatenate("Bull-",frontbull);
      if(frontbear>backbear) frontStat[timeframe]=StringConcatenate("Bear-",frontbear);
      
      if(backbull>backbear) backStat[timeframe]=StringConcatenate("Bull-",backbull);
      if(backbear>backbull) backStat[timeframe]=StringConcatenate("Bear-",backbear);

      if(CCfront[timeframe,0] == 0.0) frontStat[timeframe] = "Data";
      if(CCback[timeframe,0] == 0.0) backStat[timeframe] = "Data";
       
   return(0);
}
//-------------------------------------------------------------- CCI extreme hook
void CCIhook(int timeframe)
{
   int cci=iCCI(NULL,timeframe,cciper,PRICE_TYPICAL,0);
   int ccip=iCCI(NULL,timeframe,cciper,PRICE_TYPICAL,1);
   int ccipp=iCCI(NULL,timeframe,cciper,PRICE_TYPICAL,2);
   
   CCIhook[timeframe] = "";
   if(ccip>ExtremeHookHigh && cci<ccip && ccip>=ccipp) CCIhook[timeframe]="Bear";
   if(ccip<ExtremeHookLow && cci>ccip && ccip<=ccipp) CCIhook[timeframe]="Bull";
   
   return(0);
}
//----------------------------------------------------------------
void ComboCheck(int timeframe)
{
   bool ccid_bull = StringFind(ccistat[timeframe],"Bull",0)>=0;
   bool ccid_bear = StringFind(ccistat[timeframe],"Bear",0)>=0;
   
   bool ccf_bull = StringFind(frontStat[timeframe],"Bull",0)>=0;
   bool ccf_bear = StringFind(frontStat[timeframe],"Bear",0)>=0;
   
   bool ccb_bull = StringFind(backStat[timeframe],"Bull",0)>=0;
   bool ccb_bear = StringFind(backStat[timeframe],"Bear",0)>=0;
   
   if(comboAlarm[timeframe]==true && comboTime[timeframe]!=iTime(NULL,timeframe,0)) {
      if(ccid_bull && ccf_bull && ccb_bull) {Alert(StringConcatenate(Symbol()," - ",TFlabels[timeframe]," -"," Bullish Combo!")); }
      if(ccid_bear && ccf_bear && ccb_bear) {Alert(StringConcatenate(Symbol()," - ",TFlabels[timeframe]," -"," Bearish Combo!")); }
      comboTime[timeframe]=iTime(NULL,timeframe,0);
      }
      
      
   return(0);
}
//----------------------------------------------------------------------
void SuperComboCheck()
{
if(SuperComboAlarm==true){
   int tf;
   bool ccid_bull, ccid_bear, ccf_bull, ccf_bear, ccb_bull, ccb_bear;
   
   for(int j=0; j<9; j++) {
      tf = timeframes[j];
      SCBull[tf] = false;
      SCBear[tf] = false;
   
      ccid_bull = StringFind(ccistat[tf],"Bull",0)>=0;
      ccid_bear = StringFind(ccistat[tf],"Bear",0)>=0;
   
      ccf_bull = StringFind(frontStat[tf],"Bull",0)>=0;
      ccf_bear = StringFind(frontStat[tf],"Bear",0)>=0;
   
      ccb_bull = StringFind(backStat[tf],"Bull",0)>=0;
      ccb_bear = StringFind(backStat[tf],"Bear",0)>=0;
      
      if(ccid_bull && ccf_bull && ccb_bull) SCBull[tf] = true;
      if(ccid_bear && ccf_bear && ccb_bear) SCBear[tf] = true;      
      }

   if (SCBull[1] && SCBull[5]) {
      if(SuperComboTime[1] != iTime(NULL,1,0)) {
         Alert(StringConcatenate(Symbol()," - ",TFlabels[1]," & ",TFlabels[5],","," Super Bullish Combo!"));
         SuperComboTime[1] = iTime(NULL,1,0);
         //ExtMapBuffer1[0]=100;
         }
      }
   if (SCBull[5] && SCBull[15]) {
      if(SuperComboTime[5] != iTime(NULL,5,0)) {
         Alert(StringConcatenate(Symbol()," - ",TFlabels[5]," & ",TFlabels[15],","," Super Bullish Combo!"));
         SuperComboTime[5] = iTime(NULL,5,0);
         //ExtMapBuffer1[0]=100;
         }
      }
   if (SCBull[15] && SCBull[30]) {
      if(SuperComboTime[15] != iTime(NULL,15,0)) {
         Alert(StringConcatenate(Symbol()," - ",TFlabels[15]," & ",TFlabels[30],","," Super Bullish Combo!"));
         SuperComboTime[15] = iTime(NULL,15,0);
         //ExtMapBuffer1[0]=100;
         }
      } 
   if (SCBull[30] && SCBull[60]) {
      if(SuperComboTime[30] != iTime(NULL,30,0)) {
         Alert(StringConcatenate(Symbol()," - ",TFlabels[30]," & ",TFlabels[60],","," Super Bullish Combo!"));
         SuperComboTime[30] = iTime(NULL,30,0);
         ExtMapBuffer1[0]=100;
         }
      }
   if (SCBull[60] && SCBull[240]) {
      if(SuperComboTime[60] != iTime(NULL,60,0)) {
         Alert(StringConcatenate(Symbol()," - ",TFlabels[60]," & ",TFlabels[240],","," Super Bullish Combo!"));
         SuperComboTime[60] = iTime(NULL,60,0);
         ExtMapBuffer1[0]=100;
         }
      }  
   if (SCBull[240] && SCBull[1440]) {
      if(SuperComboTime[240] != iTime(NULL,240,0)) {
         Alert(StringConcatenate(Symbol()," - ",TFlabels[240]," & ",TFlabels[1440],","," Super Bullish Combo!"));
         SuperComboTime[240] = iTime(NULL,240,0);
         ExtMapBuffer1[0]=100;
         }
      }
   if (SCBear[1] && SCBear[5]) {
      if(SuperComboTime[1] != iTime(NULL,1,0)) {
         Alert(StringConcatenate(Symbol()," - ",TFlabels[1]," & ",TFlabels[5],","," Super Bearish Combo!"));
         SuperComboTime[1] = iTime(NULL,1,0);
         //ExtMapBuffer1[0]=-100;
         }
      }
   if (SCBear[5] && SCBear[15]) {
      if(SuperComboTime[5] != iTime(NULL,5,0)) {
         Alert(StringConcatenate(Symbol()," - ",TFlabels[5]," & ",TFlabels[15],","," Super Bearish Combo!"));
         SuperComboTime[5] = iTime(NULL,5,0);
         //ExtMapBuffer1[0]=-100;
         }
      }
   if (SCBear[15] && SCBear[30]) {
      if(SuperComboTime[15] != iTime(NULL,15,0)) {
         Alert(StringConcatenate(Symbol()," - ",TFlabels[15]," & ",TFlabels[30],","," Super Bearish Combo!"));
         SuperComboTime[15] = iTime(NULL,15,0);
         //ExtMapBuffer1[0]=-100;
         }
      }
   if (SCBear[30] && SCBear[60]) {
      if(SuperComboTime[30] != iTime(NULL,30,0)) {
         Alert(StringConcatenate(Symbol()," - ",TFlabels[30]," & ",TFlabels[60],","," Super Bearish Combo!"));
         SuperComboTime[30] = iTime(NULL,30,0);
         ExtMapBuffer1[0]=-100;
         }
      }
   if (SCBear[60] && SCBear[240]) {
      if(SuperComboTime[60] != iTime(NULL,60,0)) {
         Alert(StringConcatenate(Symbol()," - ",TFlabels[60]," & ",TFlabels[240],","," Super Bearish Combo!"));
         SuperComboTime[60] = iTime(NULL,60,0);
         ExtMapBuffer1[0]=-100;
         }
      }
   if (SCBear[240] && SCBear[1440]) {
      if(SuperComboTime[24] != iTime(NULL,24,0)) {
         Alert(StringConcatenate(Symbol()," - ",TFlabels[240]," & ",TFlabels[1440],","," Super Bearish Combo!"));
         SuperComboTime[24] = iTime(NULL,24,0);
         ExtMapBuffer1[0]=-100;
         }
      }
      
      
   return(0);
   }
}
//---------------------------------------------------------------------------------------------------------------

Комментарии к исходному коду форекс индикатора !CCI-Divergence-Master-v13c.mq4
В целях безопасности и борьбы со спамом в тексте комментариев запрещено размещать html-теги и ссылки. Благодарим за понимание.

  • X
  • 0% загружено
« индикатор !BySu-Fx info 3.0.mq4
индикатор !CrazyEddyBoxes.mq4 »