How to sort MT4 Self-Created Class (CList)

Asked 2 years ago, Updated 2 years ago, 37 views

We store data obtained using MT4 in our own class.

I would like to set it to the list using the code below and sort it by the positionProfitLoss column in the list. Could you tell me how to compare, sort?

class HogeClass:public CObject{
public:
  string hogeId, hogeTime
  intamount, positionProfitLoss
public:
  void
    hereinafter abbreviated
}

CList hogeList;

voidsetToList(){
  HogeClass*hoge=new HogeClass(
    "posId 1234"
    , "20201010"
    , 1000
    , -49
  );
  hogeList.Add(hoge);
}

c++

2022-09-30 15:44

1 Answers

When you ask questions, write more information about your environment.

I'm not sure what "MT4" means, but let's say it's probably "MetaTrader4".

As far as MetaTrader 5 references are concerned, if you override CObject::Compare() and compare it based on the desired member variable, you can use CList::Sort().

class Xxx:public CObject{
...
public:
    virtual int Compare(const CObject*node, const int mode = 0) const override {
        // To obtain a pointer from the node argument to Xxx, click
        // Downcast with static_cast or dynamic_cast.
        // Returns 0 if this object equals a node object.
        // Returns -1 if this object is smaller than the node object.
        // Returns 1 if this object is greater than the node object.
        // It is not known what the argument mode is.
    }
};

Before you ask a question, read the reference first.Regardless of major or small vendors, Japanese references can be translated incorrectly or out of date, so you can get more accurate information by reading the original English references.If you have high school knowledge, you can read technical English.

By the way, this library looks very similar to the old Microsoft Foundation Classes (MFCs), but from the standpoint of a fairly experienced C++ programmer, the overall design is quite strange.I think it's better not to use it unless there's a good reason.


2022-09-30 15:44

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.