Reputation: 137
could you please help me.
1) Is it better to keep orders in the EA's arrays rather than querying the system with the Order.. commands in mql4? Keeping data in arrays means that you have to query the system less and that internet reliability may be less of an issue. However, the coding required to keep an accurate order book is quite cumbersome.
2) How do you keep track of orders that is on the same Symbol but has come from two different EA's?
Thank you very much
Upvotes: 0
Views: 859
Reputation: 4681
It depends on your needs and ideas, without that it could be quite difficult to tell anything.
you can keep an array of ticket numbers (or CArrayObj
) but need to check that ticket exists before doing other operations (like trail). if you have problems with internet - change vps and do not try to solve it with coding.
Each ea keeps a book of its own deals.
Cannot imagine sence of keeping just numbers of tickets, but maybe it exists. If you need to store some data in addition to what can be achieved from Order...() then use classes or structures, some fields might be filled with osl,tp,oop,lot,magic, symbol etc once and do not call Order.() functions later except OrderProfit(),OrderClosePrice() and OrderCloseTime()
-such functions would be called all the time.
Example of how to store data is below: instances of CTrade are added to CArrayObj
#include <Object.mqh>
#include <Arrays\ArrayObj.mqh>
class CTrade : public CObject
{
private:
int m_ticketId;
double m_oop,m_osl,m_otp,m_lot;//OrderOpenPrice() and sl, tp, lot-add more
public:
CTrade(const int ticket){
m_ticketId=ticket;
}
bool isTicketExist(){
if(OrderSelect(m_ticketId,SELECT_BY_TICKET))
return(OrderCloseTime()==0);
else return(false);//or GetLastError()!=4108
}
};
CArrayObj* listOfTrades=NULL;
int OnInit(void){
listOfTrades=new CArrayObj;
}
void OnDeinit(const int reason){
if(CheckPointer(listOfTrades)==POINTER_DYNAMIC)
delete(listOfTrades);
}
void OnTick(){
for(int i=listOfTrades.Total()-1;i>=0;i--){
CTrade *trade=listOfTrades.At(i);
if(!trade.isTicketExist())
{listOfTrades.Delete(i);continue;}
//do trail or what you need
} // - loop over the array when necessary but clean it first
}
listOfTrades.Add(new CTrade(ticket));// - way to add elements to the list
Upvotes: 2