Expert Advisor and last trade.

 
I have my expert advisor designed to only trade once.. but others can, by looking at the magic number of that ea's trade, well it seems that when it trades, the trade is not wipped out when it gets stop lossed out and will not enter another trade until i reset it manually. Is the trade supposed to remain in the cache like that?
(when going through the trades, it finds the old trade and thinks it is still in one)
 
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:
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
Reason: