Type()
Tobias,
Many thanks for response
Understand your words but still a little confused.
I don't see any reference to Type() by itself - which I understand to be required to return a value from the following expression (which I incorrectly used)
myposition.Type();
Perhaps I am misunderstanding something but the following are ALL the references to Type() in PositionInfo.mqh
return(FormatType(str,PositionType())); // line # 127 FormatType(type,PositionType()), // line # 271 FormatType(type,PositionType()), // line # 277 m_type =PositionType(); // line # 344 if(m_type==PositionType() && // line # 355
and PositionType() is found via the following
ENUM_POSITION_TYPE CPositionInfo::PositionType(void) const { return((ENUM_POSITION_TYPE)PositionGetInteger(POSITION_TYPE)); }
I don't see where .Type is found
TicketType = myposition.Type();
Like I said previously the above doesn't return TYPE of deal just appears to default to ZERO
I don't see any reference to Type() by itself - which I understand to be required to return a value from the following expression (which I incorrectly used)
Oh yes, of course. I just looked into it and the method Type() is not even inside the CPositionInfo class but in the CObject class that it inherits from.
//+------------------------------------------------------------------+ //| PositionInfo.mqh | //| Copyright 2009-2020, MetaQuotes Software Corp. | //| http://www.mql5.com | //+------------------------------------------------------------------+ #include <Object.mqh> //+------------------------------------------------------------------+ //| Class CPositionInfo. | //| Appointment: Class for access to position info. | //| Derives from class CObject. | //+------------------------------------------------------------------+ class CPositionInfo : public CObject { protected: ENUM_POSITION_TYPE m_type; double m_volume; double m_price; ...
It inherits the public aspects from CObject which you find directly in the Include folder with no subfolder whatsoever.
class CObject { private: CObject *m_prev; // previous item of list CObject *m_next; // next item of list public: CObject(void): m_prev(NULL),m_next(NULL) { } ~CObject(void) { } //--- methods to access protected data CObject *Prev(void) const { return(m_prev); } void Prev(CObject *node) { m_prev=node; } CObject *Next(void) const { return(m_next); } void Next(CObject *node) { m_next=node; } //--- methods for working with files virtual bool Save(const int file_handle) { return(true); } virtual bool Load(const int file_handle) { return(true); } //--- method of identifying the object virtual int Type(void) const { return(0); } //--- method of comparing the objects virtual int Compare(const CObject *node,const int mode=0) const { return(0); } }; //+------------------------------------------------------------------+
As you can see it returns 0; But this is not position type. I don't know what id does to be honest, except that you could use it to return enums of different objects types, as int types maybe. But that is not concerning you when working with PositionInfo. Not sure what it does here. The method Could be changed to give back enums of object types, which are somewhat analog to integers.
Tobias,
Thanks again for your swift response.
I am not going mad after all!
Seems a little weird.
Just really a warning for anyone using position.Type() - it doesn't do what one may expect
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
I used option //A above to get the ticket type using the standard libraries
I now understand this was incorrect and should use option //B
BUT... I didn't get any error using //A but the result was always zero
I would have expected a 'compile' error if .Type is an invalid option.
Obviously have now tracked down my problem but curious about why the command appeared to have been accepted (and took me longer than expected to track down)