Fixing and EA that works in strategy tester but not on live charts

 
Can anyone give me suggestions on how to fix an EA that works in strategy tester but only intermittently when attached to a live chart.  Autotrading is enabled and other EA's in the same account continue to make trades.  Strategy tester makes trades using the same price data and there are no errors in the journal.  It only ever worked properly for a brief period on a build 646 account.  Tested unsuccessfuly on a build 670 account. On occasion, the EA in question places a single order, instead of the multiple buy or sell signals it is supposed to.  In the the strategy tester it continues to do so.  Any suggestions on which settings to review/change would be appreciated.  Thanks.
 
i don't think someone can help without seeing the code
 

I haven't added include files yet so the code is gargantuan in size 

Please see below open trade section:

 

   if (((T1_Order == SIGNAL_BUY)||(T2_Order == SIGNAL_BUY2)||(T3_Order == SIGNAL_BUY3)||(T4_Order == SIGNAL_BUY4))  && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

       {


   if( T1_Enabled==1) {  
if (((T1_status==14)||(T1_status==12)||(T1_status==10))&&((T1_status!=11)&&(T1_status!=13))&&(Total<=cap)&&(T1_Order == SIGNAL_BUY)){
         Ticket = OrderSend(Symbol(), OP_BUY, T1_Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + T1_magic + ")", T1_magic, 0, DodgerBlue);
                     T1_IsTrade = True; 
                     
                              if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
               Total = OrdersTotal();
               T1_status = 11;
                                Print("BUY order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
                        } else {
                                Print("Error opening BUY order : ", GetLastError());
                        }
         }
         }
              }       
      if( T2_Enabled==1) {                    
if (((T2_status==24)||(T2_status==22)||(T2_status==20))&&((T2_status!=21)&&(T2_status!=23))&&(Total<=cap)&&(T2_Order == SIGNAL_BUY2)){
         Ticket = OrderSend(Symbol(), OP_BUY, T2_Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + T2_magic + ")", T2_magic, 0, DodgerBlue);
                     T2_IsTrade = True; 
                              if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
               Total = OrdersTotal();
               T2_status = 21;
                                Print("BUY order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
                        } else {
                                Print("Error opening BUY order : ", GetLastError());
                        }
         }
                     }                     
                     
}

   if( T3_Enabled==1) {  
if (((T3_status==34)||(T3_status==32)||(T3_status==30))&&((T3_status!=31)&&(T3_status!=33))&&(Total<=cap)&&(T3_Order == SIGNAL_BUY3)){
         Ticket = OrderSend(Symbol(), OP_BUY, T3_Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + T3_magic + ")", T3_magic, 0, DodgerBlue);
                     T3_IsTrade = True; 
                              if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
               Total = OrdersTotal();
               T3_status = 31;
                                Print("BUY order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
                        } else {
                                Print("Error opening BUY order : ", GetLastError());
                        }
         }
         }
              }       
      if( T4_Enabled==1) {                    
if (((T4_status==44)||(T4_status==42)||(T4_status==40))&&((T4_status!=41)&&(T4_status!=43))&&(Total<=cap)&&(T4_Order == SIGNAL_BUY4)){
         Ticket = OrderSend(Symbol(), OP_BUY, T4_Lots, Ask, Slippage, StopLossLevel, TakeProfitLevel, "Buy(#" + T4_magic + ")", T4_magic, 0, DodgerBlue);
                     T4_IsTrade = True; 
                              if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
               Total = OrdersTotal();
               T4_status = 41;
                                Print("BUY order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Open Buy");
                        } else {
                                Print("Error opening BUY order : ", GetLastError());
                        }
         }
                     }                     
                     
}

}
}

   if (((T1_Order == SIGNAL_SELL)||(T2_Order == SIGNAL_SELL2)||(T3_Order == SIGNAL_SELL3)||(T4_Order == SIGNAL_SELL4))  && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

       {

   if( T1_Enabled==1) { 
if (((T1_status==12)||(T1_status==14)||(T1_status==10))&&((T1_status!=11)&&(T1_status!=13))&&(Total<=cap)&&(T1_Order == SIGNAL_SELL)){
         Ticket = OrderSend(Symbol(), OP_SELL, T1_Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + T1_magic + ")", T1_magic, 0, DeepPink);
                     T1_IsTrade = True; 
                              if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
                           Total = OrdersTotal();
                           T1_status = 13;
                                Print("SELL order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
                        } else {
                                Print("Error opening SELL order : ", GetLastError());
                        }
         }
                     }
                     }
                 if( T2_Enabled==1) {        
if (((T2_status==22)||(T2_status==24)||(T2_status==20))&&((T2_status!=21)&&(T2_status!=23))&&(Total<=cap)&&(T2_Order == SIGNAL_SELL2)){
         Ticket = OrderSend(Symbol(), OP_SELL, T2_Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + T2_magic + ")", T2_magic, 0, DeepPink);
                     T2_IsTrade = True; 
                              if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
                           Total = OrdersTotal();
                           T2_status = 23;
                                Print("SELL order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
                        } else {
                                Print("Error opening SELL order : ", GetLastError());
                        }
         }
                     }                     
                     
   }
   
      if( T3_Enabled==1) { 
if (((T3_status==32)||(T3_status==34)||(T3_status==30))&&((T3_status!=31)&&(T3_status!=33))&&(Total<=cap)&&(T3_Order == SIGNAL_SELL3)){
         Ticket = OrderSend(Symbol(), OP_SELL, T3_Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + T3_magic + ")", T3_magic, 0, DeepPink);
                     T3_IsTrade = True; 
                              if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
                           Total = OrdersTotal();
                           T3_status = 33;
                                Print("SELL order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
                        } else {
                                Print("Error opening SELL order : ", GetLastError());
                        }
         }
                     }
                     }
                 if( T4_Enabled==1) {        
if (((T4_status==42)||(T4_status==44)||(T4_status==40))&&((T4_status!=41)&&(T4_status!=43))&&(Total<=cap)&&(T4_Order == SIGNAL_SELL4)){
         Ticket = OrderSend(Symbol(), OP_SELL, T4_Lots, Bid, Slippage, StopLossLevel, TakeProfitLevel, "Sell(#" + T4_magic + ")", T4_magic, 0, DeepPink);
                     T4_IsTrade = True; 
                              if(Ticket > 0) {
            if (OrderSelect(Ticket, SELECT_BY_TICKET, MODE_TRADES)) {
                           Total = OrdersTotal();
                           T4_status = 43;
                                Print("SELL order opened : ", OrderOpenPrice());
                if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Open Sell");
                        } else {
                                Print("Error opening SELL order : ", GetLastError());
                        }
         }
                     }                     
                     
   }

   
         if (EachTickMode) TickCheck = True;
         if (!EachTickMode) BarCount = Bars;
      }
   }

Please see below close trade section:

 

            for (int i = 0; i < Total; i ++) {

            //+------------------------------------------------------------------+

// closebuy and close sell arguments here!
                
            //+------------------------------------------------------------------+

   if(T1_Enabled==1) {  
            OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
            if(OrderType() == OP_BUY  && OrderMagicNumber() == T1_magic ) {
            

            if (((T1_status==11))&&(T1_Order == SIGNAL_CLOSEBUY) && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

                              OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
               T1_CB_TK = OrderTicket ();
               T1_OP = OrderProfit();
               CB_MN = OrderMagicNumber();
               T1_status = 12;
               T1_IsTrade = False;

               
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
               
               if (!EachTickMode) BarCount = Bars;

            }
            }
            }


            if(T2_Enabled==1) {  
             OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
             if(OrderType() == OP_BUY  && OrderMagicNumber() == T2_magic) {

            if ((T2_status==21)))&&(T2_Order == SIGNAL_CLOSEBUY2) && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

                              OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
               T2_CB_TK = OrderTicket ();
               T2_OP = OrderProfit();
               CB_MN = OrderMagicNumber();
               T2_status = 22;
               T2_IsTrade = False;
               
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
               if (!EachTickMode) BarCount = Bars;

            }           
            }
            }
          
          
        
   if(T3_Enabled==1) {  
            OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
            if(OrderType() == OP_BUY  && OrderMagicNumber() == T3_magic ) {
            

            if (((T3_status==31))&&(T3_Order == SIGNAL_CLOSEBUY3) && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

                              OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
               T3_CB_TK = OrderTicket ();
               T3_OP = OrderProfit();
               CB_MN = OrderMagicNumber();
               T3_status = 32;
               T3_IsTrade = False;

              
               
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
               
               if (!EachTickMode) BarCount = Bars;

               //continue;
            }
            }
            }


            if(T4_Enabled==1) {  
             OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
             if(OrderType() == OP_BUY  && OrderMagicNumber() == T4_magic) {

            if (((T4_status==41))&&(T4_Order == SIGNAL_CLOSEBUY4) && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

                              OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, MediumSeaGreen);
               T4_CB_TK = OrderTicket ();
               T4_OP = OrderProfit();
               CB_MN = OrderMagicNumber();
               T4_status = 42;
               T4_IsTrade = False;
               
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Bid, Digits) + " Close Buy");
               if (!EachTickMode) BarCount = Bars;

            }           
            }
            }          

            if(T1_Enabled==1) {  
             OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
             if(OrderType() == OP_SELL && OrderMagicNumber() == T1_magic) {
            if (((T1_status==13))&&(T1_Order == SIGNAL_CLOSESELL) && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
                              OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);

               T1_CB_TK = OrderTicket ();
               T1_OP = OrderProfit();
               CS_MN = OrderMagicNumber();
               T1_status = 14;
               T1_IsTrade = False;
               
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
               if (!EachTickMode) BarCount = Bars;

            }
            }
            }


  
            if(T2_Enabled==1) {  
             OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
                         if(OrderType() == OP_SELL && OrderMagicNumber() == T2_magic) {

                        if (((T2_status==23))&&(T2_Order == SIGNAL_CLOSESELL2) && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

                              OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);

               T2_CS_TK = OrderTicket ();
               T2_OP = OrderProfit();
               CS_MN = OrderMagicNumber();
               T2_status = 24;
               T2_IsTrade = False;
               
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
               if (!EachTickMode) BarCount = Bars;

            }
            }
            }
            
    

            if(T3_Enabled==1) {  
             OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
             if(OrderType() == OP_SELL && OrderMagicNumber() == T3_magic) {
            if (((T3_status==33))&&(T3_Order == SIGNAL_CLOSESELL3) && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {
                              OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);

               T3_CB_TK = OrderTicket ();
               T3_OP = OrderProfit();
               CS_MN = OrderMagicNumber();
               T3_status = 34;
               T3_IsTrade = False;
               
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
               if (!EachTickMode) BarCount = Bars;

            }
            }
            }


  
            if(T4_Enabled==1) {  
             OrderSelect(i, SELECT_BY_POS, MODE_TRADES);
                         if(OrderType() == OP_SELL && OrderMagicNumber() == T4_magic) {

                        if (((T4_status==43))&&(T4_Order == SIGNAL_CLOSESELL4) && ((EachTickMode && !TickCheck) || (!EachTickMode && (Bars != BarCount)))) {

                              OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, DarkOrange);

               T4_CS_TK = OrderTicket ();
               T4_OP = OrderProfit();
               CS_MN = OrderMagicNumber();
               T4_status = 44;
               T4_IsTrade = False;
               
               if (SignalMail) SendMail("[Signal Alert]", "[" + Symbol() + "] " + DoubleToStr(Ask, Digits) + " Close Sell");
               if (!EachTickMode) BarCount = Bars;

            }
            }
            }
         }

Not sure if that helps and as mentioned this seems to work locally but not on live charts 

Thanks 

 
Let me guess - EA builder.
  1. We hate EA builder
  2. You couldn't be bothered to learn mql4, therefor there is no common language for us to communicate.
  3. There are only two choices: learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem, but we are not going to debug your hundreds lines of code.
  4. EA builder makes bad code counting up while closing multiple orders.
  5. EA builder makes bad code Bars is unreliable (max bars on chart) volume is unreliable (miss ticks) Always use time
  6. EA builder makes bad code Not adjusting for 4/5 digit brokers
  7. EA builder makes bad code not adjusting for ECN brokers.
  8. EA builder makes bad code not checking return codes.
 
WHRoeder:
Let me guess - EA builder.
  1. We hate EA builder
  2. You couldn't be bothered to learn mql4, therefor there is no common language for us to communicate.
  3. There are only two choices: learn to code it, or pay someone. We're not going to code it FOR you. We are willing to HELP you when you post your attempt (using SRC) and the nature of your problem, but we are not going to debug your hundreds lines of code.
  4. EA builder makes bad code counting up while closing multiple orders.
  5. EA builder makes bad code Bars is unreliable (max bars on chart) volume is unreliable (miss ticks) Always use time
  6. EA builder makes bad code Not adjusting for 4/5 digit brokers
  7. EA builder makes bad code not adjusting for ECN brokers.
  8. EA builder makes bad code not checking return codes.

Thanks for your response, I didn't realise EA builder was so unpopular.  Believe it or not the above code is my attempt to learn, clearly not that well.  Apart from the MQL4 book and online documentation, which I have read more than once, are there any only methods of learning MQL4 that you would recommend?

FYI, I posted the code in response to the earlier contribution and didn't expect anything more than suggestions for possible causes.  Now I have that and am grateful for your diagnosis.