Basic question about MT4 and forex servers

 

I want to be sure I understand how MT4 handles the forex servers.

I’ve been working with the assumption that there are market data servers which tick the EA and a broker server which I need to query separately for account information. I started cleaning up an EA to stop it from checking OrdersTotal() every tick, thinking that reduces server queries and lightens my communication load. But maybe this is not the case?

So my question is: Does each tick download account, as well as market, info? Is a check of OrdersTotal() for example, a local, and not a remote, check?



Thanks for your help.

 
LouK: So my question is: Does each tick download account, as well as market, info? Is a check of OrdersTotal() for example, a local, and not a remote, check?
  1. Connection established Account history and current orders list sent
  2. Chart is opened, history refresh is requested. This is why after a disconnect/connect IndicatorCounted returns nonzero for a few ticks and then zero. History refresh arrives.
  3. Market change, update is sent and OnTick is called if not active.
  4. Order status changes, update is sent. OrdersTotal() is local but may change while in OnTick. This is why you must count down when: Loops and Closing or Deleting Orders - MQL4 forum
 
WHRoeder:
  1. Connection established Account history and current orders list sent
  2. Chart is opened, history refresh is requested. This is why after a disconnect/connect IndicatorCounted returns nonzero for a few ticks and then zero. History refresh arrives.
  3. Market change, update is sent and OnTick is called if not active.
  4. Order status changes, update is sent. OrdersTotal() is local but may change while in OnTick. This is why you must count down when: Loops and Closing or Deleting Orders - MQL4 forum


Thanks for the help!

I understand that the value of OrdersTotal() can change intra tick. I just want to be clear about #4:

Then a line like "int numTickets=OrdersTotal();" DOES NOT constitute an additional server query, it just retrieves the value of a local variable "OrdersTotal()", which was refreshed to the value which existed at the instant of the tick, correct?

Thanks again!

 
OrdersTotal() value doesn't change if there is no change in trade orders.
 
LouK: retrieves the value of a local variable "OrdersTotal()", which was refreshed to the value which existed at the instant of the tick, correct?

It retrieves the last value saved from the last update received. If an update is received while your OnTick is busy (server calls takes time seconds/minutes) the value changes between calls.

It is not the value at the beginning of the tick, it is the current value.

Reason: