//+------------------------------------------------------------------+
//|                                       Candle Time & Spread H1.mq4|
//|    Modificado en Forex.es por "refresco", "MF1Forex" y "FXWizard"|
//|                             (2014)Indicador para minutos/segundos|
//+------------------------------------------------------------------+

#property indicator_chart_window
double s1[];
extern color  Clock_Color = OrangeRed;
extern string Corner_Placement = "1 is top right 3 is bottom right";
extern string Unidades = "Cervezas";
extern int    Corner = 3;
extern int    Divisor = 10;


//---- input parameters

//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init(){

   
   //----
   return(0);
}
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit(){
ObjectDelete("X601");
ObjectDelete("X602");
ObjectDelete("X603");
ObjectDelete("X604");
ObjectDelete("X605");
ObjectDelete("X606");
ObjectDelete("X607");
ObjectDelete("X608");

   return(0);
} 


//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start(){
  
     //Time to bar expiry
	double g;
   int m,s,k,p,h;
   m=TimeCurrent()-Time[0]+Period()*60;
   g=m/60.0;
   s=m%60;
   p=(m-m%60)/60;
   m=p-Period();
   //Comment(m + " minutes " + s + " seconds in actual bar");
   g=NormalizeDouble(g,1);
   for (k=1;k<=Bars-1;k++) s1[k]=0.0000001;
   for (k=1;k<=2;k++) s1[k]=g;
    
 
//end bar expiry


//calculate spread
 double ma=MarketInfo(Symbol(),MODE_SPREAD)/Divisor;
 //end calculate spread

//Calcula % variación diaria
 double variacion=100*(iClose(NULL,PERIOD_D1,0)-iClose(NULL,PERIOD_D1,1))/iClose(NULL,PERIOD_D1,0);
 //end calculate spread
 
 
 
 //CALCULALE PIPS WIN or LOSE
 bool allSymbols=false;
double profit=0;
   double pr=0;
   
   double se=0;
      
   for(int i=0;i<OrdersTotal();i++) {
    if(OrderSelect(i,SELECT_BY_POS)) {
     
     if(allSymbols || OrderSymbol()==Symbol()) {
      
      pr=0;
      se=0;
      
      if(OrderType()==OP_BUY) {
       pr=(Bid-OrderOpenPrice())/(Divisor*Point);
       
      }
      
      if(OrderType()==OP_SELL) {
       pr=(OrderOpenPrice()-Ask)/(Divisor*Point);
       
      }
      
      
      profit+=pr;
     
     }
    }
   }
   
  double out=profit/10;
  
  string sign=" ";
  if(out>0)     sign="+";
 //_______________________________
 //----------------------------------
 
       ObjectCreate("X608", OBJ_LABEL,0, 0, 0);
           ObjectSetText("X608","Var. Diaria: " + DoubleToStr(variacion, 2) + "%", 10, "Arial", Clock_Color);
           ObjectSet("X608", OBJPROP_CORNER, Corner);
           ObjectSet("X608", OBJPROP_XDISTANCE, 320);
           ObjectSet("X608", OBJPROP_YDISTANCE, 5);  
 
   
       ObjectCreate("X603", OBJ_LABEL,0, 0, 0);
           ObjectSetText("X603","Spread: " + DoubleToStr(ma, 1), 10, "Arial", Clock_Color);
           ObjectSet("X603", OBJPROP_CORNER, Corner);
           ObjectSet("X603", OBJPROP_XDISTANCE, 200);
           ObjectSet("X603", OBJPROP_YDISTANCE, 5);     
        
    ObjectCreate("X601", OBJ_LABEL, 0, 0, 0);
        ObjectSetText("X601","Vela:  " + DoubleToStr(m,0) + ":" + DoubleToStr(s,0),10, "Arial", Clock_Color);
        ObjectSet("X601", OBJPROP_CORNER, Corner);
        ObjectSet("X601", OBJPROP_XDISTANCE, 75);
        ObjectSet("X601", OBJPROP_YDISTANCE, 5);
   

        ObjectCreate("X606", OBJ_LABEL, 0, 0, 0);
        ObjectSetText("X606",DoubleToStr(out,1), 20, "Arial", Clock_Color);
        ObjectSet("X606", OBJPROP_CORNER, Corner);
        ObjectSet("X606", OBJPROP_XDISTANCE, 125);
        ObjectSet("X606", OBJPROP_YDISTANCE, 30);
        
        
        ObjectCreate("X607", OBJ_LABEL, 0, 0, 0);
        ObjectSetText("X607",Unidades, 14, "Arial", Clock_Color);
        ObjectSet("X607", OBJPROP_CORNER, Corner);
        ObjectSet("X607", OBJPROP_XDISTANCE, 33);
        ObjectSet("X607", OBJPROP_YDISTANCE, 30);
   return(0);
}
//+---------------------------------------------------------