Hello,
I'm trying to get the deals closed in profit within the previous 12 hours.
Output
As you can see from the output, only one deal is properly selected with HistoryDealSelect(tk), and that's because HistoryDealGetTicket(i) returns the proper ticket only the first time, returning 0 afterwards(I checked, but didn't include that in the output).
Deals at indexes 3 and 1 should also output their TP. Any ideas?
Forum on trading, automated trading systems and testing trading strategies
[MQL5] Getting history deals closed in profit
Chris Sthojan, 2019.05.23 09:19
if (HistorySelect(TimeCurrent()-(12*60*60), TimeCurrent())) { Print("Found ",HistoryDealsTotal()," deals."); for (int i = HistoryDealsTotal() - 1; i >= 0; i--) { ulong tk = HistoryDealGetTicket(i); Print("Checking deal at index: ",i," ",HistoryDealSelect(tk)); if(HistoryDealGetInteger(tk, DEAL_REASON) == DEAL_REASON_TP) { Print(HistoryDealGetString(tk,DEAL_COMMENT)); } } }
Oh, I didn't need to do HistoryDealSelect(tk)? But why though? Anyways, it works alright now, thanks!
Oh, I didn't need to do HistoryDealSelect(tk)? But why though? Anyways, it works alright now, thanks!
Reason stated in here: " HistoryDealSelect() clears in a mql5-program the list of deals available for reference, and copies the single deal, if the execution of HistoryDealSelect() has been completed successfully. If you need to go through all deals selected by the HistorySelect()function, you should better use HistoryDealGetTicket()."
https://www.mql5.com/en/docs/trading/historydealselect- www.mql5.com
Reason stated in here: " HistoryDealSelect() clears in a mql5-program the list of deals available for reference, and copies the single deal, if the execution of HistoryDealSelect() has been completed successfully. If you need to go through all deals selected by the HistorySelect()function, you should better use HistoryDealGetTicket()."
https://www.mql5.com/en/docs/trading/historydealselectI see, that makes sense. Thanks!
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello,
I'm trying to get the deals closed in profit within the previous 12 hours.
Output
As you can see from the output, only one deal is properly selected with HistoryDealSelect(tk), and that's because HistoryDealGetTicket(i) returns the proper ticket only the first time, returning 0 afterwards(I checked, but didn't include that in the output).
Deals at indexes 3 and 1 should also output their TP. Any ideas?