EA will not run on multiple pairs, need help - page 3

 
for(int i=0;i<OrdersTotal();i++)
      {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
         if(OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol()) continue;
         //---Check Order Type
         if(OrderType()==OP_BUY)
         {
           if(fastma < slowma)
           {
             if(OrderClose(OrderTicket(),Lots,OrderClosePrice(),10,clrNONE))
               Print("Order Closed : ", OrderClosePrice());
             else
               Print("Error Closing order ", GetLastError());
              
           }
          
         }
      if(OrderType()==OP_SELL)
        {
          if(fastma > slowma)
          {
             if(OrderClose(OrderTicket(),Lots,OrderClosePrice(),10,clrNONE))
               Print("Order Closed : ", OrderClosePrice());
            else
               Print("Error Closing Order : ", GetLastError());
              
          }
          
        }
      }
    Sleep(300000);
    return(0);
}
My Ea wont stop opening and closing orders, it seems to be ignoring something in my code, is there anything wrong with my close order function
 
Matt_Townsend: is there anything wrong with my close order function

Yes - you must count down when closing orders: 

for(int i=OrdersTotal()-1; i>=0; i--)
You can read up why here
 
honest_knave:

Yes - you must count down when closing orders: 

for(int i=OrdersTotal()-1; i>=0; i--)
You can read up why here
It is still just opening up and closing trades almost immediately, is there anything else wrong with code? 
 
Matt_Townsend is there anything else wrong with code? 
Print out your variables, and find out why.
 
if(OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol()) continue;

Why would you continue ?

if(OrderMagicNumber()!=MagicNumber || OrderSymbol()!=Symbol()) continue;


would make more sense
 
Keith Watford:
if(OrderMagicNumber()==MagicNumber && OrderSymbol()==Symbol()) continue;

Why would you continue ?

if(OrderMagicNumber()!=MagicNumber || OrderSymbol()!=Symbol()) continue;


would make more sense
It doesnt close orders if the code has ||, but it does work better with the != in there
 
//+---------------------------------------------+
//|System start                                 |
//+---------------------------------------------+
int start()
{


    double fastma, slowma;
    int    ticket, total;
    //---define Ma's
    
    fastma = iMA(NULL,0,5,0,MODE_EMA,PRICE_CLOSE,0);
    slowma = iMA(NULL,0,8,0,MODE_SMA,PRICE_CLOSE,0);
    
    total = OrdersTotal();
    //---Start operations
    
    if(total < 1)
    {
       if(fastma > slowma)
        {
         ticket = OrderSend(Symbol(),OP_BUY,Lots,Ask,10,0,0,"",0,0,Blue);
         if(ticket > 0)
         {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
            Print("Buy order opened : ", OrderOpenPrice());
         }
         else
           Print("Error opening order : ", GetLastError());
           return(0);
       }
       if(fastma < slowma)
       {
         ticket = OrderSend(Symbol(),OP_SELL,Lots,Bid,10,0,0,"",0,0,Red);
         if(ticket > 0)
         {
            if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
            Print("Sell order opened : ", OrderOpenPrice());
         }
         else
           Print("Error opening order : ", GetLastError());
           return(0);
       }
       return(0);
    }
  
      
    for(int i=OrdersTotal()-1;i>=0;i--)
      {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
         if(OrderMagicNumber()!=MagicNumber && OrderSymbol()!=Symbol()) continue;
         //---Check Order Type
         if(OrderType()==OP_BUY)
         {
           if(fastma < slowma)
           {
             if(OrderClose(OrderTicket(),Lots,OrderClosePrice(),10,clrNONE))
               Print("Order Closed : ", OrderClosePrice());
             else
               Print("Error Closing order ", GetLastError());
           }
          
         }
      if(OrderType()==OP_SELL)
        {
          if(fastma > slowma)
          {
             if(OrderClose(OrderTicket(),Lots,OrderClosePrice(),10,clrNONE))
               Print("Order Closed : ", OrderClosePrice());
            else
               Print("Error Closing Order : ", GetLastError());
          }
          
        }
      }
    Sleep(300000);
    return(0);
}
Here is my code as it stands now, it can open trades on whatever pair I set it on, but randomly has certain ones with open trades. I've been trying to get the code to essentially run independently on whatever pair I put it on, but unfortunately the code will not open any trades until all other trades are closed, and then doesn't open up trades on all the pairs that it is set on. Is there anyway to have the program do that, It does buy and sell the way I want it to.
 
You code
  for(int i=OrdersTotal()-1;i>=0;i--)
      {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
         if(OrderMagicNumber()!=MagicNumber || OrderSymbol()!=Symbol()) continue;
         //---Check Order Type
         if(OrderType()==OP_BUY)
Simplified
  for(int i=OrdersTotal()-1;i>=0;i--) if(
     OrderSelect(i,SELECT_BY_POS)
  && OrderMagicNumber() == MagicNumber
  && OrderSymbol()      == Symbol()
  ){
     //---Check Order Type
     if(OrderType()==OP_BUY)
 
whroeder1:
You code
  for(int i=OrdersTotal()-1;i>=0;i--)
      {
         if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false) break;
         if(OrderMagicNumber()!=MagicNumber && OrderSymbol()!=Symbol()) continue;
         //---Check Order Type
         if(OrderType()==OP_BUY)
Simplified
  for(int i=OrdersTotal()-1;i>=0;i--) if(
     OrderSelect(i,SELECT_BY_POS)
  && OrderMagicNumber() == MagicNumber
  && OrderSymbol()      == Symbol()
  ){
     //---Check Order Type
     if(OrderType()==OP_BUY)

Each chart is still not running independently, is there anything else I can do?

And the way that is coded, it no longer closes trades. 

 
Keith Watford 2016.12.14 03:10 | 122.155.43.228 ban   EN

    total = OrdersTotal();
    //---Start operations
    
    if(total <= 1)
loop through the open orders and only count trades that have the EA's magic number and chart symbol