ObjectGetValueByTime - page 2

To add comments, please log in or register
Mohamad Zulhairi Baba
19768
Mohamad Zulhairi Baba  
honest_knave:

Who would have thought that would be the solution, eh? 


I agree on your solutions earlier @honest_knave
just want clarifications in OnTick handle, for double value keep switching from 0 it it's double value.



honest_knave
Moderator
2306
honest_knave  
Mohamad Zulhairi Baba:


I agree on your solutions earlier @honest_knave
just want clarifications in OnTick handle, for double value keep switching from 0 it it's double value.




Yes, as I mentioned earlier your code creates the object every single tick (if it already exists, your code deletes it then recreates it).

If you don't wait long enough, you will get 0.

If you do wait long enough, you will get the correct value.

TBH, there is a lot of unnecessary code. This will give you the correct value right from the first tick:

string      ObjIdentifier = "ABC_";

int OnInit()
  {
   return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
   Comment("");
   ObjectsDeleteAll(0,ObjIdentifier);
  }

void OnTick()
  {  
   DrawRegressionChannel("Regression",Time[10],High[10],Time[5],Low[5],STYLE_SOLID,clrRed,2,true);
   ChartRedraw();
   Sleep(50);
   double Line0 = ObjectGetValueByTime(0,ObjIdentifier+"Regression",Time[1],0);
   double Line1 = ObjectGetValueByTime(0,ObjIdentifier+"Regression",Time[1],1);
   double Line2 = ObjectGetValueByTime(0,ObjIdentifier+"Regression",Time[1],2);
   Comment( "\nTime Now : ",TimeToString(TimeCurrent()),
            "\n\nTest Value Regression 0 : ",Line0,
            "\n\nTest Value Regression 1 : ",Line1,
            "\n\nTest Value Regression 2 : ",Line2);
  }

void DrawRegressionChannel(string name, datetime T0, double P0, datetime T1, double P1, int style, color clr, int width, bool ray)
  {
   if(ObjectFind(0,ObjIdentifier+name) < 0)
     {
      ObjectCreate(ObjIdentifier+name,OBJ_REGRESSION, 0, T0, P0, T1, P1 );
      ObjectSetInteger(0,ObjIdentifier+name,OBJPROP_STYLE,style);
      ObjectSetInteger(0,ObjIdentifier+name,OBJPROP_COLOR,clr);
      ObjectSetInteger(0,ObjIdentifier+name,OBJPROP_WIDTH, width);
      ObjectSetInteger(0,ObjIdentifier+name,OBJPROP_RAY, ray);
      ObjectSetInteger(0,ObjIdentifier+name,OBJPROP_BACK,false);
      ObjectSetString (0,ObjIdentifier+name,OBJPROP_TEXT,name+" Channel");
    }
  }
Mohamad Zulhairi Baba
19768
Mohamad Zulhairi Baba  
honest_knave:


Yes, as I mentioned earlier your code creates the object every single tick (if it already exists, your code deletes it then recreates it).

If you don't wait long enough, you will get 0.

If you do wait long enough, you will get the correct value.

TBH, there is a lot of unnecessary code. This will give you the correct value right from the first tick:

 

Thanks @honest_knave, really appreciate it. :)
honest_knave
Moderator
2306
honest_knave  
The post has now gone, but I agree it is a bit of crude workaround.
iRick
217
iRick  

I'm having a similar issue to this :

I've got the equivalent of above working, I'm able to capture the OBJ_REGRESSION values via ObjectGetValueByTime

But.... this only works using the visual mode strategy test, otherwise it just returns 0 (as in the problem above)

I know that Sleep has no impact on a Strategy Test is ChartRedraw the same?

or is there any way to simulate/force a tick via code to solve the strategy tester issue?

iRick
217
iRick  
iRick:

I'm having a similar issue to this :

I've got the equivalent of above working, I'm able to capture the OBJ_REGRESSION values via ObjectGetValueByTime

But.... this only works using the visual mode strategy test, otherwise it just returns 0 (as in the problem above)

I know that Sleep has no impact on a Strategy Test is ChartRedraw the same?

or is there any way to simulate/force a tick via code to solve the strategy tester issue?

I tried separately adding a horizontal line and then deleting it, hoping that it would somehow refresh, but it seems the chart isn't re-drawn until after the OnTick() has processed

iRick
217
iRick  
iRick:

I'm having a similar issue to this :

I've got the equivalent of above working, I'm able to capture the OBJ_REGRESSION values via ObjectGetValueByTime

But.... this only works using the visual mode strategy test, otherwise it just returns 0 (as in the problem above)

I know that Sleep has no impact on a Strategy Test is ChartRedraw the same?

or is there any way to simulate/force a tick via code to solve the strategy tester issue?

Anyone got any ideas?

Is it impossible? so basically ObjectGetValueByTime won't work via Strategy Tester

Will creating OBJ_REGRESSION lines via an Indicator and then calling from the EA help?

Is it worth putting this question to the Freelance section?

iRick
217
iRick  

I've tried this:

https://www.mql5.com/en/forum/280520

Same issue, values aren't populated until after the tick while using Strategy Tester (in non visual mode) rendering ObjectGetValueByTime useless

May have to resort to looping all the values into an array and then calculating the Intercept/Gradient manually


HELP HELP HELP ::::: How to get Regression Channel value?
HELP HELP HELP ::::: How to get Regression Channel value?
  • 2018.09.21
  • www.mql5.com
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...
12
To add comments, please log in or register