how to pass the color parameter into user define function

 

Hi all

I have a problem :how to pass the parameter to user difine function :

example :
CreateObject("Test1",Green);
CreateObject("Test2",C'236,130,0')
CreateObject("Test3",32768 )

void CreateObject(string Name1,int DefineColor)
{

ObjectCreate(Name1,OBJ_LABLEL,WindowFind("Indicato r1"),0,0);
ObjectSetText(Name1,"Testing",12,"Arial Bold:,DefineColor);
}


1. so how to pass the Color for Green, C'235,130,0,' or 32768 ?

2. in the User define function, what is the type of the color? can be string ? int? double or color ? I have try but failed

3. what is the type variable for color, or can be convert from interger, string into color type variable ?

4. can you all show me the url for this kind of detail description.

thanks for the help

rgds bob

 

color is a 4 byte unsigned integer

pass type color or int to your function

if you want to pass Green, Green has been defined somewhere as a color integer, so use color or int for parameter type.

 
Sample

void SetArrow(datetime ArrowTime, double Price, double ArrowCode, color ArrowColor)
{
 int i,err;
 string obj_name;
 //string ArrowName = indicator_name+DoubleToStr(ArrowTime,0);
 string ArrowName = indicator_name+DoubleToStr(ArrowCode,0);
   //if (ObjectFind(ArrowName) != -1) ObjectDelete(ArrowName);
//---
for (i=ObjectsTotal()-1;i>=0;i--) {
         obj_name=ObjectName(i);    
         if (indicator_name==StringSubstr(obj_name,0,StringLen(indicator_name))) ObjectDelete(obj_name); 
      }
//---   
   if (indicator_name==StringSubstr(ArrowName,0,StringLen(indicator_name))) ObjectDelete(ArrowName);
   if(!ObjectCreate(ArrowName, OBJ_ARROW, 0, ArrowTime, Price))
    {
      err=GetLastError();
      Print("error: can't create Arrow! code #",err);
      return;
    }
   else
   {
     ObjectSet(ArrowName, OBJPROP_ARROWCODE, ArrowCode);
     ObjectSet(ArrowName, OBJPROP_COLOR , ArrowColor);
     WindowRedraw();
   }
}
 
thanks:

color is a 4 byte unsigned integer

pass type color or int to your function

if you want to pass Green, Green has been defined somewhere as a color integer, so use color or int for parameter type.

 
Rosh:
Sample

void SetArrow(datetime ArrowTime, double Price, double ArrowCode, color ArrowColor)
{
 int i,err;
 string obj_name;
 //string ArrowName = indicator_name+DoubleToStr(ArrowTime,0);
 string ArrowName = indicator_name+DoubleToStr(ArrowCode,0);
   //if (ObjectFind(ArrowName) != -1) ObjectDelete(ArrowName);
//---
for (i=ObjectsTotal()-1;i>=0;i--) {
         obj_name=ObjectName(i);    
         if (indicator_name==StringSubstr(obj_name,0,StringLen(indicator_name))) ObjectDelete(obj_name); 
      }
//---   
   if (indicator_name==StringSubstr(ArrowName,0,StringLen(indicator_name))) ObjectDelete(ArrowName);
   if(!ObjectCreate(ArrowName, OBJ_ARROW, 0, ArrowTime, Price))
    {
      err=GetLastError();
      Print("error: can't create Arrow! code #",err);
      return;
    }
   else
   {
     ObjectSet(ArrowName, OBJPROP_ARROWCODE, ArrowCode);
     ObjectSet(ArrowName, OBJPROP_COLOR , ArrowColor);
     WindowRedraw();
   }
}

 

thanks for the reply,

I have try using color as a parametertype and success to pass the Green color integer, but how about the parameter is somting like C'236,130,0' to pass the function ?

for example :

CreateObject("Test2",C'236,130,0') // --- please check, as is the sperate of the parameter.


void CreateObject(string Name1,color DefineColor)
{

ObjectCreate(Name1,OBJ_LABLEL,WindowFind("Indicato r1"),0,0);
ObjectSetText(Name1,"Testing",12,"Arial Bold:,DefineColor);
}


where define parameter like C'236,130,0' is posible to pass in the function ?

rgds bob

 

color myColor = C'236,130,0';

Print(" myColor = ", myColor);

2008.01.31 13:00:13 Phy__Test2 EURJPY,M1: myColor = 33516


Print(" Defined Color = ", C'236,130,0');

2008.01.31 13:01:46 Phy__Test2 EURJPY,M15: Defined Color = 33516

What's your problem?

 
Hi Phy
Thanks for your reply
from your reply I got my answer, convert into integer first, and then send by integer, my previous question : I don't know the relation between color type variable with the integer so I cannot send directly like :
CreateObject("Test2",C'236,130,0'), because the comma act as like the parameter seperator, after your explation by example, so I get the idea, convert first into integer, and then send as a color parameter, thanks explanation by simple example.


rgds bob
 

I don't see a problem:


int start()
{
 SetColor( C'127,128,128');
 
return(0);
}
void SetColor( color myColor){
 
 ObjectCreate("RECT", OBJ_RECTANGLE, 0, Time[0], Close[0], Time[50], Close[50]);
 ObjectSet("RECT", OBJPROP_COLOR, myColor);
 
}
 
Hi:



I don't see a problem:






int start()
{
 SetColor( C'127,128,128');
 
return(0);
}
void SetColor( color myColor){
 
 ObjectCreate("RECT", OBJ_RECTANGLE, 0, Time[0], Close[0], Time[50], Close[50]);
 ObjectSet("RECT", OBJPROP_COLOR, myColor);
 
}
 
See also https://forum.mql4.com/9407