//+------------------------------------------------------------------+
//|                                               Sentinal Index.mq4 |
//+------------------------------------------------------------------+
#property indicator_separate_window 
//#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Aqua

extern int bars_to_calculate = 250;
extern bool flip_line_up_side_down = false;
extern double	EUR = 1.0,	// weights
					JPY = 1.0,
					GBP = 1.0,
					CHF = 1.0,
					CAD = 1.0,
					AUD = 1.0,
					NZD = 1.0;
					
double BIAS = 0;	// starting value for the first bar
//---- indicator buffers
double	Index[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
	string name = "";

//---- indicator line
	IndicatorShortName(name);
   IndicatorBuffers(1);
   SetIndexStyle(0,DRAW_LINE,EMPTY,EMPTY);
   SetIndexBuffer(0,Index);
   SetIndexLabel(0,NULL);
//----
   return(0);
}

//+------------------------------------------------------------------+
//| Calculates the relative change of symbol between bar i and i+1	|
//+------------------------------------------------------------------+
double Sentinal(string symbol, int i = 0)
{
double    a = iMA(symbol,0,1,0,0,4,i),
          b = iMA(symbol,0,1,0,0,4,(i+1)),
			 move = a-b;

	if(a==0||b==0)
	{
		if(i==0)
			Print("Warning: No "+symbol+" data loaded.");
		return(0);
	}

	double moveInPercent = 100*move/b;
/*	double pointSize = MarketInfo(symbol,MODE_POINT),
			 tickValue = MarketInfo(symbol,MODE_TICKVALUE);
	double moveInPips = move / pointSize,
	  		 moveInUSD  = moveInPips * tickValue;

	switch(MODE)
	{
		case 0: return(moveInPercent);
		case 1: return(moveInPips);
		case 2: return(moveInUSD);
	}
*/

	return(moveInPercent);
}

//+------------------------------------------------------------------+
int start()
{
//	int iMax = Bars - 1 - IndicatorCounted();
   int iMax = Bars -1 ;

	if(iMax >= bars_to_calculate)
	{
		iMax = bars_to_calculate;
   }
   
   Index[iMax+1] = BIAS;

//----
   for(int i = iMax; i >= 0; i--)
	{
		double x = 0;

		x -= EUR * Sentinal("EURUSD",i);
		x +=   JPY * Sentinal("USDJPY",i);
		x -= GBP * Sentinal("GBPUSD",i);
		x +=   CHF * Sentinal("USDCHF",i);
		x +=   CAD * Sentinal("USDCAD",i);
		x -= AUD * Sentinal("AUDUSD",i);
		x -= NZD * Sentinal("NZDUSD",i);

if (flip_line_up_side_down)
      x *= -1;
      	
		Index[i] = Index[i+1]+x;
	}

	return(0);
}



