![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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 );
}
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.
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?
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 );
}
}
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 :)
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? :)
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:
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