HELP HELP HELP ::::: How to get Regression Channel value?

 

Hi guys, I,m trying to get regression channel value with this code below :

ObjectCreate("trend_regression",OBJ_REGRESSION,0,Time[200],0,Time[0],0);
ObjectSet("trend_regression",OBJPROP_DEVIATION,1);


Print("REG : ",ObjectGetValueByTime(ChartID(),"trend_regression",Time[0],0));

but I encounter with wrong respond( in this case, printed value is zero) ;

i.e the code returned the value OBJPROP_PRICE2 !!!!!

Can any one help me to get regression value in any TIME?

Sincerely...

 

Just search (top right) for "linear regression" => CodeBase or articles and use iCustom(..) to request the relevant data.

Search first:
Bare in mind there is practically nothing that has not been programmed for MQ4/5 yet! So search first!
Its easier and the result has fff: far fewer faults than a do-it-yourself-solution -  generally speaking!

 

Carl Schreiber:

Just search (top right) for "linear regression" => CodeBase or articles and use iCustom(..) to request the relevant data.


Search first:
Bare in mind there is practically nothing that has not been programmed for MQ4/5 yet! So search first!
Its easier and the result has fff: far fewer faults than a do-it-yourself-solution -  generally speaking!

Dear Carl, Thank you for your reply,


I already searched about this subject but my question is that why the code ---->>ObjectGetValueByTime(ChartID(),"trend_regression",Time[0],0)) <<----- 

do not work??!!!

please look at this page : https://docs.mql4.com/objects/objectgetvaluebytime

and read this paragraph :

Note

When this function is used on the current chart, this chart is accessed directly, while in order to receive the properties of an object on a different chart, a synchronous call is used. The synchronous call means that the function waits for the execution of all commands that have been enqueued for this chart prior to its call, that is why this function can be time consuming. This feature should be taken into account when working with a large number of objects on a chart.

An object can have several values in one price coordinate, therefore it is necessary to specify the line number. This function applies only to the following objects:

  • Trendline (OBJ_TREND)
  • Trendline by angle (OBJ_TRENDBYANGLE)
  • Gann line (OBJ_GANNLINE)
  • Equidistant channel (OBJ_CHANNEL) - 2 lines
  • Linear regression channel (OBJ_REGRESSION) - 3 lines
  • Standard deviation channel (OBJ_STDDEVCHANNEL) - 3 lines


So the code  objectgetvaluebytime about this object should be work correctly but did not!!!! why?


ObjectGetValueByTime - Object Functions - MQL4 Reference
ObjectGetValueByTime - Object Functions - MQL4 Reference
  • docs.mql4.com
When this function is used on the current chart, this chart is accessed directly, while in order to receive the properties of an object on a different chart, a synchronous call is used. The synchronous call means that the function waits for the execution of all commands that have been enqueued for this chart prior to its call, that is...
 

Set it first, then get the value on the next tick.

//+------------------------------------------------------------------+
//| Expert deinitialization function                                 |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
  {
//---
   ObjectDelete("trend_regression");
  }
//+------------------------------------------------------------------+
//| Expert tick function                                             |
//+------------------------------------------------------------------+
void OnTick()
  {
//---
   int ratesTotal=Bars;
   static int prevCalculated;
   
   if(ratesTotal!=prevCalculated)
     {
      ObjectCreate("trend_regression",OBJ_REGRESSION,0,0,0,0,0);
      ObjectSet("trend_regression",OBJPROP_TIME1,Time[0]);
      ObjectSet("trend_regression",OBJPROP_TIME2,Time[200]);
      ObjectSet("trend_regression",OBJPROP_DEVIATION,1);
     }
   else
      Print("REG : ",ObjectGetValueByTime(ChartID(),"trend_regression",Time[0],0));
      
   prevCalculated=ratesTotal;
  }
//+------------------------------------------------------------------+
 
Ernst Van Der Merwe:

Set it first, then get the value on the next tick.

Dear "Ernst Van Der Merwe",Thank you so much for your correct reply.I get it.  It works correctly... Thanks
Reason: