OrderSelect(f,SELECT_BY_POS,MODE_HISTORY); if(OrderType()==0)ordertyp="BUY";
At that point, f is the count of all history orders for that pair. If you only have that pair, f-1 is the position last one. If you have other pairs then f or f-1 is meaningless as a position, so the select fails, you don't check for it, and send garbage.datetime lastClose; int init(){ for(int pos=0; pos < OrdersHistoryTotal(); pos++) if ( OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY) // Only orders w/ && OrderCloseTime() > lastClose // not yet processed, && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() // and my pair. && OrderType() <= OP_SELL){// Avoid cr/bal https://www.mql5.com/en/forum/126192 lastClose = OrderCloseTime(); } } int start(){ for(int pos=0; pos < OrdersHistoryTotal(); pos++) if ( OrderSelect(pos, SELECT_BY_POS, MODE_HISTORY) // Only orders w/ && OrderCloseTime() > lastClose // not yet processed, && OrderMagicNumber() == magic.number // my magic number && OrderSymbol() == Symbol() // and my pair. && OrderType() <= OP_SELL){// Avoid cr/bal https://www.mql5.com/en/forum/126192 lastClose = OrderCloseTime(); send }
Thank you very much. It works perfectly!
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
I'm trying to use this code someone else published to automate e-mails to myself with order data after a SL or TP is hit.
However, when I get the e-mail, it looks like this...
EURUSD OpenTime: 1970.01.01 00:00 Close Time: 1970.01.01 00:00 Order Type BUY Open 0.0000 Close 0.0000 Profit (0.0000)
Can anyone see why this code isn't pulling the order information?