This is one of my functions I use ...
int cnt, total;
total = OrdersHistoryTotal();
for(cnt=0;cnt<total; cnt++){
if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY)==true)
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNo){
LastOrderType = OrderType();
LastOrderLots = OrderLots();
LastOrderProfit = OrderProfit();
}
}
}
If you tweak the last line of code slightly, you could easily get what you want.
Thanks a lot!
One question remains though: When I select an order via OrderSelect, can i be sure that the position with the highest index is always the last closed order (in case of MODE_HISTORY)? Or do i have to dig through all indices and sort out the latest with OrderCloseTime()?
Thanks a lot!
One question remains though: When I select an order via OrderSelect, can i be sure that the position with the highest index is always the last closed order (in case of MODE_HISTORY)? Or do i have to dig through all indices and sort out the latest with OrderCloseTime()?
It is probably best to sort them yourself. There is some anecdotal evidence suggesting the orders are not necessarily always sorted chronologically.
It is probably best to sort them yourself. There is some anecdotal evidence suggesting the orders are not necessarily always sorted chronologically.
I think it depends on how your broker sorts orders once they are closed, I believe it is chronological
I think it depends on how your broker sorts orders once they are closed, I believe it is chronological
Not always, it would seem:
https://www.mql5.com/en/forum/139121
It is probably best to sort them yourself. There is some anecdotal evidence suggesting the orders are not necessarily always sorted chronologically.
Anecdotal evidence ? It's documented.
Consecutive selection of orders using the SELECT_BY_POS parameter returns information in the sequence in which it was received from the trading server. Sorting of the resulting list of orders cannot be guaranteed.
- docs.mql4.com
This is one of my functions I use ...
int cnt, total;
total = OrdersHistoryTotal();
for(cnt=0;cnt<total; cnt++){
if(OrderSelect(cnt,SELECT_BY_POS,MODE_HISTORY)==true)
if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNo){
LastOrderType = OrderType();
LastOrderLots = OrderLots();
LastOrderProfit = OrderProfit();
}
}
}
If you tweak the last line of code slightly, you could easily get what you want.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey Guys
Is there a function for an EA that gets triggered when a profit target is hit for a certain position? I can't find one :(
Thanks for helping me out :)