Sentinal Index SMA IBFX

Sentinal Index SMA IBFX
Price Data Components
Series array that contains close prices for each bar
Indicators Used
Moving average indicator
Miscellaneous
Implements a curve of type %1
0 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

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---