//+------------------------------------------------------------------+
//|                                                      Stoch-3.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_separate_window
#property indicator_buffers 3
#property indicator_color1 Red
#property indicator_color2 Yellow
#property indicator_color3 Lime
#property indicator_level1 85.0
#property indicator_level2 15.0
#property indicator_level3 70.0
#property indicator_level4 30.0
#property indicator_minimum 0
#property indicator_maximum 100
extern string Первый_Stochastic="Период в минутах и параметры";
extern int Period.1=30,
           Stoch_K1=5,
           Stoch_D1=3,
           Stoch_S1=3;
extern string Второй_Stochastic="Период в минутах и параметры";           
extern int Period.2=60,
           Stoch_K2=5,
           Stoch_D2=3,
           Stoch_S2=3;
extern string Третий_Stochastic="Период в минутах и параметры";           
extern int Period.3=240,
           Stoch_K3=5,
           Stoch_D3=3,
           Stoch_S3=3;
           
//--- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexLabel(0,"Период "+Period.1+"\n");
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexLabel(1,"Период "+Period.2+"\n");
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ExtMapBuffer3);
   SetIndexLabel(2,"Период "+Period.3+"\n");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int limit,shift1,shift2,shift3;
   int counted_bars=IndicatorCounted();
//----
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   for(int i=limit;i>=0;i--){
      shift1 = HighBar(Symbol(), 0, i, Period.1);
      shift2 = HighBar(Symbol(), 0, i, Period.2);
      shift3 = HighBar(Symbol(), 0, i, Period.3);
      ExtMapBuffer1[i] = iStochastic(NULL,Period.1,Stoch_K1,Stoch_D1,Stoch_S1,MODE_SMA,0,MODE_MAIN,shift1);
      ExtMapBuffer2[i] = iStochastic(NULL,Period.2,Stoch_K2,Stoch_D2,Stoch_S2,MODE_SMA,0,MODE_MAIN,shift2);
      ExtMapBuffer3[i] = iStochastic(NULL,Period.3,Stoch_K3,Stoch_D3,Stoch_S3,MODE_SMA,0,MODE_MAIN,shift3);
      }
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
int HighBar(string symbol,int TFLow,int BarLow,int TFHigh){
   datetime BarTimeLow = iTime(symbol, TFLow, BarLow);    
   int res = iBarShift(symbol, TFHigh, BarTimeLow, false);
   return (res);
 }
//+------------------------------------------------------------------+