//+------------------------------------------------------------------+
//|                                              MultiInstrument.mq4 |
//|                               Copyright © 2010, Vladimir Hlystov |
//|                                         http://cmillion.narod.ru |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, Vladimir Hlystov"
#property link      "http://cmillion.narod.ru"

#property indicator_chart_window
#property indicator_buffers 4

#property indicator_color1 Red
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Blue

double Line1[], Line2[], Line3[], Line4[];

extern string simbol="USDCHF";//"SILVER";
//выводит другой инструмент в текущее окно
//+------------------------------------------------------------------+
int init()
  {
   SetIndexStyle(0,DRAW_HISTOGRAM,0,3);
   SetIndexBuffer(0,Line1);
     
   SetIndexStyle(1,DRAW_HISTOGRAM,0,3);
   SetIndexBuffer(1,Line2);  
   
   SetIndexStyle(2,DRAW_HISTOGRAM,0,1);
   SetIndexBuffer(2,Line3);
   
   SetIndexStyle(3,DRAW_HISTOGRAM,0,1);
   SetIndexBuffer(3,Line4);
   return(0);
  }
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectsDeleteAll(0,OBJ_TREND);
   return(0);
  }
//+------------------------------------------------------------------+
int start()
  {
   int BarsWind=WindowFirstVisibleBar();
   int Bar = iHighest(NULL,0,MODE_HIGH,BarsWind,0);
   double High_Win = High[Bar];
   Bar = iLowest(NULL,0,MODE_LOW,BarsWind,0);
   double Low_Win  = Low[Bar];
   Bar = iHighest(simbol,0,MODE_HIGH,BarsWind,0);
   double H=iHigh(simbol,0,Bar);
   Bar = iLowest(simbol,0,MODE_LOW,BarsWind,0);
   double L=iLow(simbol,0,Bar);
   double OpenBar,CloseBar,LowBar,HighBar;
   string nameCandle;
   int Digit = MarketInfo(simbol,MODE_DIGITS);
   for(int i=BarsWind; i>=0; i--)
   {
      OpenBar = iOpen (simbol,0,i);
      CloseBar= iClose(simbol,0,i);
      LowBar  = iLow  (simbol,0,i);
      HighBar = iHigh (simbol,0,i);
      nameCandle=StringConcatenate(simbol," ",TimeToStr(Time[i],TIME_DATE|TIME_MINUTES));
      OpenBar =(OpenBar -L)/(H-L)*(High_Win-Low_Win)+Low_Win;
      CloseBar=(CloseBar-L)/(H-L)*(High_Win-Low_Win)+Low_Win;
      LowBar  =(LowBar  -L)/(H-L)*(High_Win-Low_Win)+Low_Win;
      HighBar =(HighBar -L)/(H-L)*(High_Win-Low_Win)+Low_Win;
      
      if (OpenBar>CloseBar) 
      {
         Line1[i]=OpenBar; 
         Line2[i]=CloseBar;
         Line3[i]=HighBar; 
         Line4[i]=LowBar; 
      }
      else 
      {
         Line1[i]=OpenBar; 
         Line2[i]=CloseBar;
         Line3[i]=LowBar;  
         Line4[i]=HighBar; 
      }
   }
   return(0);
  }
//+------------------------------------------------------------------+