Who would have thought that would be the solution, eh?
I agree on your solutions earlier @honest_knavejust 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_";
void OnDeinit(const int reason)
double Line0 = ObjectGetValueByTime(0,ObjIdentifier+"Regression",Time,0);
double Line1 = ObjectGetValueByTime(0,ObjIdentifier+"Regression",Time,1);
double Line2 = ObjectGetValueByTime(0,ObjIdentifier+"Regression",Time,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 );
ObjectSetString (0,ObjIdentifier+name,OBJPROP_TEXT,name+" Channel");
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
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?
I've tried this:
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