Download MetaTrader 5
To add comments, please log in or register
Join MQL5 Cloud Network. Start earning money!
ZenTrader
51
ZenTrader 2014.10.20 23:33 

Hi,

 I have spent a frustrating few hours attempting to rename an Rectangle object from a class function call inside the OnEvent.

 

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

   m_Prime.ChartEvent(id, lparam, dparam, sparam);

  }

 

I can get all the data from the created object and the build a new rectangle they way I want it. I then need to delete the original. But I can't. Even if I use DeleteAllObjects, it removes all object apart from the one in the Create event.

 

void Prime::ChartEvent(const int id, const long& lparam, const double& dparam, const string& sparam)
{
    switch (id)
    {
        case CHARTEVENT_OBJECT_CREATE:
        {
            if (ObjectGet(sparam, OBJPROP_TYPE)  == OBJ_RECTANGLE)
            {
                ChartSetInteger(0, CHART_EVENT_OBJECT_CREATE, 0);
                ChartSetInteger(0, CHART_EVENT_OBJECT_DELETE, 0);
                Print("Event Create ..");
                RectangleStuff(sparam); // Looks at the rectangle then builds a new one with a different name.
                ObjectDelete(0,sparam);
                ChartSetInteger(0, CHART_EVENT_OBJECT_CREATE, 1);
                ChartSetInteger(0, CHART_EVENT_OBJECT_DELETE, 1);
            }
        }
    }
    return;
}        

 

I have tried even setting a bool global variable for deletion outside of the main OnChartEvent, but that also would not work. My final thought was to let a tick go by and call a delete from OnCalculate but that just sounded absurd. So how do I end the relationship with the OnChartEvent and this rectangle object, so that I can delete it?  

Alain Verleyen
Moderator
28672
Alain Verleyen 2014.10.21 15:25  
ZenTrader:

Hi,

 I have spent a frustrating few hours attempting to rename an Rectangle object from a class function call inside the OnEvent.

 

 

I can get all the data from the created object and the build a new rectangle they way I want it. I then need to delete the original. But I can't. Even if I use DeleteAllObjects, it removes all object apart from the one in the Create event.

 

 

I have tried even setting a bool global variable for deletion outside of the main OnChartEvent, but that also would not work. My final thought was to let a tick go by and call a delete from OnCalculate but that just sounded absurd. So how do I end the relationship with the OnChartEvent and this rectangle object, so that I can delete it?  

What's the error code returned by ObjectDelete() ?

Return Value

Returns true if the removal was successful, otherwise returns false. To read more about the error call GetLastError().

/
To add comments, please log in or register