MQL4 - automated forex trading   /  

Forum

Expert Advisor and last trade.

Back to topics list To post a new topic, please log in or register

avatar
120
oldman 2006.08.24 14:47 
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)
Sound Alerts in Indicators

Sound Alerts in Indicators

How to create "voice" indicators for daily usage.


avatar
43
zolero 2006.08.25 04:08 
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

Back to topics list  

To add comments, please log in or register