ObjectGetDouble returns "object does not exist" error even though object exists

 

This has me baffled.  I'm drawing a horizontal line on my chart, and allowing the user to select and drag it to vary a value. I'm handling a CHARTEVENT_OBJECT_DRAG event,  and the object is recognized, raises the event, and passes the name of the object in the sparam.  But when I do an "ObjectGetDouble(0, objectName, OBJPROP_PRICE, 0, propertyValue)", it's returning false (failure), the propertyValue remains 0.0, and GetLastError() reports 4202 (ERR_OBJECT_DOES_NOT_EXIST).

How can it exist and raise and event, but not exist when I try to get its property? 

 
daveh551:

This has me baffled.  I'm drawing a horizontal line on my chart, and allowing the user to select and drag it to vary a value. I'm handling a CHARTEVENT_OBJECT_DRAG event,  and the object is recognized, raises the event, and passes the name of the object in the sparam.  But when I do an "ObjectGetDouble(0, objectName, OBJPROP_PRICE, 0, propertyValue)", it's returning false (failure), the propertyValue remains 0.0, and GetLastError() reports 4202 (ERR_OBJECT_DOES_NOT_EXIST).

How can it exist and raise and event, but not exist when I try to get its property? 

Are you trying to get the object property while dragging it? Why don't you use CHARTEVENT_OBJECT_CLICK instead?
 
daveh551:

This has me baffled.  I'm drawing a horizontal line on my chart, and allowing the user to select and drag it to vary a value. I'm handling a CHARTEVENT_OBJECT_DRAG event,  and the object is recognized, raises the event, and passes the name of the object in the sparam.  But when I do an "ObjectGetDouble(0, objectName, OBJPROP_PRICE, 0, propertyValue)", it's returning false (failure), the propertyValue remains 0.0, and GetLastError() reports 4202 (ERR_OBJECT_DOES_NOT_EXIST).

How can it exist and raise and event, but not exist when I try to get its property? 

Please show code to reproduce your problem.
 
angevoyageur:
Please show code to reproduce your problem.

Here's the code:

 

void OnChartEvent(const int id,const long& lparam,const double& dparam,const string& sparam)

  {

      if(id == CHARTEVENT_OBJECT_DRAG && sparam == baseLineName)

        {

            ResetLastError();

            long currentChart = ChartID();

            double lineValue;

            bool success = ObjectGetDouble(0, baseLineName, OBJPROP_PRICE, 0, lineValue);

            if(!success)

              {   

                  int lastError = GetLastError();

                  Alert("ObjectGetDouble() [", baseLineName,"] failed: ", ErrorDescription(lastError), " (", lastError, ")");

                  return;

              }


 I do some other things with lineValue after that code, but the error has occurred by the "if (!success)" block.

Thanks for your help. 

 
daveh551:

Here's the code:

 I do some other things with lineValue after that code, but the error has occurred by the "if (!success)" block.

Thanks for your help. 

Hello Daveh,

instead of using CHARTEVENT_OBJECT_DRAG I suggest you to use CHARTEVENT_OBJECT_CLICK...

Something like this:

void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
{
//---
   if(id==CHARTEVENT_OBJECT_CLICK)
   {
      string ClickedChartObject=sparam;
      Print("You clicked on the object named '"+sparam+"'");
      //--- 
      if(ClickedChartObject == "baseLineName")
      Print("Object price = "+ObjectGetDouble(0, "baseLineName", OBJPROP_PRICE, 0));
      //---
      ChartRedraw();
   }

 I hope it helps you somehow.

 
Malacarne:

Hello Daveh,

instead of using CHARTEVENT_OBJECT_DRAG I suggest you to use CHARTEVENT_OBJECT_CLICK...

Something like this:

 I hope it helps you somehow.

The thing is that I don't want to get an event when the line is clicked on.  I only want an event when it's dragged to a new position.  So a) it does seem that CHARTEVENT_OBJECT_DRAG is the right event, and b) OnChartEvent is firing at the time that I want it to and c) whether I use OBJECT_CLICK or OBJECT_DRAG, I still need to read the value of the object property, and that is the call that's failing.  Unless there's an implementation error in CHARTEVENT_OBJECT_DRAG that is causing  MQL to think the object doesn't exist, then I don't see that using CHARTEVENT_OBJECT_CLICK would really solve anything.
 
Dave, you retreive the chart ID in your code and store it in variable currentChart. But in ObjectGetDouble you hardwire the chart ID to zero. If your chart is a sub-chart then this approach should not work.
Reason: