#property copyright "Copyright © 2010, sangmane"
#property link      "sangmane@forexfactory.com"

#property show_inputs

extern double Spread = 1.5;

int start()
{
	double pip = Point;
	if(Digits==3 || Digits==5) pip = 10*Point;
	int fh = FileOpenHistory("symbols.sel",FILE_BIN|FILE_READ);
	if(fh<0) return;
	int fs = FileOpen("symbols.sel",FILE_BIN|FILE_WRITE);
	if(fs<0) {
		FileClose(fh);
		return;
	}
	int arraySize = FileSize(fh)/4;
	int ablock[];
	ArrayResize(ablock,arraySize);
	FileReadArray(fh,ablock,0,arraySize);
	FileWriteArray(fs,ablock,0,arraySize);
	FileClose(fs);
	FileClose(fh);
	fs = FileOpen("symbols.sel",FILE_BIN|FILE_READ|FILE_WRITE);
	string temp, symbol;		
	double bid, ask;
	FileSeek(fs,4,SEEK_SET);
	while(!IsStopped()) {
		temp = FileReadString(fs,12);
		if(FileIsEnding(fs)) break;
		symbol = StringSubstr(temp,0,StringFind(temp,"\x00",0));
		if(symbol==Symbol()){
			Print("Symbol Found");
			int pos = FileTell(fh)-12;
			FileSeek(fs,pos+0x40,SEEK_SET);
			bid = FileReadDouble(fs,DOUBLE_VALUE);
			ask = NormalizeDouble(bid+Spread*pip,Digits);
			FileSeek(fs,pos+0x40+DOUBLE_VALUE,SEEK_SET);
			FileWriteDouble(fs,ask,DOUBLE_VALUE);
			FileSeek(fs,pos+0x70+DOUBLE_VALUE,SEEK_SET);
			FileWriteDouble(fs,ask,DOUBLE_VALUE);			
			break;
		}
		FileSeek(fs,0x80-12,SEEK_CUR);
	}
	FileClose(fs);
	return(0);
}
//+------------------------------------------------------------------+

