CC_at_s_v2_001





//+------------------------------------------------------------------+
//|                                                           CC.mq4 |
//|                                              SemSemFX@rambler.ru |
//|              http://onix-trade.net/forum/index.php?showtopic=107 |
//+------------------------------------------------------------------+
#property copyright "SemSemFX@rambler.ru"
#property link      "http://onix-trade.net/forum/index.php?showtopic=107"
string Indicator_Name="CC:    ";
int Objs=0;

double f1;
double kp;
string para;
string tr;

double f2;
double kp2;
string para2;
string tr2;

#property indicator_separate_window
#property indicator_buffers 8
//---- parameters
extern int MA_Method=3;
extern int Price=6;
extern bool USD = 1;
extern bool EUR = 1;
extern bool GBP = 1;
extern bool CHF = 1;
extern bool JPY = 1;
extern bool AUD = 0;
extern bool CAD = 0;
extern bool NZD = 0;
extern color Color_USD = LimeGreen;
extern color Color_EUR = Aqua;
extern color Color_GBP = Red;
extern color Color_CHF = Gray;
extern color Color_JPY = Yellow;
extern color Color_AUD = DarkOrange;
extern color Color_CAD = Magenta;
extern color Color_NZD = Teal;
extern int Line_Thickness = 3;
extern int Bars.Count = 100;
// for monthly
extern int mn_per = 12;
extern int mn_fast = 3;
// for weekly
extern int w_per = 9;
extern int w_fast = 3;
// for daily
extern int d_per = 5;
extern int d_fast = 3;
// for H4
extern int h4_per = 18;
extern int h4_fast = 6;
// for H1
extern int h1_per = 24;
extern int h1_fast = 8;
// for M30
extern int m30_per = 16;
extern int m30_fast = 2;
// for M15
extern int m15_per = 16;
extern int m15_fast = 4;
// for M5
extern int m5_per = 12;
extern int m5_fast = 3;
// for M1
extern int m1_per = 30;
extern int m1_fast = 10;


double arrUSD[];
double arrEUR[];
double arrGBP[];
double arrCHF[];
double arrJPY[];
double arrAUD[];
double arrCAD[];
double arrNZD[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   if (USD)Indicator_Name=StringConcatenate(Indicator_Name," USDm");
   if (EUR)Indicator_Name=StringConcatenate(Indicator_Name," EURm");
   if (GBP)Indicator_Name=StringConcatenate(Indicator_Name," GBPm");
   if (CHF)Indicator_Name=StringConcatenate(Indicator_Name," CHFm");
   if (AUD)Indicator_Name=StringConcatenate(Indicator_Name," AUDm");
   if (CAD)Indicator_Name=StringConcatenate(Indicator_Name," CADm");
   if (JPY)Indicator_Name=StringConcatenate(Indicator_Name," JPYm");
   if (NZD)Indicator_Name=StringConcatenate(Indicator_Name," NZDm");
   IndicatorShortName(Indicator_Name);
   int cur=0; 
   int st=23; 
   if (USD){sl("~",cur,Color_USD);cur+=st;}
   if (EUR){sl("~",cur,Color_EUR);cur+=st;}
   if (GBP){sl("~",cur,Color_GBP);cur+=st;}
   if (CHF){sl("~",cur,Color_CHF);cur+=st;}
   if (AUD){sl("~",cur,Color_AUD);cur+=st;}
   if (CAD){sl("~",cur,Color_CAD);cur+=st;}
   if (JPY){sl("~",cur,Color_JPY);cur+=st;}
   if (NZD){sl("~",cur,Color_NZD);cur+=st;}
   
      
   int width=0;
   if(0>StringFind(Symbol(),"USDm",0))width=3;else width=Line_Thickness;
   SetIndexStyle(0,DRAW_LINE,DRAW_LINE,width,Color_USD);
   SetIndexBuffer(0,arrUSD);
   SetIndexLabel(0, "USDm"); 
   if(0>StringFind(Symbol(),"EURm",0))width=3;else width=Line_Thickness;
   SetIndexStyle(1,DRAW_LINE,DRAW_LINE,width,Color_EUR);
   SetIndexBuffer(1,arrEUR);
   SetIndexLabel(1, "EURm"); 
   if(0>StringFind(Symbol(),"GBPm",0))width=3;else width=Line_Thickness;
   SetIndexStyle(2,DRAW_LINE,DRAW_LINE,width,Color_GBP);
   SetIndexBuffer(2,arrGBP);
   SetIndexLabel(2, "GBPm"); 
   if(0>StringFind(Symbol(),"CHFm",0))width=3;else width=Line_Thickness;
   SetIndexStyle(3,DRAW_LINE,DRAW_LINE,width,Color_CHF);
   SetIndexBuffer(3,arrCHF);
   SetIndexLabel(3, "CHFm"); 
   if(0>StringFind(Symbol(),"JPYm",0))width=3;else width=Line_Thickness;
   SetIndexStyle(4,DRAW_LINE,DRAW_LINE,width,Color_JPY);
   SetIndexBuffer(4,arrJPY);
   SetIndexLabel(4, "JPYm"); 
   if(0>StringFind(Symbol(),"AUDm",0))width=3;else width=Line_Thickness;
   SetIndexStyle(5,DRAW_LINE,DRAW_LINE,width,Color_AUD);
   SetIndexBuffer(5,arrAUD);
   SetIndexLabel(5, "AUDm"); 
   if(0>StringFind(Symbol(),"CADm",0))width=3;else width=Line_Thickness;
   SetIndexStyle(6,DRAW_LINE,DRAW_LINE,width,Color_CAD);
   SetIndexBuffer(6,arrCAD);
   SetIndexLabel(6, "CADm"); 
   if(0>StringFind(Symbol(),"NZDm",0))width=3;else width=Line_Thickness;
   SetIndexStyle(7,DRAW_LINE,DRAW_LINE,width,Color_NZD);
   SetIndexBuffer(7,arrNZD);
   SetIndexLabel(7, "NZDm"); 
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   for(int i=0; i<Objs; i++){
      if(!ObjectDelete(Indicator_Name+i))
         Print("error: code #",GetLastError());
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
     int limit;
     int counted_bars=IndicatorCounted();
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars+Bars.Count;
     int Slow,Fast;
     color wt;
     switch(Period())
       {
         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<limit; i++){
      // Ïðåäâàðèòåëüíûé ðàññ÷åò
      if (EUR){
         double EURUSD_Fast=ma("EURUSDm",Fast,MA_Method,Price,i);
         double EURUSD_Slow=ma("EURUSDm",Slow,MA_Method,Price,i);
         if (!EURUSD_Fast || !EURUSD_Slow)break;
      }
      if (GBP){
         double GBPUSD_Fast=ma("GBPUSDm",Fast,MA_Method,Price,i);
         double GBPUSD_Slow=ma("GBPUSDm",Slow,MA_Method,Price,i);
         if (!GBPUSD_Fast || !GBPUSD_Slow)break;
      }
      if (AUD){
         double AUDUSD_Fast=ma("AUDUSDm",Fast,MA_Method,Price,i);
         double AUDUSD_Slow=ma("AUDUSDm",Slow,MA_Method,Price,i);
         if (!AUDUSD_Fast || !AUDUSD_Slow)break;
      }
      if (NZD){
         double NZDUSD_Fast=ma("NZDUSDm",Fast,MA_Method,Price,i);
         double NZDUSD_Slow=ma("NZDUSDm",Slow,MA_Method,Price,i);
         if (!NZDUSD_Fast || !NZDUSD_Slow)break;
      }
      if (CAD){
         double USDCAD_Fast=ma("USDCADm",Fast,MA_Method,Price,i);
         double USDCAD_Slow=ma("USDCADm",Slow,MA_Method,Price,i);
         if (!USDCAD_Fast || !USDCAD_Slow)break;
      }
      if (CHF){
         double USDCHF_Fast=ma("USDCHFm",Fast,MA_Method,Price,i);
         double USDCHF_Slow=ma("USDCHFm",Slow,MA_Method,Price,i);
         if (!USDCHF_Fast || !USDCHF_Slow)break;
      }
      if (JPY){
         double USDJPY_Fast=ma("USDJPYm",Fast,MA_Method,Price,i)/100;
         double USDJPY_Slow=ma("USDJPYm",Slow,MA_Method,Price,i)/100;
         if (!USDJPY_Fast || !USDJPY_Slow)break;
      }
      // ðàññ÷åò âàëþò
      if (USD){
         arrUSD[i]=0;
         if (EUR) arrUSD[i]+=EURUSD_Slow-EURUSD_Fast;
         if (GBP) arrUSD[i]+=GBPUSD_Slow-GBPUSD_Fast;
         if (CHF) arrUSD[i]+=USDCHF_Fast-USDCHF_Slow;
         if (JPY) arrUSD[i]+=USDJPY_Fast-USDJPY_Slow;
      }// end if USD
      if (EUR){
         arrEUR[i]=0;
         if (USD) arrEUR[i]+=EURUSD_Fast-EURUSD_Slow;
         if (GBP) arrEUR[i]+=(EURUSD_Fast/GBPUSD_Fast-EURUSD_Slow/GBPUSD_Slow)*ma("EURUSDm",1,MA_Method,Price,i);
         if (CHF) arrEUR[i]+=(EURUSD_Fast*USDCHF_Fast-EURUSD_Slow*USDCHF_Slow)*ma("EURUSDm",1,MA_Method,Price,i);
         if (JPY) arrEUR[i]+=(EURUSD_Fast*USDJPY_Fast-EURUSD_Slow*USDJPY_Slow)*ma("EURUSDm",1,MA_Method,Price,i);
      }// end if EUR
      if (GBP){
         arrGBP[i]=0;
         if (USD) arrGBP[i]+=GBPUSD_Fast-GBPUSD_Slow;
         if (EUR) arrGBP[i]+=(EURUSD_Slow/GBPUSD_Slow-EURUSD_Fast/GBPUSD_Fast)*ma("GBPUSDm",1,MA_Method,Price,i);
         if (CHF) arrGBP[i]+=(GBPUSD_Fast*USDCHF_Fast-GBPUSD_Slow*USDCHF_Slow)*ma("GBPUSDm",1,MA_Method,Price,i);
         if (JPY) arrGBP[i]+=(GBPUSD_Fast*USDJPY_Fast-GBPUSD_Slow*USDJPY_Slow)*ma("GBPUSDm",1,MA_Method,Price,i);
      }// end if GBP        
      if (CHF){
         arrCHF[i]=0;
         if (USD) arrCHF[i]+=USDCHF_Slow-USDCHF_Fast;
         if (EUR) arrCHF[i]+=(EURUSD_Slow*USDCHF_Slow-EURUSD_Fast*USDCHF_Fast)*ma("USDCHFm",1,MA_Method,Price,i);
         if (GBP) arrCHF[i]+=(GBPUSD_Slow*USDCHF_Slow-GBPUSD_Fast*USDCHF_Fast)*ma("USDCHFm",1,MA_Method,Price,i);
         if (JPY) arrCHF[i]+=(USDJPY_Fast/USDCHF_Fast-USDJPY_Slow/USDCHF_Slow)*ma("USDCHFm",1,MA_Method,Price,i);
      }// end if CHF
      if (JPY){
         arrJPY[i]=0;
         if (USD) arrJPY[i]+=USDJPY_Slow-USDJPY_Fast;
         if (EUR) arrJPY[i]+=(EURUSD_Slow*USDJPY_Slow-EURUSD_Fast*USDJPY_Fast)*ma("USDJPYm",1,MA_Method,Price,i)/100;
         if (GBP) arrJPY[i]+=(GBPUSD_Slow*USDJPY_Slow-GBPUSD_Fast*USDJPY_Fast)*ma("USDJPYm",1,MA_Method,Price,i)/100;
         if (CHF) arrJPY[i]+=(USDJPY_Slow/USDCHF_Slow-USDJPY_Fast/USDCHF_Fast)*ma("USDJPYm",1,MA_Method,Price,i)/100;
      }// end if JPY
     
    f1=0; f2=0;
     // Eur/Usd
     kp=(arrEUR[0]-arrEUR[1])-(arrUSD[0]-arrUSD[1]);
          if (MathAbs(kp)>f1)
           {para2=para; f2=f1; tr2=tr; para="EURm/USDm"; f1=MathAbs(kp);
             if (kp>0) tr="buy"; if (kp<0) tr="sell";}
     // Eur/Gbp    
     kp=(arrEUR[0]-arrEUR[1])-(arrGBP[0]-arrGBP[1]);
          if (MathAbs(kp)>f1)
           {para2=para; f2=f1; tr2=tr; para="EURm/GBPm"; f1=MathAbs(kp);
             if (kp>0) tr="buy"; if (kp<0) tr="sell";}
     // Eur/Chf    
     kp=(arrEUR[0]-arrEUR[1])-(arrCHF[0]-arrCHF[1]);
          if (MathAbs(kp)>f1)
           {para2=para; f2=f1; tr2=tr; para="EURm/CHFm"; f1=MathAbs(kp);
             if (kp>0) tr="buy"; if (kp<0) tr="sell";}
     // Eur/Jpy    
     kp=(arrEUR[0]-arrEUR[1])-(arrJPY[0]-arrJPY[1]);
          if (MathAbs(kp)>f1)
           {para2=para; f2=f1; tr2=tr; para="EURm/JPYm"; f1=MathAbs(kp);
             if (kp>0) tr="buy"; if (kp<0) tr="sell";}
     // Gbp/Usd    
     kp=(arrGBP[0]-arrGBP[1])-(arrUSD[0]-arrUSD[1]);
          if (MathAbs(kp)>f1)
            {para2=para; f2=f1; tr2=tr; para="GBPm/USDm"; f1=MathAbs(kp);
             if (kp>0) tr="buy"; if (kp<0) tr="sell";}
     // Gbp/Chf    
     kp=(arrGBP[0]-arrGBP[1])-(arrCHF[0]-arrCHF[1]);
          if (MathAbs(kp)>f1)
           {para2=para; f2=f1; tr2=tr; para="GBPm/CHFm"; f1=MathAbs(kp);
             if (kp>0) tr="buy"; if (kp<0) tr="sell";}
     // Gbp/Jpy
     kp=(arrGBP[0]-arrGBP[1])-(arrJPY[0]-arrJPY[1]);
          if (MathAbs(kp)>f1)
           {para2=para; f2=f1; tr2=tr; para="GBPm/JPYm"; f1=MathAbs(kp);
             if (kp>0) tr="buy"; if (kp<0) tr="sell";}
     // Usd/Chf    
     kp=(arrUSD[0]-arrUSD[1])-(arrCHF[0]-arrCHF[1]);
          if (MathAbs(kp)>f1)
           {para2=para; f2=f1; tr2=tr; para="USDm/CHFm"; f1=MathAbs(kp);
            if (kp>0) tr="buy"; if (kp<0) tr="sell";}
     // Usd/Jpy    
     kp=(arrUSD[0]-arrUSD[1])-(arrJPY[0]-arrJPY[1]);
          if (MathAbs(kp)>f1)
           {para2=para; f2=f1; tr2=tr; para="USDm/JPYm"; f1=MathAbs(kp);
            if (kp>0) tr="buy"; if (kp<0) tr="sell";}                             
     }//end block for(int i=0; i<limit; i++)
  //----
      ObjectDelete("ob"); 
      ObjectCreate("ob", OBJ_LABEL, 1, 0, 0);
      ObjectSet("ob", OBJPROP_CORNER, 1);
      ObjectSet("ob", OBJPROP_XDISTANCE, 5);
      ObjectSet("ob", OBJPROP_YDISTANCE, 2);
      ObjectSetText("ob", para, 12, "Arial Black", White);  
    if (tr=="buy") wt=LimeGreen; else wt=Red;
      ObjectDelete("ob1"); 
      ObjectCreate("ob1", OBJ_LABEL, 1, 0, 0);
      ObjectSet("ob1", OBJPROP_CORNER, 1);
      ObjectSet("ob1", OBJPROP_XDISTANCE, 5);
      ObjectSet("ob1", OBJPROP_YDISTANCE, 22);
      ObjectSetText("ob1", tr, 12, "Arial Black", wt);
      ObjectDelete("ob2"); 
      ObjectCreate("ob2", OBJ_LABEL, 1, 0, 0);
      ObjectSet("ob2", OBJPROP_CORNER, 1);
      ObjectSet("ob2", OBJPROP_XDISTANCE, 5);
      ObjectSet("ob2", OBJPROP_YDISTANCE, 42);
      tr=DoubleToStr(f1,4);
      ObjectSetText("ob2", tr, 10, "Arial Black", DodgerBlue);
      
      ObjectDelete("ob3"); 
      ObjectCreate("ob3", OBJ_LABEL, 1, 0, 0);
      ObjectSet("ob3", OBJPROP_CORNER, 3);
      ObjectSet("ob3", OBJPROP_XDISTANCE, 5);
      ObjectSet("ob3", OBJPROP_YDISTANCE, 42);
      ObjectSetText("ob3", para2, 12, "Arial Black", White);  
    if (tr2=="buy") wt=LimeGreen; else wt=Red;
      ObjectDelete("ob4"); 
      ObjectCreate("ob4", OBJ_LABEL, 1, 0, 0);
      ObjectSet("ob4", OBJPROP_CORNER, 3);
      ObjectSet("ob4", OBJPROP_XDISTANCE, 5);
      ObjectSet("ob4", OBJPROP_YDISTANCE, 22);
      ObjectSetText("ob4", tr2, 12, "Arial Black", wt);
    ObjectDelete("ob5"); 
      ObjectCreate("ob5", OBJ_LABEL, 1, 0, 0);
      ObjectSet("ob5", OBJPROP_CORNER, 3);
      ObjectSet("ob5", OBJPROP_XDISTANCE, 5);
      ObjectSet("ob5", OBJPROP_YDISTANCE, 2);
      tr=DoubleToStr(f2,4);
      ObjectSetText("ob5", tr, 10, "Arial Black", DodgerBlue);
      
         
   return(0);
  }
//+------------------------------------------------------------------+

// Subroutines
double ma(string sym, int per, int Mode, int Price, int i){
   return(iMA(sym,0,per,0,Mode,Price,i));
}   

void sl(string sym, int y, color col){
   int window=WindowFind(Indicator_Name);
   string ID=Indicator_Name+Objs;
   Print("ID:",ID);
   int tmp=10+y;
   Objs++;
   if (ObjectCreate(ID, OBJ_LABEL, window, 0, 0)){
      //ObjectSet(ID, OBJPROP_CORNER, 1);
      ObjectSet(ID, OBJPROP_XDISTANCE, y+35);
      ObjectSet(ID, OBJPROP_YDISTANCE, 0);
      ObjectSetText(ID, sym, 18, "Arial Black", col); 
   }
}   
   

   






Sample





Analysis



Market Information Used:



Indicator Curves created:

Implements a curve of type DRAW_LINE


Indicators Used:

Moving average indicator


Custom Indicators Used:

Order Management characteristics:

Other Features: