Question about drawing in an object. - page 2

 
fxcourt:

Strange. This is what i used to test it.

int init()

{

ObjectCreate( "reg",OBJ_REGRESSION, 0, iTime(NULL,60,3), 0, iTime(NULL,60,0)) ;

}


int start()

{


ObjectSet("reg",OBJPROP_TIME1,iTime(NULL,60,Hour()));

ObjectSet("reg",OBJPROP_TIME2,iTime(NULL,60,0));

double regression_value = ObjectGet("reg",OBJPROP_TIME2);

Comment(regression_value);

}


int init()

{

ObjectCreate( "reg",OBJ_REGRESSION, 0, iTime(NULL,60,3), 0, iTime(NULL,60,0)) ;

}


int start()

{


ObjectSet("reg",OBJPROP_TIME1,iTime(NULL,60,Hour()));

ObjectSet("reg",OBJPROP_TIME2,iTime(NULL,60,0));

double regression_value = ObjectGet("reg",OBJPROP_PRICE2);

Comment(regression_value );

}

 
fxcourt:


int init()

{

ObjectCreate( "reg",OBJ_REGRESSION, 0, iTime(NULL,60,3), 0, iTime(NULL,60,0)) ;

}


int start()

{


ObjectSet("reg",OBJPROP_TIME1,iTime(NULL,60,Hour()));

ObjectSet("reg",OBJPROP_TIME2,iTime(NULL,60,0));

double regression_value = ObjectGet("reg",OBJPROP_PRICE2);

Comment(regression_value );

}

Yes, this does it. I'll try to put this in my EA now to see how it will work.

 
fxcourt:


int init()

{

ObjectCreate( "reg",OBJ_REGRESSION, 0, iTime(NULL,60,3), 0, iTime(NULL,60,0)) ;

}


int start()

{


ObjectSet("reg",OBJPROP_TIME1,iTime(NULL,60,Hour()));

ObjectSet("reg",OBJPROP_TIME2,iTime(NULL,60,0));

double regression_value = ObjectGet("reg",OBJPROP_PRICE2);

Comment(regression_value );

}

Ok, but you are using the H1 time-frame. How can I convert that to M15? Also I want to regression channel to be redrawn after a new bar has been completed, so how can I avoid the 0 bars?

 
Nauticus:

Ok, but you are using the H1 time-frame. How can I convert that to M15? Also I want to regression channel to be redrawn after a new bar has been completed, so how can I avoid the 0 bars?


datetime time;

int init()

{

time = Time[0];

ObjectCreate( "reg",OBJ_REGRESSION, 0, iTime(NULL,60,3), 0, iTime(NULL,60,0)) ;

}


int start()

{

if(time != Time[0])//assume the ea runs on a 15M chart, this will run once on the first tick of each bar

{

time = Time[0];

ObjectSet("reg",OBJPROP_TIME1,iTime(NULL,60,Hour()));//this will keep the first point at 00:00

ObjectSet("reg",OBJPROP_TIME2,iTime(NULL,15,1));//will move the second point to the previous closed bar

double regression_value = ObjectGet("reg",OBJPROP_PRICE2);

Comment(regression_value );

}

}

 
fxcourt:


datetime time;

int init()

{

time = Time[0];

ObjectCreate( "reg",OBJ_REGRESSION, 0, iTime(NULL,60,3), 0, iTime(NULL,60,0)) ;

}


int start()

{

if(time != Time[0])//assume the ea runs on a 15M chart, this will run once on the first tick of each bar

{

time = Time[0];

ObjectSet("reg",OBJPROP_TIME1,iTime(NULL,60,Hour()));//this will keep the first point at 00:00

ObjectSet("reg",OBJPROP_TIME2,iTime(NULL,15,1));//will move the second point to the previous closed bar

double regression_value = ObjectGet("reg",OBJPROP_PRICE2);

Comment(regression_value );

}

}

Excellent. There is a 1 pips difference at times, but it's not that big of a problem. Thanks for all the great help both fbj and fxcourt. I learned a lot from you guys :)

 
Your welcome Nauticus
 

Guys I have a new problem now. With this solution you provided me everything works fine, but when I started testing it on longer periods I sometimes got this:



The code I'm using looks like this:

int Bar=27;

datetime time;

int init()
{
 time=Time[0];
 ObjectCreate("Regression",OBJ_REGRESSION,0,iTime(NULL,60,3),0,iTime(NULL,60,0));
 ObjectSet("Regression",OBJPROP_COLOR,Red);
}

int start()
{  
 if (Hour()>=8 && Hour()<=20)
 {
  if(time != Time[0])
  {
   time = Time[0];
    if (DayOfWeek()==1)
    {
     Bar++;
     ObjectSet("Regression",OBJPROP_TIME1,iTime(NULL,15,Bar));
     ObjectSet("Regression",OBJPROP_TIME2,iTime(NULL,15,1));
    }
    else 
    {
     ObjectSet("Regression",OBJPROP_TIME1,iTime(NULL,60,Hour()));
     ObjectSet("Regression",OBJPROP_TIME2,iTime(NULL,15,1));
    }
   Reg_Value = ObjectGet("Regression",OBJPROP_PRICE2);
  }
  else ObjectDelete("Regression");
 }    
return;
}

This is the code that fxcourt gave me and it seemed to work. As you can see I changed it a bit so that it would detect Mondays where the market opens at 1AM and to do that I used the int Bar. However from the picture you can see that the channel was supposed to be drawn at 8AM, but somewhat didn't. So the problem is with the other days of the week. Could someone give any hints? :)

 
Nauticus:

Guys I have a new problem now. With this solution you provided me everything works fine, but when I started testing it on longer periods I sometimes got this:



The code I'm using looks like this:

This is the code that fxcourt gave me and it seemed to work. As you can see I changed it a bit so that it would detect Mondays where the market opens at 1AM and to do that I used the int Bar. However from the picture you can see that the channel was supposed to be drawn at 8AM, but somewhat didn't. So the problem is with the other days of the week. Could someone give any hints? :)

Why not try:

if (DayOfWeek()==1)
    {
     
     ObjectSet("Regression",OBJPROP_TIME1,iTime(NULL,60,Hour() - 1));
     ObjectSet("Regression",OBJPROP_TIME2,iTime(NULL,15,1));
    }
 
fxcourt:

Why not try:

Thanks, but it seems the big problem is with the other days, not Monday. I'm having those problems when testing it on January for some odd reason...

 

Hi Guys...

Read over this thread cause I was trying to get the value of the regression lines. I see that, using the code above, you can get the endpoint of the line as if wiggles around with the price. But I want the values of the upper and lower lines, not the center. Was hoping that

double deviation_value = ObjectGet("reg",OBJPROP_DEVIATION);

...would get the pips to add to OBJPROP_PRICE2, but it returns zero. Does anyone else have any way to get the value of the upper/lower lines?

Thank you,
-Derk