Hello,
i am getting the following error when testing: invalid pointer access in 'S_D_Trader.mq5' (58,13)
This is the important part of the indicator.
The Method CheckForMitigation() return a Pointer of Zone object.
I never had so many problems while programming OOP, like with this language.
Can anyone help or explain why the pointer is invalid??
Show the code for CheckForMitigation.
This one is calling the other one:
Zone *CheckForMitigation() { datetime time = iTime(NULL, _timeframe, 0); double high = iHigh(NULL, _timeframe, 0); double low = iLow(NULL, _timeframe, 0); double open = iOpen(NULL, _timeframe, 0); double close = iClose(NULL, _timeframe, 0); Bar *bar = new Bar(-1, time, high, low, open, close); return _zones.CheckForMitigation(bar); }
Zone *CheckForMitigation(Bar *bar) { Zone *zone = _zones.GetFirstNode(); _lastMitigatedZone = NULL; while(zone != NULL) { if (zone.IsEntry(bar)) { DestroyZone(zone); _zones.DeleteCurrent(); _lastMitigatedZone = zone; //return zone; } zone = _zones.GetNextNode(); } return _lastMitigatedZone; }
Dont be confused, because of the same name "_zones", in the first Method _zones is a class and in the second its a CList
This one is calling the other one:
Dont be confused, because of the same name "_zones", in the first Method _zones is a class and in the second its a CList
while(zone != NULL) { if (zone.IsEntry(bar)) { DestroyZone(zone); <--- _zones.DeleteCurrent(); _lastMitigatedZone = zone; //return zone; } zone = _zones.GetNextNode(); }
Aren't you accidentaly deleting the Zone object there? That way, the pointer would become invalid but not NULL.
Use the debugger, set a breakpoint there and check the value for _lastMitigatedZone.
First of all thank you for your help.
I am not accidentaly deleting the Zone. I want to delete it/deleting it, because it is not important anymore.
But i am just deleting it out of the CList. Why is it losing the pointer when i delete it from the list, when i give it back as value?
Is there a way to get the pointer back?
The "DestoryZone" Method is just calling a Method in another class to delete an drawn object on chart. But at the moment it is doing nothing. Its just like a placeholder:
void DestroyZone(Zone *zone) { //_structureDrawer.DeleteObject(zone.GetName()); }
An other strange thing is, that when i call the same method from a method in the same class i dont get this error.
Is there maybe a problem with the scopes, when i call it from the OnInit Method?
The next thing, is that i cant debug it in the tester. It doesnt stop at my break point.
EDIT: I am using the Method DetechCurrent now. Was that the mistake?
First of all thank you for your help.
I am not accidentaly deleting the Zone. I want to delete it/deleting it, because it is not important anymore.
But i am just deleting it out of the CList. Why is it losing the pointer when i delete it from the list, when i give it back as value?
Is there a way to get the pointer back?
The "DestoryZone" Method is just calling a Method in another class to delete an drawn object on chart. But at the moment it is doing nothing. Its just like a placeholder:
An other strange thing is, that when i call the same method from a method in the same class i dont get this error.
Is there maybe a problem with the scopes, when i call it from the OnInit Method?
The next thing, is that i cant debug it in the tester. It doesnt stop at my break point.
EDIT: I am using the Method DetechCurrent now. Was that the mistake?
It's possible to debug on tester too, use the Start on History data:
You can control the symbol and timeframe on the options:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
i am getting the following error when testing: invalid pointer access in 'S_D_Trader.mq5' (58,13)
This is the important part of the indicator.
The Method CheckForMitigation() return a Pointer of Zone object.
I never had so many problems while programming OOP, like with this language.
Can anyone help or explain why the pointer is invalid??