// catarena.mq4

#property indicator_chart_window
#property indicator_buffers 0

#property  copyright "Copyright © 2010, "
#property  link      ""

string tpl = "asdfasdfsdfsdasdfasdfasdfasdf";

int init()
{
	return(0);
}
int deinit()
{
	DeleteMyObjects();
}

int start()
{

   int counted_bars=IndicatorCounted();
   int limit, i, j;
   
    if (counted_bars<0) return(-1);

   	if (counted_bars==0) 
   	{
   		limit=Bars - 1;
   	}
   	
   	if (counted_bars>0) 
   	{
		limit=Bars-counted_bars; 
	}
	
	datetime DayStart;
	
	double m = 1;
	if(Digits == 5 || Digits == 3)
	{
		m = 10;
	}
	
   	for (i = limit-1; i >= 0; i--)
   	{
   		//int CurrHour = TimeHour(iTime(NULL, PERIOD_H1, i));
		
		DayStart = iTime(NULL, PERIOD_D1, iBarShift(NULL, PERIOD_D1, iTime(NULL, Period(), i)));

		double ClosePrice = iClose(NULL, PERIOD_D1, iBarShift(NULL, PERIOD_D1, iTime(NULL, Period(), i)) + 1);
		double Distance1 = 18*Point * m;
		double Distance2 = 18*Point * m + ND(ClosePrice * 0.0025);
		double Distance3 = 18*Point * m + ND(ClosePrice * 0.0050);
		double Distance4 = 18*Point * m + ND(ClosePrice * 0.0075);
		
		string name = tpl + "_" + DayStart + "_1";
		if(ObjectFind(name) == -1)
		{
	   		ObjectCreate(name, OBJ_TREND, 0, DayStart, ClosePrice + Distance1, DayStart + PERIOD_D1 * 60 - 1, ClosePrice + Distance1);
	   		ObjectSet(name, OBJPROP_COLOR, Blue);
   			ObjectSet(name, OBJPROP_RAY, false);
   		}
		name = tpl + "_" + DayStart + "_2";
		if(ObjectFind(name) == -1)
		{
	   		ObjectCreate(name, OBJ_TREND, 0, DayStart, ClosePrice - Distance1, DayStart + PERIOD_D1 * 60 - 1, ClosePrice - Distance1);
	   		ObjectSet(name, OBJPROP_COLOR, Red);
   			ObjectSet(name, OBJPROP_RAY, false);
   		}

		name = tpl + "_" + DayStart + "_3";
		if(ObjectFind(name) == -1)
		{
	   		ObjectCreate(name, OBJ_TREND, 0, DayStart, ClosePrice + Distance2, DayStart + PERIOD_D1 * 60 - 1, ClosePrice + Distance2);
	   		ObjectSet(name, OBJPROP_COLOR, Blue);
   			ObjectSet(name, OBJPROP_RAY, false);
   		}
   		
		name = tpl + "_" + DayStart + "_4";
		if(ObjectFind(name) == -1)
		{
	   		ObjectCreate(name, OBJ_TREND, 0, DayStart, ClosePrice - Distance2, DayStart + PERIOD_D1 * 60 - 1, ClosePrice - Distance2);
	   		ObjectSet(name, OBJPROP_COLOR, Red);
   			ObjectSet(name, OBJPROP_RAY, false);
   		}

		name = tpl + "_" + DayStart + "_5";
		if(ObjectFind(name) == -1)
		{
	   		ObjectCreate(name, OBJ_TREND, 0, DayStart, ClosePrice + Distance3, DayStart + PERIOD_D1 * 60 - 1, ClosePrice + Distance3);
	   		ObjectSet(name, OBJPROP_COLOR, Blue);
   			ObjectSet(name, OBJPROP_RAY, false);
   		}
   		
		name = tpl + "_" + DayStart + "_6";
		if(ObjectFind(name) == -1)
		{
	   		ObjectCreate(name, OBJ_TREND, 0, DayStart, ClosePrice - Distance3, DayStart + PERIOD_D1 * 60 - 1, ClosePrice - Distance3);
	   		ObjectSet(name, OBJPROP_COLOR, Red);
   			ObjectSet(name, OBJPROP_RAY, false);
   		}

		name = tpl + "_" + DayStart + "_7";
		if(ObjectFind(name) == -1)
		{
	   		ObjectCreate(name, OBJ_TREND, 0, DayStart, ClosePrice + Distance4, DayStart + PERIOD_D1 * 60 - 1, ClosePrice + Distance4);
	   		ObjectSet(name, OBJPROP_COLOR, Blue);
   			ObjectSet(name, OBJPROP_RAY, false);
   		}
   		
		name = tpl + "_" + DayStart + "_8";
		if(ObjectFind(name) == -1)
		{
	   		ObjectCreate(name, OBJ_TREND, 0, DayStart, ClosePrice - Distance4, DayStart + PERIOD_D1 * 60 - 1, ClosePrice - Distance4);
	   		ObjectSet(name, OBJPROP_COLOR, Red);
   			ObjectSet(name, OBJPROP_RAY, false);
   		}
   	}
   		
   	return(0);
}

double ND(double d)
{
	return (NormalizeDouble(d, Digits));
}

void DeleteMyObjects()
{
	int i;
	string name;
	for(i = ObjectsTotal(); i >= 0; i--)
	{
		name = ObjectName(i);
		if(	StringFind(name, tpl, 0) != -1)
		{
			ObjectDelete(name);
		}
	}
}