OrderSelect(xx, SELECT_BY_POS, MODE_TRADES); --> looks at open trades only
OrderSelect(xx, SELECT_BY_POS, MODE_HISTORY); --> looks already closed trades only
if you have a stop-loss signal then you should go through all opened positions and find the one which has magic number & all other stuff you need to identify the trade. and then close it.
if you have only one trade at time use OrdersTotal() function. If it's zero then you don't have any opened position. if you use more symbols or more ea-s at the same time then put a small code in front of your ea to find out how many opened trades you have. like:
Hope it helps!
zolero
OrderSelect(xx, SELECT_BY_POS, MODE_HISTORY); --> looks already closed trades only
if you have a stop-loss signal then you should go through all opened positions and find the one which has magic number & all other stuff you need to identify the trade. and then close it.
if you have only one trade at time use OrdersTotal() function. If it's zero then you don't have any opened position. if you use more symbols or more ea-s at the same time then put a small code in front of your ea to find out how many opened trades you have. like:
n=0; pkk=OrdersTotal(); while(pkk>=0) { OrderSelect(pkk, SELECT_BY_POS, MODE_TRADES); if(OrderSymbol()==Symbol()) { if(OrderMagicNumber()==magic) { n++; } } pkk--; }if n>0 you have something... if n=0 your ea could open another trade.
Hope it helps!
zolero

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
(when going through the trades, it finds the old trade and thinks it is still in one)