string 		DTPrefix				 	= "DTool";
string 		TF_Text 					= "undefined";
color       LineColor      		= Orange;
color			DT_M1Color				= DarkGray;
color			DT_M5Color				= DodgerBlue;
color			DT_M15Color				= Violet;
color			DT_M30Color				= HotPink;
color			DT_H1Color				= Orange;
color			DT_H4Color				= Blue;
color			DT_D1Color				= Brown;
color			DT_W1Color				= Green;
color			DT_MN1Color				= Tomato;
int		   visibility				= 1;
int         Width 					= 2;
string      LevelName 				= "";
//int			VisSettings				= 1; // 1= this TF + all lower; 0= this TF only

void SetColors(int tf,int VisSettings=1,bool twotone =false)
{
	switch(twotone)
	{
		 case true:
		 	if(tf <= 60) {LineColor = Red;	visibility = 1+2+4+8+16;TF_Text = "IntraDay";}
		 	if(tf > 60)  {LineColor = Red;	visibility = 1+2+4+8+16+32+64+128+256; TF_Text = "Swing";}
			break;
		 case false:
			switch(tf)
			{
				 case 1      :
				 	TF_Text = "1 Min";
				 	LineColor = DarkGray;
				 	VisSettings =1 ? visibility = 1: visibility = 1;
				 	//log(3,__FUNCTION__,TF_Text,"vis",visibility);
				 	break;
				 case 5      :
				 	TF_Text = "5 Min";
				 	LineColor = DodgerBlue;
				 	//visibility = 1+2;
				 	VisSettings =1 ? visibility = 1+2: visibility = 2;
				 	//log(3,__FUNCTION__,TF_Text,"vis",visibility);
				 	break;
				 case 15     :
				 	TF_Text = "15 Min";
				 	LineColor = Violet;
				 	visibility = 1+2+4;
				 	VisSettings =1 ? visibility = 1+2+4: visibility = 4;
				 	//log(3,__FUNCTION__,TF_Text,"vis",visibility);
				 	break;
				 case 30     :
				 	TF_Text = "30 Min";
				 	LineColor = HotPink;
				 	visibility = 1+2+4+8;
				 	VisSettings =1 ? visibility = 1+2+4+8: visibility = 8;
				 	//log(3,__FUNCTION__,TF_Text,"vis",visibility);
				 	break;
				 case 60     :
				 	TF_Text = "1Hr";
				 	LineColor = Orange;
				 	visibility = 1+2+4+8+16;
				 	VisSettings =1 ? visibility = 1+2+4+8+16: visibility = 16;
				 	//log(3,__FUNCTION__,TF_Text,"vis",visibility);
				 	break;
				 case 240    :
				 	TF_Text = "4Hr";
				 	LineColor = Blue;
				 	visibility = 1+2+4+8+16+32;
				 	VisSettings =1 ? visibility = 1+2+4+8+16+32: visibility = 32;
				 	//log(3,__FUNCTION__,TF_Text,"vis",visibility);
				 	break;
				 case 1440   :
				 	TF_Text = "Daily";
				 	LineColor = Brown;
				 	visibility = 1+2+4+8+16+32+64;
				 	VisSettings =1 ? visibility = 1+2+4+8+16+32+64: visibility = 64;
				 	//log(3,__FUNCTION__,TF_Text,"vis",visibility);
				 	break;
				 case 10080  :
				 	TF_Text = "Weekly";
				 	LineColor = Green;
				 	//visibility = 1+2+4+8+16+32+64+128;
				 	if(VisSettings==1) visibility = 1+2+4+8+16+32+64+128;
				 	else visibility = 128;
				 	//log(3,__FUNCTION__,TF_Text,"vis",visibility);
				 	break;
				 case 43200  :
				 	TF_Text = "Monthly";
				 	LineColor = Tomato;
				 	visibility = 1+2+4+8+16+32+64+128+256;
				 	VisSettings =1 ? visibility = 1+2+4+8+16+32+64+128+256: visibility = 256;
				 	//log(3,__FUNCTION__,TF_Text,"vis",visibility);
				 	break;
			}
	}

}

string   SetLevelName(string name, string symbol,int TF, string prefix="",string type= "")
{
	MathSrand(GetTickCount());
	string spc = "_";
	int unique = (int)MathRand()*TimeLocal();
	////log(4,"LevelName",name);

	name  += symbol+spc+TF+spc+(string)GetTickCount();

	if(prefix != "") name += prefix + spc;
	if(type != "") name += type + spc;
	////log(4,"LevelName",name);

	
	////log(4,"LevelName",name);
	name += makerand(name+(string)unique);
	////log(4,"LevelName",name);
	return (name);

}
int makerand(string key)
{

   int i, k;
   int h = 0;

   if (IsTesting()) {
      key = "_" + key;
   }

   for (i = 0; i < StringLen(key); i++) {
      k = StringGetChar(key, i);
      h = h + k;
      h = bitRotate(h, 5); // rotate 5 bits
   }

   for (i = 0; i < StringLen(key); i++) {
      k = StringGetChar(key, i);
      h = h + k;
      // rotate depending on character value
      h = bitRotate(h, k & 0x0000000F);
   }

   // now we go backwards in our string
   for (i = StringLen(key); i > 0; i--) {
      k = StringGetChar(key, i - 1);
      h = h + k;
      // rotate depending on the last 4 bits of h
      h = bitRotate(h, h & 0x0000000F);
   }

   return(h & 0x7fffffff);
}

int bitRotate(int value, int count)
{
	/**
	* Rotate a 32 bit integer value bit-wise
	* the specified number of bits to the right.
	* This function is needed for calculations
	* in the hash function makeMacicNumber()
	*/
   int tmp, mask;
   mask = (0x00000001 << count) - 1;
   tmp = value & mask;
   value = value >> count;
   value = value | (tmp << (32 - count));
   return(value);
}