PositionClass Help

 

Hi All,

Its been a while since uni and i am struggling with my position class

I need to be able to create a cList of my PositionClass:CObject and iterate through it etc.

I get an invalid pointer when I try to access the Profit() function of a PositionClass in the list.

Here is my class, what am I doing wrong ?

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
class PositionClass: public CObject
  {
private:
   int               m_arg;
   string            _symbol;
   string            _status;
   datetime          _opentime;
   datetime          _closetime;
   double            _openprice;
   double            _closeprice;
   double            _volume;

public:
   ulong             _ticketnumber;
   void              PositionClass(string symbol,ulong ticketnumber, double price, double volume);
   void              PositionClass(int aArg);
   void              PositionClass();
   void             ~PositionClass();
   void              Close(double price);
   double            Profit(double price);
  };
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void PositionClass::PositionClass(int aArg)
  {
   m_arg = aArg;
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void PositionClass::PositionClass()
  {
//nothing
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void PositionClass::~PositionClass()
  {
//nothing
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void PositionClass::PositionClass(string symbol,ulong ticketnumber, double price, double volume)
  {
   _symbol = symbol;
   _ticketnumber = ticketnumber;
   _openprice = price;
   _volume = volume;
   _opentime = TimeCurrent();
   _status = "OPEN";
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void PositionClass::Close(double price)
  {
   _closeprice = price;
   _closetime = TimeCurrent();
   _status = "CLOSED";
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double PositionClass::Profit(double price)
  {
   double profit = 0;
//if closed return the profit
   if(_status == "CLOSED")
     {
      profit = (_closeprice - _openprice) * _volume;
     }
//if open return the floating profit
   if(_status == "OPEN")
     {
      profit = (price - _openprice) * _volume;
     }
   return profit;
  }
Documentation on MQL5: MQL5 programs / Runtime Errors
Documentation on MQL5: MQL5 programs / Runtime Errors
  • www.mql5.com
The executing subsystem of the client terminal has an opportunity to save the error code in case it occurs during a MQL5 program run. There is a predefined variable _LastError for each executable MQL5 program. Before starting the OnInit function, the _LastError variable is reset...
 
Please use the Styler to generate the code, and insert the code into the forum using the button Code(the first time I corrected your sheet from the text).
 
Geoffrey Warren Brown: Here is my class, what am I doing wrong ?

Do you really expect an answer? There are no mind readers here and our crystal balls are cracked. Always post all relevant code (using SRC).
     How To Ask Questions The Smart Way. 2004
          Be precise and informative about your problem

How can we know what it's doing and what you want it to do?

 
Why you not using ctrade class