//+------------------------------------------------------------------+
//|                                     MultipleCurrencies_1_SMA.mq4 |
//|                      Copyright © 2004, MetaQuotes Software Corp. |
//|                                       http://www.metaquotes.net/ |
//+------------------------------------------------------------------+
// Step 02 Add a mini fractal dot to the primary pair


#property copyright "Copyright © 2009, Mark Bass"

#property indicator_chart_window
#property indicator_buffers 6
#property indicator_color1 Yellow      // 1 SMA Typical for primary pair
#property indicator_color2 Lime        // Up mini fractals for primary pair
#property indicator_color3 Red         // Down mini fractal for primary pair
#property indicator_color4 Magenta
#property indicator_color5 Lime
#property indicator_color6 Red

//---- input parameters
extern double EURUSDbase = 1.32;
extern double USDCHFbase = 1.15;
extern double USDCHFtweak = 0.0000;
extern bool displayMA = false;
extern int MAmode = 0; // 0 = SMA, 1 = EMA, 2 = SMMA
extern int MAperiods = 1;
double EURUSD[], EURUSDupmf[], EURUSDdnmf[];
double USDCHF[], USDCHFupmf[], USDCHFdnmf[];
int pips = 10;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicator buffers mapping
   SetIndexBuffer(0,EURUSD);
   SetIndexStyle(0,DRAW_LINE);   
   SetIndexLabel(0,"EURUSD");
      
   SetIndexBuffer(1,EURUSDupmf);
   SetIndexStyle(1,DRAW_ARROW,STYLE_SOLID,1);
   SetIndexArrow(1,233);
   SetIndexLabel(1,"mini fractals");

   SetIndexBuffer(2,EURUSDdnmf);
   SetIndexStyle(2,DRAW_ARROW,STYLE_SOLID,1);
   SetIndexArrow(2,234);
   SetIndexLabel(2,"mini fractals");

   SetIndexBuffer(3,USDCHF);
   SetIndexStyle(3,DRAW_LINE);   
   SetIndexLabel(3,"USDCHF");
   
   SetIndexBuffer(4,USDCHFupmf);
   SetIndexStyle(4,DRAW_ARROW,STYLE_SOLID,1);
   SetIndexArrow(4,233);
   SetIndexLabel(4,"mini fractals");

   SetIndexBuffer(5,USDCHFdnmf);
   SetIndexStyle(5,DRAW_ARROW,STYLE_SOLID,1);
   SetIndexArrow(5,234);
   SetIndexLabel(5,"mini fractals");

   
//---- initialization done
   return(0);
  }
//+------------------------------------------------------------------+
//| Mark Bass' Pivots                                          |
//+------------------------------------------------------------------+
int start()
  {
   int limit;
   int counted_bars=IndicatorCounted();
   double EU, EU1, EU2;
   double UC, UC1, UC2;

  
//---- check for possible errors
   if(counted_bars<0) return(-1);
//---- last counted bar will be recounted
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
//---- main loop
   for(int i=0; i<limit; i++)
     {
      EU = iMA("EURUSD",0,MAperiods,0,MAmode,PRICE_TYPICAL,i);
      EU1 = iMA("EURUSD",0,MAperiods,0,MAmode,PRICE_TYPICAL,i+1);
      EU2 = iMA("EURUSD",0,MAperiods,0,MAmode,PRICE_TYPICAL,i+2);
      if (displayMA) EURUSD[i]= EU;

      UC = iMA("USDCHF",0,MAperiods,0,MAmode,PRICE_TYPICAL,i);
      UC1 = iMA("USDCHF",0,MAperiods,0,MAmode,PRICE_TYPICAL,i+1);
      UC2 = iMA("USDCHF",0,MAperiods,0,MAmode,PRICE_TYPICAL,i+2);
      USDCHF[i] = EURUSDbase + USDCHFbase - UC + USDCHFtweak;


      if (EU1 > EU && EU1 > EU2 && UC1 < UC && UC1 < UC2) {
         if (displayMA) EURUSDupmf[i+1] = EU1;
         USDCHFupmf[i+1] = EURUSDbase + USDCHFbase - UC1 + USDCHFtweak;
      }
      if (EU1 < EU && EU1 < EU2 && UC1 > UC && UC1 > UC2) {
         if (displayMA) EURUSDdnmf[i+1] = EU1;
         USDCHFdnmf[i+1] = EURUSDbase + USDCHFbase - UC1 + USDCHFtweak;
      }
      // USDCHF is inverted from EURUSD      
      //if (UC1 > UC && UC1 > UC2) USDCHFdnmf[i+1] = USDCHF[i]-10*pips*Point;
      //if (UC1 < UC && UC1 < UC2) USDCHFupmf[i+1] = USDCHF[i]+10*pips*Point;
      
     }
//---- done
   return(0);
  }
//+------------------------------------------------------------------+

