//+------------------------------------------------------------------+
//|                                                         TEST.mq4 |
//|                        Copyright 2012, MetaQuotes Software Corp. |
//|                                              http://www.mql5.com |
//+------------------------------------------------------------------+
#property indicator_chart_window

#define TIMEFRAMESSHOW 3
#define TIMEFRAMES 6
#define SYMBOLS 2
#define SYMBOLSMIX 7

input uchar timeframe = 0;
input int window = 1;
input int periodL = 5;
input int periodH = 12;

int timeframes[] = { PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_H1, PERIOD_H4, PERIOD_D1 };
string timeframesS[] = { "M1", "M5", "M15", "H1", "H4", "D1" };
char strengths[ SYMBOLS ][ TIMEFRAMES ];

string symbolsNames[ SYMBOLS ] = { "USD", "GBP" };

string symbols[][ SYMBOLSMIX ] = { { "AUDUSD", "EURUSD", "GBPUSD", "NZDUSD", "USDCAD", "USDCHF", "USDJPY" },
								   { "EURGBP", "GBPAUD", "GBPCAD", "GBPCHF", "GBPNZD", "GBPJPY", "GBPUSD" } };
bool symbolsRev[][ SYMBOLSMIX ] = { { true, true, true, true, false, false, false },
									{ true, false, false, false, false, false, false } };

int OnInit()
  {
int i;
int i2;
string name;
int x = 10;
int items;
int base;
items = ( timeframe == 0 ) ? TIMEFRAMES : TIMEFRAMESSHOW;
base = ( timeframe == 2 ) ? 3 : 0;

for( i = 0; i < items; i++ ) {
	ObjectCreate(0,name = "total" + i,OBJ_LABEL,window,0,0);
	ObjectSet(name,OBJPROP_CORNER,3);
	ObjectSet(name,OBJPROP_XDISTANCE,107);
	ObjectSet(name,OBJPROP_YDISTANCE,10 + ( 20 * i ));
}

for( i2 = 0; i2 < SYMBOLS; i2++ ) {
for( i = 0; i < items; i++ ) {
	ObjectCreate(0,name = symbolsNames[ i2 ] + i,OBJ_LABEL,window,0,0);
	ObjectSet(name,OBJPROP_CORNER,3);
	ObjectSet(name,OBJPROP_XDISTANCE,x);
	ObjectSet(name,OBJPROP_YDISTANCE,10 + ( 20 * i ));

}
x +=140;
}
//---
   return(INIT_SUCCEEDED);
  }

void OnDeinit( int const out ) {
int i;
int i2;
int items;
int base;
items = ( timeframe == 0 ) ? TIMEFRAMES : TIMEFRAMESSHOW;
base = ( timeframe == 2 ) ? 3 : 0;

for( i = 0; i < items; i++ )
	ObjectDelete(0,"total" + i);

for( i2 = 0; i2 < SYMBOLS; i2++ ) {
for( i = 0; i < items; i++ )
	ObjectDelete(0,symbolsNames[ i2 ] + i);
}
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
int i;
int i2;
int total;
string name;
//---
run();
int items;
int base;
items = ( timeframe == 0 ) ? TIMEFRAMES : TIMEFRAMESSHOW;
base = ( timeframe == 2 ) ? 3 : 0;

for( i = 0; i < items; i++ ) {
name = "total" + i;
		ObjectSetText(name, total = strengths[ 1 ][ i ] - strengths[ 0 ][ i ] );
		if ( MathAbs( total ) >= 5 )
			ObjectSet(name, OBJPROP_COLOR, clrRoyalBlue );
		else
			ObjectSet(name, OBJPROP_COLOR, clrGray );
}

for( i2 = 0; i2 < SYMBOLS; i2++ ) {
	for( i = 0; i < items; i++ )
		ObjectSetText(symbolsNames[ i2 ] + i, symbolsNames[ i2 ] + " " + timeframesS[ base + i ] + ": " + strengths[ i2 ][ i ] );
}
//--- return value of prev_calculated for next call
   return(rates_total);
  }


		void run() {

			uint		i;
			uint		i2;
			uint		i3;

			double		ma5[ 2 ];
			double		ma12[ 2 ];

			double		trend[ 2 ];
int items;
int base;
items = ( timeframe == 0 ) ? TIMEFRAMES : TIMEFRAMESSHOW;
base = ( timeframe == 2 ) ? 3 : 0;

		  //-- @CODE@ --

			ArrayFill( strengths, 0, TIMEFRAMES * 2, 0 );

			for( i = 0; i < items; i++ ) {

				for( i3 = 0; i3 < SYMBOLS; i3++ ) {

					for( i2 = 0; i2 < SYMBOLSMIX; i2++ ) {

						ma5[ 0 ] = iCustom( symbols[ i3 ][ i2 ], timeframes[ base + i ], "NonLag ma nrp 2 nmc (1)", periodL, 0, 0, 0, 0, 0 );
						ma5[ 1 ] = iCustom( symbols[ i3 ][ i2 ], timeframes[ base + i ], "NonLag ma nrp 2 nmc (1)", periodL, 0, 0, 0, 0, 1 );

/*
						ma5[ 0 ] = iMA( symbols[ i3 ][ i2 ], timeframes[ base + i ], periodL, 0, MODE_SMA, PRICE_CLOSE, 0 );
						ma5[ 1 ] = iMA( symbols[ i3 ][ i2 ], timeframes[ base + i ], periodL, 0, MODE_SMA, PRICE_CLOSE, 1 );
*/
						trend[ 0 ] = ma5[ 0 ] - ma5[ 1 ];

						ma12[ 0 ] = iCustom( symbols[ i3 ][ i2 ], timeframes[ base + i ], "NonLag ma nrp 2 nmc (1)", periodH, 0, 0, 0, 0, 0 );
						ma12[ 1 ] = iCustom( symbols[ i3 ][ i2 ], timeframes[ base + i ], "NonLag ma nrp 2 nmc (1)", periodH, 0, 0, 0, 0, 1 );

/*
						ma12[ 0 ] = iMA( symbols[ i3 ][ i2 ], timeframes[ base + i ], periodH, 0, MODE_SMA, PRICE_CLOSE, 0 );
						ma12[ 1 ] = iMA( symbols[ i3 ][ i2 ], timeframes[ base + i ], periodH, 0, MODE_SMA, PRICE_CLOSE, 1 );
*/
						trend[ 1 ] = ma12[ 0 ] - ma12[ 1 ];

						if ( trend[ 0 ] > 0 && trend[ 1 ] > 0 )
							( symbolsRev[ i3 ][ i2 ] ) ? strengths[ i3 ][ i ]-- : strengths[ i3 ][ i ]++;
						else if ( trend[ 0 ] < 0 && trend[ 1 ] < 0 )
							( symbolsRev[ i3 ][ i2 ] ) ? strengths[ i3 ][ i ]++ : strengths[ i3 ][ i ]--;

					}

				}

			}

		};
