Add int flag in each trade order

 
I try to tarck EA trading detail. I put flag in OrderInfo class .
1.As buy ,put an flag. Check modify okay.
2.Check the flag later ,it come to unknown state.

It's look like orderinfo just  a copy of trade operation.Want to know is PositionInfo or tradeinfo class keep trade data  always,that I can put flag to store date for later usage.

class COrderInfo : public CObject
  {
protected:
   ulong             m_ticket;
 ...
   double            m_stop_loss;
   double            m_take_profit;

   uint  m_newproperty;

public:

   uint              newproperty(void) const;

   uint              newpropertyChange(const uint newproperty) ;

}


void OnTrade(void)

  {

      COrderInfo m_order;

     m_order.Select(my_result.order);

if ( OrderGetInteger(ORDER_STATE)==ORDER_STATE_PLACED)

     { m_order.CheckState();  

       m_order.PolicyChange(3);

       m_order.StoreState(); 

       m_ticket=my_result.order;   

}


}





Strategy Testing - Algorithmic Trading, Trading Robots - MetaTrader 5 Help
Strategy Testing - Algorithmic Trading, Trading Robots - MetaTrader 5 Help
  • www.metatrader5.com
The Strategy Tester allows you to test and optimize trading strategies (Expert Advisors) before using them for live trading. During testing, an Expert Advisor with initial parameters is once run on history data. During optimization, a trading strategy is run several times with different sets of parameters which allows selecting the most...
 
It's difficult to understand you. You could use a translation tool.
 
lippmaje:
It's difficult to understand you. You could use a translation tool.

I don't find it difficult at all.
I find it impossible to understand.

 
Keith Watford:

I don't find it difficult at all.
I find it impossible to understand.

Update discription.
Keith you are my fellow. 
 
How do you use the class, how do you add the flag, and what do you mean by "check later"? Can you show the code?
 
lippmaje:
How do you use the class, how do you add the flag, and what do you mean by "check later"? Can you show the code?

update code ~ check later is after few seconds to read the flag. >> I not special to descriptor it.

 
sungsungD:

update code ~ check later is after few seconds to read the flag. >> I not special to descriptor it.

You need to keep the info in the global variable scope.

At the moment you are allocating a local object in OnTrade:

void OnTrade(void)
  {
   COrderInfo m_order;
   ...
  } // <- m_order goes out of scope, so its information is lost

You could use a CHashMap or CList to add your order info instance to the global scope.

If you only have 1 open position at any time, you could just make COrderInfo global.


Solution #1: (one open position at any time)

COrderInfo MyOrder;

void OnTrade(void)
  {
   MyOrder.Select(my_result.order);
   ...
  }


Solution #2: (multiple positions/orders)

#include <Generic/HashMap.mqh>

CHashMap<ulong,COrderInfo*> MyOrders;

void OnTrade(void)
  {
   COrderInfo *info=new COrderInfo;
   info.Select(my_result.order);
   MyOrders.Add(my_result.order,info);
   ...
  }

void CheckOrder(ulong order)
  {
   COrderInfo *info;
   if(MyOrders.TryGetValue(order,info)) Print("order #",order," newproperty=",info.newproperty());
   else                                 Print("order #",order," not found");
  }
 

my case will be mutiple  >> And your response is great help, I will try next Sunday

If I use as global scope. I need to maintain  the life scope. I think this don't keep OO thinking andmaybe more trouble many warier message >.<.
I get confuse that we can get order by select(ID). I think it's mean there is one global in the system, if possibble to update this one as on trade or open operation

Not create an new COrderInfo  HashMap?

      m_order.PropertyChange(3);

       m_order.StoreState(); 

 
sungsungD:

my case will be mutiple  >> And your response is great help, I will try next Sunday

ok great

If I use as global scope. I need to maintain  the life scope. I think this don't keep OO thinking andmaybe more trouble many warier message >.<.
I get confuse that we can get order by select(ID). I think it's mean there is one global in the system, if possibble to update this one as on trade or open operation

Not create an new COrderInfo  HashMap?

Sorry, but I cannot understand you. I suggest to type your request in native language and use a translation tool.

COrderInfo.Select() reads information from the trade server/MT terminal cache. This is distinct from the global variable scope of an EA.

//+------------------------------------------------------------------+
//| Selecting an order to access                                     |
//+------------------------------------------------------------------+
bool COrderInfo::Select(void)
  {
   return(OrderSelect(m_ticket));
  }
 

I use method 2,the simple verify result Success!! (only try CHashMap add ,no delete >,<)


COrderInfo.Select() reads information from the trade server/MT terminal cache. This is distinct from the global variable scope of an EA.

<< COrderInfo.Select() reads information from the trade server/MT terminal cache. so lt's mean there will not a copy in client(our PC).

I think you already answer me. I get it.
Before you tell this, I thought client and server both will maintain one order list, and client will sync order request to trade server.
If we have DOC about how to read data from MT terminal cache.

And relative question is that if local not maintain a order list , some case ex server not response ... sever issue may not verify be client ?

Maybe like slip, the data you see (local order time,price)  --->> server( transaction time ,price)


 Before you post

I write xxEA
CTrade m_trade;

void OnTrade(void)
{
 COrderInfo m_order;
if ( OrderGetInteger(ORDER_STATE)==ORDER_STATE_PLACED)
     { 
       m_order.CheckState();  
       m_order.PropertyChange(3);
       m_order.StoreState(); >>>>>>>>>>>>>>>>>>>//store to Global (MT5 library maintain)

       .....
     }

}


Now

Local PC ---------<<<<<<<<<<<<<------------------------->>>>>>>>>>>>------ Brokers Server

 (local var)   Order            >> net buffer ? >>>>        Order   (each client get one order list)

 (Read from MT cache)    Result << net buffer   <<<<        execution  Result data


Data pass by 
    my_result << need pervert it overwrite by next tick. ?

data always sync from server and update as transaction send the result to client. 

MT5 App/ MT5 PC client has a loop always check the sever update new result.