//+------------------------------------------------------------------+
//|                                        Boxinglife Stochastic.mq4 |
//|                                                 author : Skyline |
//|                                          email : glicci@yahoo.it |
//+------------------------------------------------------------------+
// You can find me at following forums :
// www.forexpertutti.it (italian forum)
// www.fastbrokers.net/forum (international forum)
// www.forexfactory.com (international forum)

// v1.0 [07 May 2007] ** Indicator created

#property copyright ""
#property link      ""

#property indicator_chart_window
extern color  Color      = Black;
extern int    Label_Size = 20;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
     ObjectDelete("Label_M5");
     ObjectDelete("Label_M15");
     ObjectDelete("Label_M30");   
     ObjectDelete("Label_H1"); 
     ObjectDelete("Label_Stoch5");
     ObjectDelete("Label_Stoch20");
     ObjectDelete("Label_Stoch50"); 
     ObjectDelete("ArrowStoch5_TF5");  
     ObjectDelete("ArrowStoch20_TF5");               
     ObjectDelete("ArrowStoch50_TF5");   
     ObjectDelete("ArrowStoch5_TF15");  
     ObjectDelete("ArrowStoch20_TF15");               
     ObjectDelete("ArrowStoch50_TF15");      
     ObjectDelete("ArrowStoch5_TF30");  
     ObjectDelete("ArrowStoch20_TF30");               
     ObjectDelete("ArrowStoch50_TF30"); 
     ObjectDelete("ArrowStoch5_TF60");  
     ObjectDelete("ArrowStoch20_TF60");               
     ObjectDelete("ArrowStoch50_TF60");                            
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {

         
   int    counted_bars=IndicatorCounted();

   // Disegna label per timeframe
   DrawTFLabel(5,"Label_M5",150,40);
   DrawTFLabel(15,"Label_M15",150,60);
   DrawTFLabel(30,"Label_M30",150,80);
   DrawTFLabel(60,"Label_H1",150,100);
 
   // Disegna label per stoch
   DrawStochLabel(5,"Label_Stoch5",110,20);
   DrawStochLabel(20,"Label_Stoch20",60,20);
   DrawStochLabel(50,"Label_Stoch50",10,20);

   // Disegna Freccie per TF5
   DrawArrow(5,5,"ArrowStoch5_TF5",120,40);
   DrawArrow(5,20,"ArrowStoch20_TF5",75,40);
   DrawArrow(5,50,"ArrowStoch50_TF5",25,40); 

   // Disegna Freccie per TF15   
   DrawArrow(15,5,"ArrowStoch5_TF15",120,60);
   DrawArrow(15,20,"ArrowStoch20_TF15",75,60); 
   DrawArrow(15,50,"ArrowStoch50_TF15",25,60); 
   
   // Disegna Freccie per TF30   
   DrawArrow(30,5,"ArrowStoch5_TF30",120,80);
   DrawArrow(30,20,"ArrowStoch20_TF30",75,80);
   DrawArrow(30,50,"ArrowStoch50_TF30",25,80); 
      
   // Disegna Freccie per TF60   
   DrawArrow(60,5,"ArrowStoch5_TF60",120,100);
   DrawArrow(60,20,"ArrowStoch20_TF60",75,100);
   DrawArrow(60,50,"ArrowStoch50_TF60",25,100);  
   
//----
   
//----
   return(0);
  }
   //DrawTFLabel(5,"Label_M5",150,40);

// Routine per disegnare le label degli stoch
  // DrawStochLabel(5,"Label_Stoch5",110,20);
void DrawStochLabel(int TipoStoch, string Label, int PosX, int PosY)
{
    // Stoch5 Label
   ObjectCreate(Label, OBJ_LABEL, 0, 0, 0);
   ObjectSet(Label, OBJPROP_CORNER, 1);
   ObjectSet(Label, OBJPROP_XDISTANCE, PosX);
   ObjectSet(Label, OBJPROP_YDISTANCE, PosY);  
   if (TipoStoch == 5)  ObjectSetText(Label, "Stoch5", 8, "Comic Sans MS", Black);
   if (TipoStoch == 20) ObjectSetText(Label, "Stoch20", 8, "Comic Sans MS", Black);   
   if (TipoStoch == 50) ObjectSetText(Label, "Stoch50", 8, "Comic Sans MS", Black);      
}
      
// Routine per disegnare le label dei timframe
void DrawTFLabel(int TF, string Label, int PosX, int PosY)
{
   // M5 Label
   ObjectCreate(Label, OBJ_LABEL, 0, 0, 0);
   ObjectSet(Label, OBJPROP_CORNER, 1);
   ObjectSet(Label, OBJPROP_XDISTANCE, PosX);
   ObjectSet(Label, OBJPROP_YDISTANCE, PosY);
   if (TF == 5)  ObjectSetText(Label, "M5", 8, "Comic Sans MS", Black);
   if (TF == 15) ObjectSetText(Label, "M15", 8, "Comic Sans MS", Black);
   if (TF == 30) ObjectSetText(Label, "M30", 8, "Comic Sans MS", Black);   
   if (TF == 60) ObjectSetText(Label, "H1", 8, "Comic Sans MS", Black);   
}

// Routine per disegnare la freccia
void DrawArrow(int TF, int TipoStoch, string NameArrow, int PosX, int PosY)
{ string Temp;
    // Arrow Stoch5_TF5 
   if ( StochMain(TF,TipoStoch) > StochSignal(TF,TipoStoch) ) 
   { 
    Temp="Ù";
    Color = Green;
   }
   else 
   {
    Temp="Ú";
    Color = Red;
   } 
   
   ObjectDelete(NameArrow);
   ObjectCreate(NameArrow, OBJ_LABEL, 0, 0, 0);
   ObjectSetText(NameArrow,Temp,10, "Wingdings", Color);
   ObjectSet(NameArrow, OBJPROP_CORNER, 1);
   ObjectSet(NameArrow, OBJPROP_XDISTANCE,PosX);
   ObjectSet(NameArrow, OBJPROP_YDISTANCE,PosY);

}
 
// Rileva valore Main Stocastico
double StochMain(int TF,int TipoStoch)
{ double valore;
  if (TipoStoch == 5)  valore = iStochastic(NULL,TF,TipoStoch,3,3,MODE_SMA,0,MODE_MAIN,0);
  if (TipoStoch == 20) valore = iStochastic(NULL,TF,TipoStoch,10,20,MODE_SMA,0,MODE_MAIN,0); 
  if (TipoStoch == 50) valore = iStochastic(NULL,TF,TipoStoch,10,20,MODE_SMA,0,MODE_MAIN,0);   
  return(valore);
}  

// Rileva valore Signal Stocastico
double StochSignal(int TF,int TipoStoch)
{ double valore;
  if (TipoStoch == 5)  valore = iStochastic(NULL,TF,TipoStoch,3,3,MODE_SMA,0,MODE_SIGNAL,0);
  if (TipoStoch == 20) valore = iStochastic(NULL,TF,TipoStoch,10,20,MODE_SMA,0,MODE_SIGNAL,0); 
  if (TipoStoch == 50) valore = iStochastic(NULL,TF,TipoStoch,10,20,MODE_SMA,0,MODE_SIGNAL,0);   
  return(valore);  
}  

//+------------------------------------------------------------------+

