Objects in MQL5

 

Hello,

I´m stuck with my code. I always get the "invalid pinter access" failure and I can´t fix it. Would be great if someone can see where I´m going wrong.

class CAOI : public CObject {
public: 
   ENUM_AOI_TYPE type;
   datetime time;
   double highAoi;
   double lowAoi;

};
CArrayObj aoiMn;
CArrayObj aoiW;
CArrayObj aoiD;
CArrayObj aoiFour;
CArrayObj aoiOne;
CArrayObj aoiFif;

.....

      CAOI* aoi = new CAOI();
      if(TrendUp == true) aoi.type = AOI_UP;
      else aoi.type = AOI_DOWN;
      aoi.time = timeHigherRangeLow;
      aoi.highAoi = prevHigherRangeHigh;
      aoi.lowAoi = higherRangeLow;
      aoi.mitigated = false;
      //aoi.draw(TimeCurrent());
      if(timeFrame == PERIOD_MN1) aoiMn.Add(aoi);
      if(timeFrame == PERIOD_W1) aoiW.Add(aoi);
      if(timeFrame == PERIOD_D1) aoiD.Add(aoi);
      if(timeFrame == PERIOD_H4) aoiFour.Add(aoi);
      if(timeFrame == PERIOD_H1) aoiOne.Add(aoi);
      if(timeFrame == PERIOD_M15) aoiFif.Add(aoi);

   
   for(int j = aoiMn.Total()-1; j >= 0; j--){
         CAOI* aoi = aoiMn.At(j);
         
         if(aoi.type == AOI_UP && iLow(_Symbol,PERIOD_M1,i) < aoi.lowAoi) aoiMn.Delete(j);
         if(aoi.type == AOI_DOWN && iHigh(_Symbol,PERIOD_M1,i) > aoi.highAoi) aoiMn.Delete(j);


    }

The last line gives me the error, if I exclude that line from my code it works.


Thank you

Anja

 
Anja Einbecker:

The last line gives me the error, if I exclude that line from my code it works.

         if(aoi.type == AOI_UP && iLow(_Symbol,PERIOD_M1,i) < aoi.lowAoi) aoiMn.Delete(j);
         else if(aoi.type == AOI_DOWN && iHigh(_Symbol,PERIOD_M1,i) > aoi.highAoi) aoiMn.Delete(j);
Don't access a pointer (aoi, in this case) after you deleted the object it points to.
 
Stanislav Korotky #:
Don't access a pointer (aoi, in this case) after you deleted the object it points to.
it works, thank you :)