Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
They do work in the MT4 Strategy Tester. You must be doing something incorrectly in your code.
However, since you have not provided any sample code nor any other details, there is nothing more that can be stated.
Please refer to the Documentation, or the examples in the CodeBase or in Articles for more information.
Apologies for posting in the wrong section.
int OnInit(){ Print("OrdersHistoryTotal :", OrdersHistoryTotal()); return(INIT_SUCCEEDED); }
This code will Print 72 when it's attached as an EA.
When run under strategy tester, it will Print 0.
I'm guessing this is because it's looking for closed orders during the strategy testing session, which is not what I'm looking for.
int testvar = 0; int OnInit() { if(FileIsExist("test.ini")){ getData(); } Comment("testvar :", testvar); return(INIT_SUCCEEDED); } void getData() { int handle=FileOpen("test.ini",FILE_READ|FILE_CSV); if(handle==INVALID_HANDLE) {Print("invalid handle");return;} else{ testvar = (int)FileReadNumber(handle); } // I have the number 142 saved in the ini file.
This code will comment "142" when run as an EA. It will comment "0" when run through strategy tester.
What I'm trying to do is load my trade history into an array so I can plot the trades I took via strategy tester by connecting my trade open and close times and prices with trendlines.
Any guidance is appreciated.
That is absolutely correct. Why would you expect anything else except "0" for the OrdersHistoryTotal() at the beginning of the test?
Remember that the trade functions report on the trades made in the Strategy Tester environment, not on the live account environment!
Files written and read during a back-test are in a different folder to that of the live EAs being run.
"The file is opened in the folder of the client terminal in the subfolder MQL4\files (or Tester\Files in case of testing)."
I see. I found a post on this forum claiming they were accessing closed orders on account using OrderSelect() while backtesting.
https://www.mql5.com/en/forum/124193
Is this possible?
After placing the file in the right directory, it's working as intended now. Thank you sir.
![Accesing to order history in backtest Accesing to order history in backtest](https://c.mql5.com/36/80/accesing-to-order-history-in-backte.jpg)
- 2010.02.26
- www.mql5.com
You are misunderstanding the answers given on that topic. The trade functions when used in an EA being tested, always return information about the test environment, not the live environment.
EDIT: Please note, that when testing an Indicator instead of an EA, then things work differently as it accesses the "live" trade data instead.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
OrdersHistoryTotal() and OrderSelect() doesn't work for strategy tester.
Saving to CSV and Reading from CSV doesn't work for strategy tester.
Is what I'm trying to do possible for MT4? Any guidance is appreciated.