- niqmadu: with my assumption that I would only need to check the most recent 100 orders in the order history as I might be able to compile enough small signals for that to not be enough. In this case neither signal trades over 100 times in the one year backtest, so I remain stumped.You assume that history is ordered.dabbler: Order History is nice in that it is there for free. It is unreliable in the sense that the order of entries is mysterious (by actual test)Could EA Really Live By Order_History Alone? (ubzen) - MQL4 forum
if(LastTime <= 0) LastTime = OrderOpenTime(); if(OrderOpenTime() > LastTime) LastTime = OrderOpenTime();
No need for the first line. No need for the if() on the second line, as you already did it as part of the if(OrderSelect.- In the history loop you need to filter out non-trades (deleted pending orders, credits and balance adjustments.)
int position = OrdersHistoryTotal()-1; if(position > 100) position = 100; //If more than 100 orders in the history then only check the most recent 100 for(pos = position; pos >= 0 ; pos--)
This code doesn't check the 100 most recent ([OHT-1 .. OHT-100],) it checks the oldest 101 ([100 .. 0].)
- niqmadu: with my assumption that I would only need to check the most recent 100 orders in the order history as I might be able to compile enough small signals for that to not be enough. In this case neither signal trades over 100 times in the one year backtest, so I remain stumped.You assume that history is ordered.dabbler: Order History is nice in that it is there for free. It is unreliable in the sense that the order of entries is mysterious (by actual test)Could EA Really Live By Order_History Alone? (ubzen) - MQL4 forum
- No need for the first line. No need for the if() on the second line, as you already did it as part of the if(OrderSelect.
- In the history loop you need to filter out non-trades (deleted pending orders, credits and balance adjustments.)
- This code doesn't check the 100 most recent ([OHT-1 .. OHT-100],) it checks the oldest 101 ([100 .. 0].)
WHR -- Thanks so much for the code review and thoughts, very clear and to the point. I will review and revise.
Kind regards,
N
WHR -- Thanks so much for the code review and thoughts, very clear and to the point. I will review and revise.
Kind regards,
N
I can see the very real problems with my assumption that order history is in any given order, and I had completely omitted the fact that all the ordermodify results from my adjustment of the trailing stops would be in there as well, which would blow the history past my expected threshold of 100 quite easily. Then there is the question of how long or short the order history might be set to be....
I think my preferred solution would be to simply write to a file for each magic number and track the last open time of the respective order. The only concern I can think of on initial review would be the latency of reading multiple files (albeit very short ones) in a single EA. My guess is that the operating system should be able to keep it in RAM and not have to seek to the hard drive in most cases, alleviating that issue.
If I am off base in my thought process I certainly would be grateful for the feedback,
Many thanks to all those who contribute to the forum,
N
and I had completely omitted the fact that all the ordermodify results from my adjustment of the trailing stops would be in there as well,
They are not stored in the order history

- 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,
Rather than try to find one home run trading strategy, I've opted to find a collection of high probability but low gain strategies, the collection of which would be attractive. I noticed different back test results when testing them singly and together several months ago, and parsed my code down to try and isolate the error assuming it was an error in my code.
Whether it is an error in my code (my thought) or a weakness of the backtester, it appears to be associated either with my use searching through the order history to find the last open time for a trade of a given magic number.
After some initial code my EA calls a sequence of individual trade signals.
At the beginning of each signal I check to see if enough time has elapsed since the last trade on that signal. If I comment out all but one signal call then I get what "appears" to be the expected behavior. If I uncomment one of the signals so it is called then the behavior changes--the expected delay between trades does not appear to be enforced and I can get multiple trades one after another as the preceding one closes out (I typically only allow one trade per signal in the same direction at the same time). I require a delay between trades so as to not trade on a stale signal if I am attempting to trade on the four hour chart with the trade executing at the start of a bar and closing very soon after, and to prevent multiple trades executing on a stale signal after a stopped out trade.
Here is the typical line of code that checks the delay.
Here is how the variable mode_DELAY is returned.
In this case the delay is expected to be PERIOD_H4 (or 240 minutes) * 60 seconds * 16 which as I understand it is 16 four hour bars or 64 hours.
The mode_DELAY variable is returned as a DOUBLE (without a decimal) that is passed as an INT to the function that checks the last open time. I check the time that the last trade of the relevant magic number was opened at the beginning of all the signals.
As I review the back test results it is as if when I add the second signal then there is no prior trade of the first signal's magic number found in the order/order history. I can see a potential gotcha with my assumption that I would only need to check the most recent 100 orders in the order history as I might be able to compile enough small signals for that to not be enough. In this case neither signal trades over 100 times in the one year backtest, so I remain stumped.
I've read that people have struggled some with TimeCurrent() in the back tester but I think the error is in my code in my search of the Order Histories..... I'm just not seeing it.
I do apologize for the longer question, but would be grateful for some assistance from those with keener eyes than mine,
Kind regards,
Nathan