Download MetaTrader 5
To add comments, please log in or register
Having a great idea? Share it on the traders' Forum!
akose
66
akose 2014.09.01 22:34 

Hello friends

I want my EA ,

that I have set my magic number, if you call the same magic number is equal to the don't opening of new orders, but sometimes get lost magic number.

Thanks for yours answer.

for(int pos= OrdersTotal()-1; pos>=0; pos--)
   {
    OrderSelect(pos,SELECT_BY_POS,MODE_TRADES);
    magicnumber = OrderMagicNumber();  int profit = OrderProfit();   type = OrderType();   orderticket = OrderTicket();
   
        if(type == OP_SELL  &&  profit < hedge &&   magic !=  magicnumber )    <---------
          {   
            for(int a =0; a<total;a++) 
               {
                if(orderticketarray[a] == orderticket ) eticket = 1; 
                } 
      
                 if(eticket == 0)
                   {   
                    orderticketarray[sayac]= orderticket;  counter ++;                                  
                   
      --------->     if(magicnumber != magic ) { OrderSend(Symbol(),OP_BUY,Lot,Ask,3,0,0,"sell zarar al Al",magic,0,Green);}
                    }
                   
               
      
          
          }
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.09.02 04:28  

Your logic needs to be redone.

Hongliang Liu
1196
Hongliang Liu 2014.09.02 06:44  

more code needed for debug.

if(magicnumber != magic ) { OrderSend(Symbol(),OP_BUY,Lot,Ask,3,0,0,"sell zarar al Al",magic,0,Green);}

 if clause is no need because of the following judgement

if(type == OP_SELL  &&  profit < hedge &&   magic !=  magicnumber )
whroeder1
13644
whroeder1 2014.09.02 12:17  
    OrderSelect(pos,SELECT_BY_POS,MODE_TRADES);
    magicnumber = OrderMagicNumber(); ...
What happens when there is NO open orders and OrderSelect FAILS? Check your return codes (OrderSelect) What are Function return values ? How do I use them ? - MQL4 forum and Common Errors in MQL4 Programs and How to Avoid Them - MQL4 Articles
/
To add comments, please log in or register