I've got an Oanda account (forced upgrade to v20 :-/) and your code works fine on my end.
I tried it on both an EA and a Script.
All I did was place your code that's inside
int start {}
to the OnInit() function for the EA (it's the weekend so OnTick() doesn't work) and, for the Script, inside the OnStart() function.
It didn't work in the Strategy Tester and I'm guessing (can't recall, just got back into MQL) that it's because it has to be placed inside the OnTester() function of the EA.
Hi,before call OrdersHistoryTotal you need to load the orders to memory using the method HistoryOrderSelect.
- www.mql5.com
Hi,before call OrdersHistoryTotal you need to load the orders to memory using the method HistoryOrderSelect.
I think that you will find that the OP's code is mql4
I think that you will find that the OP's code is mql4
Thanks Alexander, I'll use what you've given me here and go from there. I'm also just getting back into it - it's mostly like riding a bike, but some of the finer points still obviously elude me!
Apologies Bilal and Keith for my rookie mistake.
Lee
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi All,
I've spent the better part of a day trying to do something I thought would be extremely simple - getting my account's closed trades using a very basic EA snippet. I've made sure all of my account history is showing on the 'Account History' tab, my broker is Oanda and my account was recently migrated to the v-20 servers.
This is what is returned in the Journal after running the EA. The tester log gives the same information:
**********************************************************************************************************************************************************************
2018.12.02 18:36:42.648 EURUSD-4,H1: 529 tick events (1504 bars, 2032 bar states) processed in 0:00:00.000 (total time 0:00:00.000)
2018.12.02 18:36:42.648 2018.11.01 00:00:00 ORDER HISTORY test started
2018.12.02 18:36:42.648 TestGenerator: spread set to 13
**********************************************************************************************************************************************************************
**********************************************************************************************************************************************************************
int start()
{
int orderPos;
// GET CLOSED TRADES
for (orderPos = 0; orderPos < OrdersHistoryTotal(); orderPos++)
{
if(OrderSelect(orderPos, SELECT_BY_POS, MODE_HISTORY))
{
OrderPrint();
}
}
return(0);
}
*************************************************************************************************************************************************************************
Thanks again for any help.