//+--------------------------------------------------------------------+
//|                                              MTF_Stochastic1.1.mq4 |
//|                                     Copyright © 2006-07, Keris2112 |
//|                     Copyright © 2004-07, MetaQuotes Software Corp. |
//|                                         http://www.metaquotes.net/ |
//| You can turn the Alert on or off and it'll alert only once per bar |
//| added some dots where stoch crossed above 80 or 20                 |
//+--------------------------------------------------------------------+
#property copyright "Copyright © 2006-07, Keris2112"
#property link      "http://www.forex-tsd.com"

#property indicator_separate_window
#property indicator_buffers 5
#property indicator_color4 Lime
#property indicator_color5 Red
#property indicator_width4 2 
#property indicator_width5 2 
//---- input parameters
/*************************************************************************
_M1   1
_M5   5
_M15  15
_M30  30 
_H1   60
_H4   240
_D1   1440
_W1   10080
_MN1  43200
You must use the numeric value of the timeframe that you want to use
when you set the TimeFrame' value with the indicator inputs.
---------------------------------------
MODE_SMA    0 Simple moving average, 
MODE_EMA    1 Exponential moving average, 
MODE_SMMA   2 Smoothed moving average, 
MODE_LWMA   3 Linear weighted moving average. 
You must use the numeric value of the MA Method that you want to use
when you set the 'ma_method' value with the indicator inputs.

**************************************************************************/
extern string note1 = "Current timeframe = 0, M30 chart = 30";
extern string note2 = "H1 chart = 60, H4 chart = 240";
extern string note3 = "D1=1440, W1=10080, MN1=43200";
extern int TimeFrame=0;
extern string note4 = "Stochastic";
extern int K1=5;
extern int D1=3;
extern int Slowing1=3;
extern string note5 = "MAMethod: 0=SMA,1=EMA,2=SMMA,3=LWMA";
extern int MAMethod1=0;
extern string note6 = "PriceField: 0=Hi/Low, 1=Close/Close";
extern int PriceField1=0;

double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
double ExtMapBuffer4[];
double ExtMapBuffer5[];
//+-- Show regular timeframe string (HCY) ---------------------------+
string GetTimeFrameStr() {
   switch(TimeFrame)
   {
      case 1 : string TimeFrameStr2="M1"; break;
      case 5 : TimeFrameStr2="M5"; break;
      case 15 : TimeFrameStr2="M15"; break;
      case 30 : TimeFrameStr2="M30"; break;
      case 60 : TimeFrameStr2="H1"; break;
      case 240 : TimeFrameStr2="H4"; break;
      case 1440 : TimeFrameStr2="D1"; break;
      case 10080 : TimeFrameStr2="W1"; break;
      case 43200 : TimeFrameStr2="MN1"; break;
   } 
   return (TimeFrameStr2);
} //string GetTimeFrameStr()
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator line
   IndicatorBuffers(5);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(0,DRAW_NONE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(1,DRAW_NONE);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexStyle(2,DRAW_NONE);
   SetIndexBuffer(3,ExtMapBuffer4);
   SetIndexStyle(3,DRAW_HISTOGRAM);
   SetIndexBuffer(4,ExtMapBuffer5);
   SetIndexStyle(4,DRAW_HISTOGRAM);
  
   SetIndexLabel(2,"");
   SetIndexLabel(3,"");
   SetIndexLabel(4,"");
   // Show regular timeframe string (HCY)
   if (TimeFrame == 0) {
      TimeFrame = Period();
      }
  IndicatorDigits(2);
   
//---- name for DataWindow and indicator subwindow label   
   IndicatorShortName(Symbol()+","+GetTimeFrameStr()+": Stoch("+K1+","+D1+","+Slowing1+")");  
  }
//----
   return(0);

//+------------------------------------------------------------------+
//| MTF Stochastic                                                   |
//+------------------------------------------------------------------+
int start()
  {
   datetime TimeArray[];
   int    i,shift,limit,y=0,counted_bars=IndicatorCounted();
    
// Plot defined timeframe on to current timeframe   
   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimeFrame); 
   
   limit=Bars-counted_bars;
   for(i=0,y=0;i<limit;i++)
   {
   if (Time[i]<TimeArray[y]) y++; 
   
 /***********************************************************   
   Add your main indicator loop below.  You can reference an existing
      indicator with its iName  or iCustom.
   Rule 1:  Add extern inputs above for all neccesary values   
   Rule 2:  Use 'TimeFrame' for the indicator timeframe
   Rule 3:  Use 'y' for the indicator's shift value
 **********************************************************/  
     
   ExtMapBuffer1[i]=iStochastic(NULL,TimeFrame,K1,D1,Slowing1,MAMethod1,PriceField1,0,y);
   ExtMapBuffer2[i]=iStochastic(NULL,TimeFrame,K1,D1,Slowing1,MAMethod1,PriceField1,1,y);
   
   ExtMapBuffer3[i]=(ExtMapBuffer1[i]-ExtMapBuffer2[i])/Point;
  
   if(ExtMapBuffer3[i]>0){ExtMapBuffer4[i]=ExtMapBuffer3[i];ExtMapBuffer5[i]=EMPTY_VALUE;}
   if(ExtMapBuffer3[i]<0){ExtMapBuffer5[i]=ExtMapBuffer3[i];ExtMapBuffer4[i]=EMPTY_VALUE;}
   
   }
   return(0);
  }
//+------------------------------------------------------------------+