Need help with multiple trade entries.

 
I need help with the following. I can give an idea of how the flow of the program should go, but cannot get the code working.

Check currency to make sure that I can trade multiple currencies.
Check if the current candle has not changed.
If not changed, return 0
if changed, check for open trades and pending orders.
Close all pending orders and open trades.

Start with trade entry.
Enter buystop, then enter sellstop.
Check for pending orders to confirm.
Check for trailing stop and if applicable, ordermodify.

I tried to code this, but can only get the one pending order to enter, it does not enter the second pending order. I can also not get the coding done for the checking of the current candle, for it to close all trades if the candle changes, and then enter new pending orders.
 
Nobody can help you without a code of EA.
 
Rosh:
Nobody can help you without a code of EA.


Sorry, here is the code.



 
//---- input parameters
extern double TakeProfit = 300;
extern double StopLoss = 0;
extern double Lots = 0;
extern double TrailingStop = 40;
 
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   return(0);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
 
 
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
 
 
int start()
  
  {
  Lots=MathFloor(AccountBalance()/1000);
  if (Lots>50)
  Lots=50;
  else
  Lots=Lots;
 
    int cnt, ticket, total,expire;
    double Stop1, Ask1, Stop2, Bid1;
//----
    if(Bars < 100)
      {
        Print("bars less than 100");
        return(0); 
      }
//----
    if(TakeProfit < 10)
      {
        Print("TakeProfit less than 10");
        return(0); 
      }
//----
    Stop1 = (iHigh(NULL,0,1));
    Ask1 = (iHigh(NULL,0,1));
    Bid1 = (iLow(NULL,0,1));
   
   datetime barTime =Time[0];
   {
   if( barTime < Time[0] )
    {
        // we have a new bar opened
        barTime = Time[0]; // keep the new bar open time
    }
    }
   
//----
    total  = OrdersTotal();
    if(total < 1)
      {
       
       if (barTime == Time[0])
       {
       if (ticket != 1)
     
          {
           ticket = OrderSend(Symbol(), OP_BUYSTOP, Lots, Ask1, 3, Ask - 60*Point,
                              Ask + TakeProfit*Point, "Trading_the_candle", 12345, 0 , Green);
            if(OrderSelect(ticket, SELECT_BY_TICKET, MODE_TRADES))
            if(ticket < 2)
             {
               //if (OrderType() == OP_BUYSTOP)
           ticket = OrderSend(Symbol(), OP_SELLSTOP, Lots, Bid1, 3, Bid + 60*Point,
                              Bid - TakeProfit*Point, "Trading_the_candle", 12345, 0 , Red);
              }
            else
                Print("Error opening BUY order : ", GetLastError());
            return(0);
          }
        }
        }}
//---
    for(cnt = 0; cnt < total; cnt++)
      {
        OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
        if(OrderType() <= OP_SELL && OrderSymbol() == Symbol())
          {
            if(OrderType() == OP_BUY)  
              {
               
                if(TrailingStop > 0) 
                  {                
                    if(Bid - OrderOpenPrice() > Point*TrailingStop)
                      {
                        if(OrderStopLoss() < Bid - Point*TrailingStop)
                          {
                            OrderModify(OrderTicket(), OrderOpenPrice(),
                                        Bid - Point*TrailingStop,
                                        OrderTakeProfit(), 0, Green);
                            return(0);
                          }
                      }
                  }
              }
            else
              {
               
                if(TrailingStop > 0) 
                  {                
                    if((OrderOpenPrice() - Ask) > (Point*TrailingStop))
                      {
                        if((OrderStopLoss() > (Ask + Point*TrailingStop)) ||
                           (OrderStopLoss() == 0))
                          {
                            OrderModify(OrderTicket(), OrderOpenPrice(),
                                        Ask + Point*TrailingStop,
                                        OrderTakeProfit(), 0, Red);
                            return(0);
                          }
                      }
                  }
              }
          }
      }
//----
    return(0);
  }
//+------------------------------------------------------------------+
Reason: