Download MetaTrader 5

EA forget or lose my magic number

To add comments, please log in or register
akose
66
akose  

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
1399
SYED NAUFAL GADDAFI  

Your logic needs to be redone.

Hongliang Liu
1294
Hongliang Liu  

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
16550
whroeder1  
    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