//+------------------------------------------------------------------+
//|                                               SpreadCharts 2.mq4 |
//|                             Copyright © 2009, Skype: en.ua.en.ua |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2009, Skype: en.ua.en.ua"
#property link      ""

#property indicator_separate_window
#property indicator_buffers 2

extern int Timeframe = 1;
extern string Symbol_1 = "AUDUSD";
extern string Symbol_2 = "EURCHF";

double SpreadAsk[];
double SpreadBid[];

int init()
{
   SetIndexBuffer(0,SpreadAsk);
   SetIndexBuffer(1,SpreadBid);
   SetIndexStyle(0,DRAW_SECTION,EMPTY,2,Red);
   SetIndexStyle(1,DRAW_SECTION,EMPTY,2,Blue);
   return(0);
}

int start()
{
   int k;
   double N = 0;
   double Sum = 0;
   for(k = 0; k < iBars(Symbol_1,Timeframe); k++)
   {
      int symb2Shift = iBarShift(Symbol_2,Timeframe,iTime(Symbol_1,Timeframe,k),true);
      if(symb2Shift != -1)
      {   
         double askSymb1 = iOpen(Symbol_1,Timeframe,k) + MarketInfo(Symbol_1,MODE_SPREAD)*MarketInfo(Symbol_1,MODE_POINT);
         double bidSymb1 = iOpen(Symbol_1,Timeframe,k);
         
         double askSymb2 = iOpen(Symbol_2,Timeframe,symb2Shift) + MarketInfo(Symbol_2,MODE_SPREAD)*MarketInfo(Symbol_2,MODE_POINT);
         double bidSymb2 = iOpen(Symbol_2,Timeframe,symb2Shift);
         
         if(bidSymb1!=0&&bidSymb2!=0)
         {
            SpreadAsk[k] = askSymb1 - bidSymb2;
            SpreadBid[k] = bidSymb1 - askSymb2;                  
         }
      }
      else
      {
         //SpreadAsk[k] = 0;
         //SpreadBid[k] = 0;
      }

   }
   string comment = "Spread ASK: " + GetCurrentSpread("ask") + " BID: " + GetCurrentSpread("bid");
   Comment(comment);
   return(0);
}
double GetCurrentSpread(string param)
{
   if(param == "ask")
   {
      return(MarketInfo(Symbol_1,MODE_ASK) - MarketInfo(Symbol_2,MODE_BID));
   }
   else
   {
      return(MarketInfo(Symbol_1,MODE_BID) - MarketInfo(Symbol_2,MODE_ASK));
   }
}