//+------------------------------------------------------------------+
//|                                                      Quantum.mq4 |
//+------------------------------------------------------------------+
//2012Jan27 mod for mer071898

#property copyright "Copyright © 2010, zznbrm"
                          
//---- indicator settings
#property indicator_chart_window
#property  indicator_buffers 2 
#property  indicator_color1 Blue
#property  indicator_color2 Red
#property  indicator_width1 5
#property  indicator_width2 5

//---- input parameters
extern int    eintDepth3         = 300;
extern int    symbolCod          = 250;        // Код символа в диапазоне 33 - 255

extern ENUM_LINE_STYLE LineStyle = 0;          // Стиль линий
extern color  ColorHigh          = clrYellow;  // Цвет линии Hihg
extern color  ColorLow           = clrYellow;  // Цвет линии Low

//---- indicator buffers
double gadblUp3[];
double gadblDn3[];
double Bars_High,Bars_Low;
datetime t1=0,t2=0;  
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
   SetIndexBuffer( 0, gadblUp3 );
   SetIndexEmptyValue( 0, 0.0 );
   SetIndexStyle( 0, DRAW_ARROW );
   SetIndexArrow( 0, symbolCod ); 
   SetIndexLabel( 0, NULL );
   
   SetIndexBuffer( 1, gadblDn3 );
   SetIndexEmptyValue( 1, 0.0 );
   SetIndexStyle( 1, DRAW_ARROW );
   SetIndexArrow( 1, symbolCod ); 
   SetIndexLabel( 1, NULL ); 
    
   IndicatorDigits( 5 );
     
   //---- name for DataWindow and indicator subwindow label
   IndicatorShortName( "Quantum(" + eintDepth3 + ")" );
   
   return( 0 );
}

//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
   return( 0 );
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   int counted_bars = IndicatorCounted();
   
   if (counted_bars < 0) return (-1);
   if (counted_bars > 0) counted_bars--;
   int intLimit = Bars - counted_bars;
   int intLow3, intHigh3;

   
   
   
   for( int inx = intLimit; inx >= 0; inx-- )
   {          
   // блок тайминга от индикации канала
   t1 = iTime(Symbol(),0,eintDepth3);
   t2 = iTime(Symbol(),0,0); 
   
      gadblUp3[inx] = 0.0;
      gadblDn3[inx] = 0.0;
      
      
      intHigh3 = iHighest( Symbol(), Period(), MODE_HIGH, eintDepth3, inx );
      intLow3 = iLowest( Symbol(), Period(), MODE_LOW, eintDepth3, inx );
      
  //--------  Находим  хай - лоу за выставленный диапазон баров   ---------------------------------------------------+ 
  Bars_High    = NormalizeDouble(iHigh(Symbol(),PERIOD_CURRENT,iHighest(Symbol(),PERIOD_CURRENT,MODE_HIGH,eintDepth3,0)),_Digits);
  Bars_Low     = NormalizeDouble(iLow (Symbol(),PERIOD_CURRENT,iLowest(Symbol(),PERIOD_CURRENT,MODE_LOW,eintDepth3,0)),_Digits); 
   
  DrawLine("High",Bars_High,t1,Bars_High,t2,LineStyle,ColorHigh);
  DrawLine("Low",Bars_Low,t1,Bars_Low,t2,LineStyle,ColorLow);
    
      if ( intLow3 == inx )
      {
       gadblUp3[inx] = Low[inx];
        
      }

     
      if ( intHigh3 == inx )
      {
      gadblDn3[inx] = High[inx];
        
      }
      
     
      
      
   }
   
   
      
   return( 0 );
}

//+------------------------------------------------------------------+
//|     Функция создания линий                                       |
//+------------------------------------------------------------------+
void DrawLine(string name, double price1,datetime time1,double price2, datetime time2, int stil, color LineColor) {
   if(ObjectFind(name)<0)//ObjectDelete(name); 
   ObjectCreate(name,OBJ_TREND,0,0,0,0,0);
   ObjectSet(name,OBJPROP_STYLE,stil);
   ObjectSet(name,OBJPROP_COLOR,LineColor);
   ObjectSet(name, OBJPROP_TIME1,time1);
   ObjectSet(name, OBJPROP_PRICE1, price1);
   ObjectSet(name, OBJPROP_TIME2,  time2);
   ObjectSet(name, OBJPROP_PRICE2, price2);
   ObjectSet(name, OBJPROP_BACK,false);
   ObjectSet(name,OBJPROP_RAY,false); 
}