//////////////////////////////////////////////////////////////////////
//
//                                                  signalTable.mq4  
//
//////////////////////////////////////////////////////////////////////
#property copyright ""
#property link      ""

#property indicator_chart_window

extern string ____1____ = "Настройки для машек";
extern int period_MA1        = 5;
extern int ma_method_MA1     = 0;
extern int applied_price_MA1 = 0;
extern int period_MA2        = 12;
extern int ma_method_MA2     = 0;
extern int applied_price_MA2 = 0;

extern string ____2____ = "Настройки RSI";
extern int period_rsi        =21;
extern int applied_price_rsi =0;

extern string ____3____ = "Настройки CCI";
extern int period_CCI        =14;
extern int applied_price_CCI =0;

extern string ____4____ = " Коды стрелок";
extern int symbolCodeBuy=221, 
           symbolCodeSell=222, 
           symbolCodeNoSignal=175;

extern string ____5____ = "Настройки цветов";
extern color noSignalColor=MediumPurple,
             BayColor = Lime,
             SellColor = Red,
             textColor=Gold;
                        
extern string ___6___ = "Координаты_на_графике";            
extern int scaleX=20,
           scaleY=20,
           offsetX=35,
           offsetY=20,
           fontSize=20,
           corner=1;            
            
int period[]={1,5,15,30,60,240,1440,10080,43200};  
string periodString[]={"M1","M5","M15","M30","H1","H4","D1","W1","MN1"},
       // создаем еще один массив с названиями индикаторов
       signalNameString[]={"2MA","RSI","CCI","Bar","Gep"};

//////////////////////////////////////////////////////////////////////
//
// init()          
//
//////////////////////////////////////////////////////////////////////
int init()
{
   // таблица сигналов
   for(int x=0;x<9;x++)
      for(int y=0;y<5;y++)
      {
         ObjectCreate("signal"+x+y,OBJ_LABEL,0,0,0,0,0);
         // изменяем угол привязки
         ObjectSet("signal"+x+y,OBJPROP_CORNER,corner);
         ObjectSet("signal"+x+y,OBJPROP_XDISTANCE,x*scaleX+offsetX);
         ObjectSet("signal"+x+y,OBJPROP_YDISTANCE,y*scaleY+20);
         ObjectSetText("signal"+x+y,CharToStr(symbolCodeNoSignal),
                       fontSize,"Wingdings",noSignalColor);
      }
  
  // названия таймфреймов    
  for(x=0;x<9;x++)
  {
      ObjectCreate("textPeriod"+x,OBJ_LABEL,0,0,0,0,0);   
      // изменяем угол привязки      
      ObjectSet("textPeriod"+x,OBJPROP_CORNER,corner);
      ObjectSet("textPeriod"+x,OBJPROP_XDISTANCE,x*scaleX+offsetX);
      ObjectSet("textPeriod"+x,OBJPROP_YDISTANCE,offsetY-10);
      ObjectSetText("textPeriod"+x,periodString[x],8,"Tahoma",textColor);
  }
  
  // названия индикаторов 
  for(y=0;y<5;y++)
  {
      ObjectCreate("textSignal"+y,OBJ_LABEL,0,0,0,0,0);   
      // изменяем угол привязки      
      ObjectSet("textSignal"+y,OBJPROP_CORNER,corner);
      ObjectSet("textSignal"+y,OBJPROP_XDISTANCE,offsetX-25);
      ObjectSet("textSignal"+y,OBJPROP_YDISTANCE,y*(scaleY)+offsetY+8);
      ObjectSetText("textSignal"+y,signalNameString[y],8,"Tahoma",textColor);      
  }
  return(0);
}
  
int start()
{
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx--MA--xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
   for(int x=0;x<9;x++)
   {
      double MA1 = iMA(Symbol(),period[x],period_MA1,0,ma_method_MA1,applied_price_MA1,0);
      double MA2 = iMA(Symbol(),period[x],period_MA2,0,ma_method_MA2,applied_price_MA2,0);
      if(MA1>MA2)
        ObjectSetText("signal"+x+"0",CharToStr(symbolCodeBuy),fontSize,"Wingdings",BayColor);
      // сигнал на продажу   
      else if(MA1<MA2) 
        ObjectSetText("signal"+x+"0",CharToStr(symbolCodeSell),fontSize,"Wingdings",SellColor);   
   }
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx--RSI--xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
   for(x=0;x<9;x++)
   {
      double rsi = iRSI(Symbol(),period[x],period_rsi,applied_price_rsi,0);
      double rsi_1 = iRSI(Symbol(),period[x],period_rsi,applied_price_rsi,1);
      double del = rsi-rsi_1;
      // сигнал 
      if(rsi>50&&del>0)
        ObjectSetText("signal"+x+"1",CharToStr(symbolCodeBuy),fontSize,"Wingdings",BayColor);
      if(rsi>50&&del<0)
        ObjectSetText("signal"+x+"1",CharToStr(symbolCodeSell),fontSize,"Wingdings",BayColor);        
      // сигнал на продажу   
      else if(rsi<50&&del<0) 
        ObjectSetText("signal"+x+"1",CharToStr(symbolCodeSell),fontSize,"Wingdings",SellColor);
      else if(rsi<50&&del>0) 
        ObjectSetText("signal"+x+"1",CharToStr(symbolCodeBuy),fontSize,"Wingdings",SellColor);           
   }
   
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx--CCI--xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
      for(x=0;x<9;x++)
   {
      double CCI =iCCI(Symbol(),period[x],period_CCI,applied_price_CCI,0);
      double CCI_1 =iCCI(Symbol(),period[x],period_CCI,applied_price_CCI,1);
      double der =CCI-CCI_1;
      if(CCI>100&&der>0)
        ObjectSetText("signal"+x+"2",CharToStr(symbolCodeBuy),fontSize,"Wingdings",BayColor);
      if(CCI>100&&der<0)
        ObjectSetText("signal"+x+"2",CharToStr(symbolCodeSell),fontSize,"Wingdings",BayColor);
        
      if(CCI<100&&CCI>-100&&der>0)
        ObjectSetText("signal"+x+"2",CharToStr(symbolCodeBuy),fontSize,"Wingdings",noSignalColor);
      if(CCI<100&&CCI>-100&&der<0)
        ObjectSetText("signal"+x+"2",CharToStr(symbolCodeSell),fontSize,"Wingdings",noSignalColor);
        
        
      // сигнал на продажу   
      else if(CCI<-100&&der<0) 
        ObjectSetText("signal"+x+"2",CharToStr(symbolCodeSell),fontSize,"Wingdings",SellColor);
      else if(CCI<-100&&der>0) 
        ObjectSetText("signal"+x+"2",CharToStr(symbolCodeBuy),fontSize,"Wingdings",SellColor);         
   }
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx--Bar--xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
   for(x=0;x<9;x++)
   {
    double x00 =iOpen(Symbol(),period[x],0)-iClose(Symbol(),period[x],0);
      // сигнал 
      if(x00<0)
        ObjectSetText("signal"+x+"3",CharToStr(symbolCodeBuy),fontSize,"Wingdings",BayColor);
      // сигнал на продажу   
      else if(x00>0) 
        ObjectSetText("signal"+x+"3",CharToStr(symbolCodeSell),fontSize,"Wingdings",SellColor);   
   } 
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx--Gep--xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx   
      for(x=0;x<9;x++)
   {
      
    double x0 =iOpen(Symbol(),period[x],0)-iClose(Symbol(),period[x],1);


      // сигнал на покупку   
      if(x0>0)
      ObjectSetText("signal"+x+"4",CharToStr(symbolCodeBuy),fontSize,"Wingdings",BayColor);      
      if(x0<0)
      ObjectSetText("signal"+x+"4",CharToStr(symbolCodeSell),fontSize,"Wingdings",SellColor);
      if(x0==0)
      ObjectSetText("signal"+x+"4",CharToStr(symbolCodeNoSignal),fontSize,"Wingdings",noSignalColor);            
   }
//xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 
   
     
   return(0);
}

//////////////////////////////////////////////////////////////////////
//
//  deinit()                       
//
//////////////////////////////////////////////////////////////////////
int deinit()
{
   // при удалении нашего индикатора нужно удалить все объекты,
   // которые мы уже создали

   ObjectsDeleteAll();
   return(0);
}

