//+------------------------------------------------------------------+
//|                                                PA_WHEAT-CORN.mq4 |
//|                                             Copyright © 2010, PA |
//|                                             http://www.blai5.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, PA"
#property link      "http://www.blai5.net"

#property indicator_separate_window
#property indicator_level1 130
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Lime
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];

string sW = "WHEAT";
string sC = "CORN";

int TimeFrame= 0;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexLabel(0, "W/C");
   SetIndexStyle(1, DRAW_LINE);
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexLabel(1, "W-C");
//----
   TimeFrame = MathMax(TimeFrame, Period());

   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 limit = Bars - counted_bars;

   for (int i = 0; i < limit; i++) {
      if (iClose(sC, TimeFrame, i) != 0.0)
         ExtMapBuffer1[i] = iClose(sW, TimeFrame, i) / iClose(sC, TimeFrame, i) * 100.0;
      else
         ExtMapBuffer1[i] = 0.0;
      ExtMapBuffer2[i] = iClose(sW, TimeFrame, i) - iClose(sC, TimeFrame, i);
   }
  
//----
   return(0);
  }
//+------------------------------------------------------------------+