//+------------------------------------------------------------------+
//|                                               Spread History.mq4 |
//+------------------------------------------------------------------+
#property  copyright ""
//---- indicator settings
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1  Green
#property indicator_color2  Red

extern int Corner = 0;
extern int X = 10;
extern int Y = 20;
extern color Color = Blue;
extern int IndicatorPeriod = 5;

//---- indicator buffers
double    MinSpreadBuffer[];
double    MaxSpreadBuffer[];

string IndicatorName="SpreadIndicator";
string LabelName="SpreadHistory";

datetime OldTime, NewTime;
int max,min;

int init()
  {
  IndicatorShortName(IndicatorName);

	SetIndexBuffer(0,MinSpreadBuffer);
	SetIndexBuffer(1,MaxSpreadBuffer);
	SetIndexLabel(0,"MinSpread");
	SetIndexLabel(1,"MaxSpread");
	
	//SetIndexEmptyValue(0,0.0);
	IndicatorDigits(0);
	//SetIndexStyle(0,DRAW_NONE);	  
	
	MinSpreadBuffer[1]=0;
	MaxSpreadBuffer[1]=0;
	int Spread=MarketInfo(Symbol(),MODE_SPREAD);
	min=Spread;
	max=Spread;

  return(0);
  }
  
int start()
  {
  int windex=WindowFind(IndicatorName);
  if(windex<0) return;

	ObjectCreate(LabelName, OBJ_LABEL, windex, 0, 0);
  ObjectSet(LabelName, OBJPROP_CORNER, Corner);      
  ObjectSet(LabelName, OBJPROP_XDISTANCE, X ); 
  ObjectSet(LabelName, OBJPROP_YDISTANCE, Y);

	int Spread=MarketInfo(Symbol(),MODE_SPREAD);
  ObjectSetText(LabelName,"  ΡΟΠέΔ = "+DoubleToStr(Spread,0),8,"Arial",Color);
	
  NewTime=iTime(NULL,IndicatorPeriod,0);
  if(NewTime!=OldTime)
  	{
		min=Spread;
		max=Spread;

		OldTime=NewTime;
		}
  if(Spread<min) min=Spread;
  if(Spread>max) max=Spread;

	MinSpreadBuffer[0]=min;
	MaxSpreadBuffer[0]=max;

	
  return(0);
  }
int deinit()
	{
	ObjectDelete(LabelName);
	}






////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

/*
//+------------------------------------------------------------------+
int init()
  {
  IndicatorShortName(IndicatorName);

	SetIndexBuffer(0,MinSpreadBuffer);
	SetIndexBuffer(1,MaxSpreadBuffer);
	SetIndexLabel(0,"MinSpread");
	SetIndexLabel(1,"MaxSpread");


	return(0);
  }
//+------------------------------------------------------------------+
int start()
	{
	int Spread=MarketInfo(Symbol(),MODE_SPREAD);
	
  if(MinSpreadBuffer[1]==0) MinSpreadBuffer[1]=Spread;
  if(MaxSpreadBuffer[1]==0) MaxSpreadBuffer[1]=Spread;
  
  if(Spread<MinSpreadBuffer[1]) MinSpreadBuffer[1]=Spread;
  if(Spread>MaxSpreadBuffer[1]) MaxSpreadBuffer[1]=Spread;

  
  return(0);
  }
//+------------------------------------------------------------------+
int deinit()
	{
	int windex=WindowFind(IndicatorName);
  if(windex>0) ObjectsDeleteAll(IndicatorName);
	}
*/