Good morning,
I am building a function to know if the last closed deal by an expert advisor was profitable. So I am iterating deals until finding one that matches the magic number, type and deal comment desired. However, I am having trouble using the HistorySelect() function, as I don't want to use any start/end date (I don't know if the last trade was recent or not). This is what I have so far.
I am pretty sure there is an easier way to do this. Could you please point me in the right direction?
Thanks in advance!
Of course if you select from 0 to 0, you don't get nothing. You have to select from 0 to current date, then loop from last to first and break (or return) when you have found your last winning deal. Let me know if you need more details.
As a side note, entry_type can also be DEAL_ENTRY_INOUT. Unless you are sure your EA don't use reversing of position.
Of course if you select from 0 to 0, you don't get nothing. You have to select from 0 to current date.
Hi Angevoyageur,
Selecting all history is something I wanted to avoid as it seems memory consuming, I thought there could be an easier way, perhaps picking the last position alltogether.
Thanks for pointing me in the right direction ;)
Hi Angevoyageur,
selecting all history is something I wanted to avoid as it seems memory consuming, I thought there could be an easier way.
Thanks for pointing me in the right direction ;)
Of course it's time consuming, but you have to do it at least 1 time. Don't do this at each tick of course.
Once you have your last winning deal, you also have a date to start your search. You can also use OnTrade or OnTradeTransaction to check your deals "on the fly".
angevoyageur:
You can also use OnTrade or OnTradeTransaction to check your deals "on the fly".
I know it's too late to comment but i'm commenting anyways for people who're coming in future just like I came now
There is a little mistake in
for (int i = 0; i < l_deals; i++)
It should be
for (int i = 0; i < l_deals-1; i++)
l_deals-1 as i starts from 0 and deals = history orders :)
Thanks
BTW your code helped me a lot
I know it's too late to comment but i'm commenting anyways for people who're coming in future just like I came now
There is a little mistake in
for (int i = 0; i < l_deals; i++)
It should be
for (int i = 0; i < l_deals-1; i++)
l_deals-1 as i starts from 0 and deals = history orders :)
Thanks
BTW your code helped me a lot
Amine, thank you for you answer this solved another code that was breaking my head... lol the tip with "-1" as very useful
sometime others prefere using from top to down :
Amine, thank you for you answer this solved another code that was breaking my head... lol the tip with "-1" as very useful
for (int i = 0; i < l_deals; i++)
or
for (int i = 0; i =< (l_deals-1); i++)
(upper one is prettier :P)
or
(upper one is prettier :P)
<=
;-)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Good morning,
I am building a function to know if the last closed deal by an expert advisor was profitable. So I am iterating deals until finding one that matches the magic number, type and deal comment desired. However, I am having trouble using the HistorySelect() function, as I don't want to use any start/end date (I don't know if the last trade was recent or not). This is what I have so far.
I am pretty sure there is an easier way to do this. Could you please point me in the right direction?
Thanks in advance!