Download MetaTrader 5

OrderHistoryTotal()-Results on a new account ?

To add comments, please log in or register
Freelance service: the safe way to order a trading robot. Try it!
Carl Schreiber
6588
Carl Schreiber 2014.09.05 08:09 

Hi,

The Doc. of mt4 tells me:

int  OrdersHistoryTotal();

  Returned value:
    The number of closed orders in the account history loaded into the terminal.
    The history list size depends on the current settings of the "Account history" tab of the terminal.

But if there is a new account there won't be any orders (closed or open) just the deposit is booked.

On the other hand if an EA is started e.g. by an automatic restart of the terminal after a crash of what ever its functions OnTick() and OnInit() are started while the parameters aren't loaded like MarketInfo(Symbol(),MODE_TICKVALUE) - which is of course not desirable. :(

I found that if I wait by:

if ( OrdersHistoryTotal() <= 0 ) return;

I can be sure that all parameters are loaded - but a new account has not orders?

But may be the initial money deposit is counted as 'closed order' - is that true?

GreenMoney
379
GreenMoney 2014.09.05 12:53  
I believe (at least in b509 and earlier) that balance and credit entries are counted in OrdersHistoryTotal().  See this link.
whroeder1
14509
whroeder1 2014.09.05 13:58  
Somewhere in the docs it says
It is not recommended to store important market characteristics in the function init(), it is better to request market conditions in a place of use and it is obligatory to check them on empty/zero values. Otherwise, an attempt of starting a script on inactive accounts may result in receiving the wrong values.

Do not use MarketInfo/OrdersHistoryTotal in init because the parameters/values may not yet be loaded. Wait for start/OnTick.

Carl Schreiber
6588
Carl Schreiber 2014.09.05 18:43  
WHRoeder:
Somewhere in the docs it says

Do not use MarketInfo/OrdersHistoryTotal in init because the parameters/values may not yet be loaded. Wait for start/OnTick.


Yes I know that - but it's a very stupid situation: Don't use OnInit() as is may not initialize all.

But even in OnTick/start you have to do:


bool INI = false:
...
void OnTick(){
   if ( !INI ) {
       if ( OrdersHistoryTotal() <=0 ) return;
       INI = true;
   }
}

and that mean you have to write different code for debugging and the strategy-tester.

To add comments, please log in or register