Sentinal Index SMA IBFX

Download script
Sentinal Index SMA IBFX

The Sentinal Index is a custom analytical tool designed to provide a high-level overview of market dynamics by aggregating the movements of several major currency pairs into a single, unified visual index. Rather than looking at individual assets in isolation, this script calculates a "weighted sentiment" or "net movement" to help traders understand broader trends across the USD-related markets.

How the Logic Works

1. Multi-Currency Tracking The tool monitors seven specific currency pairs simultaneously: EURUSD, USDJPY, GBPUSD, USDCHF, USDCAD, AUDUSD, and NZDUSD. It looks at the price change between each consecutive candle to determine how much each currency moved during that period.

2. Dynamic Calculation Modes Depending on your preference, the script can measure these movements in three different ways:

  • Percentage: The relative change as a percentage.
  • Pips: The standard unit of measurement for forex movement.
  • USD per Lot: The actual monetary value of the movement based on the tick value.

3. Weighted Balancing (The "Sentinal" Calculation) This is the core engine of the script. It doesn't just add all movements together; it treats currencies differently to find a balanced net position:

  • It treats certain pairs as positive values and others as negative values (for example, when USD is the base currency versus when it is the quote currency).
  • By assigning these weights, the script effectively "normalizes" the data. It calculates an average change across all these assets, allowing you to see if the market is leaning in a specific direction overall, rather than being driven by just one single volatile pair.

4. Cumulative Indexing Instead of showing you a jagged line of raw averages, the script adds each new calculation to the previous value. This creates a cumulative "Index" line. This allows traders to see the long-term accumulation or depletion of momentum over time.

5. Smoothing for Clarity (SMA) Because market data can be noisy and volatile, the script includes a Simple Moving Average (SMA) overlay. By applying this moving average over the calculated index (with a default period of 336), it smooths out minor "市場雜訊" (market noise) to reveal the clearer, underlying trend of the Sentinal Index.

Summary for the Trader

In simple terms, this tool acts as a "thermometer" for the market's collective movement regarding the US Dollar and its major partners. If the index line is trending upward, it suggests a broad bullish sentiment across the tracked currencies; if it is trending downward, it suggests a bearish sentiment. It helps you see the "big picture" by condensing multiple charts into one cohesive trend line.

Price Data Components
Series array that contains close prices for each bar
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
3 Views
0 Downloads
0 Favorites
Sentinal Index SMA IBFX
//+------------------------------------------------------------------+
//|                                                 Sentinal Index.mq4 
//|                               Based on Kevin_E @ forexfactory.com
//|                               Modified by IYA, Christoph Rohner
//|
//+------------------------------------------------------------------+

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 RoyalBlue
#property indicator_color2 Goldenrod


extern int		MODE = 0,	// 0=Percent, 1=Pips, 2=USD per Lot
               SMA_Period = 336;
extern double	BIAS = 0,	// starting value for the first bar
					EUR = 1.0,	// weights
					JPY = 1.0,
					GBP = 1.0,
					CHF = 1.0,
					CAD = 1.0,
					AUD = 1.0,
					NZD = 1.0;

//---- indicator buffers
double	Index[],
         SMA_Sentinal[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{
	string name = "Sentinal Index";

//---- indicator line
	IndicatorShortName(name);
   IndicatorBuffers(2);
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Index);
   SetIndexLabel(0,name);
   
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,SMA_Sentinal);

//----
   return(0);
}

//+------------------------------------------------------------------+
//| Calculates the relative change of symbol between bar i and i+1	|
//+------------------------------------------------------------------+
double Sentinal(string symbol, int i = 0)
{
	double a = iClose(symbol,0,i),
			 b = iClose(symbol,0,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(0);
}

//+------------------------------------------------------------------+
int start()
{
	int iMax = Bars - 1 - IndicatorCounted();
	if(iMax==Bars-1)
	{
		iMax--;
		Index[Bars-1] = BIAS;
	}

//----
   for(int i = iMax; i >= 0; i--)
	{
		double x = 0;

		x +=  EUR * Sentinal("EURUSDm",i);
		x += -JPY * Sentinal("USDJPYm",i);
		x +=  GBP * Sentinal("GBPUSDm",i);
		x += -CHF * Sentinal("USDCHFm",i);
		x += -CAD * Sentinal("USDCADm",i);
		x +=  AUD * Sentinal("AUDUSDm",i);
		x +=  NZD * Sentinal("NZDUSDm",i);
		x /= (EUR+JPY+GBP+CHF+CAD+AUD+NZD);	// FIXME: incorrect if a pair is not available

//		TODO: Calculate median instead of average?

//		Index[i] = x;
		Index[i] = Index[i+1]+x;
	}

//Add SMA of Sentinal Indicator	

   for(i = iMax; i >= 0; i--)
	{
    SMA_Sentinal[i] = iMAOnArray(Index,0,SMA_Period,0,MODE_SMA,i);
   }

//---
	return(0);
}

Comments