//+------------------------------------------------------------------+
//|                                           Dreamliner Scanner.mq4 |
//+------------------------------------------------------------------+
//version 2009.02.17
#property indicator_chart_window

extern	string	IndicatorName	= "Dreamliner Scanner";
extern	string	Currencies	= "AUD,CAD,CHF,EUR,GBP,JPY,NZD,USD";
extern	string	TimeFrame	= "D1";

extern	int	EMASlow		= 8;
extern	int	EMAFast		= 5;
int	_TimeFrame;
string	Currency[50];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init() {
	Comment("");
	if (TimeFrame == "M1")	{ _TimeFrame = PERIOD_M1;  }
	if (TimeFrame == "M5")	{ _TimeFrame = PERIOD_M5;  }
	if (TimeFrame == "M15")	{ _TimeFrame = PERIOD_M15; }
	if (TimeFrame == "M30")	{ _TimeFrame = PERIOD_M30; }
	if (TimeFrame == "H1")	{ _TimeFrame = PERIOD_H1;  }
	if (TimeFrame == "H4")	{ _TimeFrame = PERIOD_H4;  }
	if (TimeFrame == "D1")	{ _TimeFrame = PERIOD_D1;  }

	for (int i=0; StringLen(Currencies) >= 3; i++) {
		Currency[i] = StringSubstr(Currencies,0,3);
		Currencies  = StringSubstr(Currencies,4);
	}
	return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit() {
	return(0);
}
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {
	string	CX = StringSubstr(Symbol(),6);
	string	text = "";
	if (IsNewBar() == false) return(0);

	for (int x=0; StringLen(Currency[x])>0; x++) {
		for (int y=x+1; StringLen(Currency[y])>0; y++) {
			string _Symbol = Currency[x] + Currency[y] + CX;
			if (MarketInfo(_Symbol,MODE_BID) > 0) {	//This is valid pair
				double EMASlow1 = iMA(_Symbol, _TimeFrame, EMASlow, 0, MODE_EMA, PRICE_CLOSE, 1);
				double EMASlow2 = iMA(_Symbol, _TimeFrame, EMASlow, 0, MODE_EMA, PRICE_CLOSE, 2);
				double EMAFast1 = iMA(_Symbol, _TimeFrame, EMAFast, 0, MODE_EMA, PRICE_CLOSE, 1);
				double EMAFast2 = iMA(_Symbol, _TimeFrame, EMAFast, 0, MODE_EMA, PRICE_CLOSE, 2);
				if (EMAFast2 > EMASlow2 && EMAFast1 < EMASlow1) {
					text = text + _Symbol + " : Short\n";
				}
				if (EMAFast2 < EMASlow2 && EMAFast1 > EMASlow1) {
					text = text + _Symbol + " : Long\n";
				}
			}
		}
	}
	Comment("\n",IndicatorName,
		"\nTimeFrame: ",TimeFrame, " (",TimeToStr(TimeLocal(),TIME_DATE|TIME_SECONDS),")", 
		"\n\n",
		text);
	return(0);
}
//+------------------------------------------------------------------+
bool IsNewBar() {
	static int TimeLastBar;
	int time = iTime(Symbol(), _TimeFrame, 0);
	if (time != TimeLastBar) {
		TimeLastBar = time;
		return(true);
	} else {
		return(false);
	}
}

