nidalzd:
Im creating an expert advisor that calculates stats of each magic number in Orderhistory() and printing them , the EA is working well on a small account with less that 30 magic numbers in order history .
however i tried this EA on an account with more than 100 magic numbers in OrderHistory() and a lot of trades and the calculations are not executed successfully , its printing 0 .
i will share my code down below
Im creating an expert advisor that calculates stats of each magic number in Orderhistory() and printing them , the EA is working well on a small account with less that 30 magic numbers in order history .
however i tried this EA on an account with more than 100 magic numbers in OrderHistory() and a lot of trades and the calculations are not executed successfully , its printing 0 .
i will share my code down below
I guess the issue is with the way you process and store your data.
Create a structure for the data you want to >accumulate<, representing your statistical analysis.
Use a hash map (std_lib has one) based on your magic numbers, and create a hash map containing these structures.
Now go through history >once< and store/accumulate your data for each entry in the structure. Get the structure by the magic number from the history entry, access the hash map with it.
This will make your loops much shorter in runtime. Currently you have exponential runtime. Doing it described way will reduce it to 2 times.
Result is the same, but runtime is much shorter.
Addendum:
Kill the timer once invoked, set it again before leaving the function.
This helps with extensive calls and runtime overlappings.
EDIT:
You can even break it down to one pass on all history data. And on subsequent calls, you can do incremental updates.
If you do it properly, this can be very efficient organized.
You need to understand how hash maps work.
Alternatively you could also use a red black tree to do it. But I would guess a hash map should be sufficient, as you won't be frequently adding new magic numbers, but only in the initial run.
nidalzd:
// Loop through the last two trades with the same magic number for(int j = s - 1; j >= s - PFperiod && j >= 0; j--)
// Loop through the last two trades with the same magic number for(int j = s - 1; j >= s - PFperiod && j >= 0; j--)
Beside the performance issue as noted by Dominik, you have a logical bug here :
// Loop through the last two trades with the same magic number for(int j = s - 1; j >= s - PFperiod && j >= 0; j--)

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
however i tried this EA on an account with more than 100 magic numbers in OrderHistory() and a lot of trades and the calculations are not executed successfully , its printing 0 .
i will share my code down below