Print not only the values but also the all the relevant timestamps and other values: time_0, time_1,_Period, and the results of the ObjectCreation and of course _LastError!
Print("Val_0 : ",val0); Print("Val_1 : ",val1); Print("time_0 : ",time_0); Print("time_1 : ",time_1); Print("Period : ",_Period); Print("Last error : ", GetLastError());
Read the text below the title: Object functions
It says:
Although it claims that ChartRedraw() will/should update chart, in my experience, it still does not work every time, no matter how long sleep you use.
Try to verify that object exists with ObjectFind().
Also, you are deleting and creating an object on every tick. Don't do that. You need to move the channel online when the new bar starts.
- First, detect if you are on a new bar.
- If it is a new bar, use ObjectFind() to detect if you already created an object,
- if it does not exist, create it,
- else use ObjectMove() to move it to the new position
This probably won't solve your problem, you won't be able to modify the channel object and immediately read new values.

- www.mql5.com
Strategy tester works differently, it draws only one chart and it does it synchronously.
That is why you see values in a strategy tester.
Read the text below the title: Object functions
It says:
Although it claims that ChartRedraw() will/should update chart, in my experience, it still does not work every time, no matter how long sleep you use.
Try to verify that object exists with ObjectFind().
Also, you are deleting and creating an object on every tick. Don't do that. You need to move the channel online when the new bar starts.
- First, detect if you are on a new bar.
- If it is a new bar, use ObjectFind() to detect if you already created an object,
- if it does not exist, create it,
- else use ObjectMove() to move it to the new position
This probably won't solve your problem, you won't be able to modify the channel object and immediately read new values.
Thank you for the guidance. I will definitely use your words.
i test ObjectFind and newbar . also print 0 .
I think using the while loop will solve my problem to some extent
while(val0==0) { val0=ObjectGetValueByTime(0,"a",time_0,0); Sleep(1); } while(val1==0) { val1=ObjectGetValueByTime(0,"a",time_1,0); Sleep(1); }
When you create the object you define the two times but for both the price value is 0:
ObjectCreate(0,"a",OBJ_REGRESSION,0,time_1, 0,time_0, 0);
Read the ref. for this: https://www.mql5.com/en/docs/objects/objectcreate

- www.mql5.com
When you create the object you define the two times but for both the price value is 0:
ObjectCreate(0,"a",OBJ_REGRESSION,0,time_1, 0,time_0, 0);
Read the ref. for this: https://www.mql5.com/en/docs/objects/objectcreate

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi . i create Regression Line with code :
The regression line between candles 1 and 29 is correctly drawn.
But when I want to get the values of the middle line of regression in candles 1 and 29 using the ObjectGetValueByTime() function, the value 0 is printed.
In the strategy tester , the program works correctly and variable values are printed! But in real time 0 values are printed!
To solve the problem, I used the Sleep function and the problem was solved to some extent, but the value 0 is printed from time to time!
Thank you for your guidance.
please see below Gif file