programming question

 

Hi all!

My EA only takes Buy OR Sell and not both buy AND Sell at the same time.

I need it to take at the same time.

This is the code for the START order, how do I change it to take both buy and sell? Thanks!! 

 

int start() {

  

   if(!IsTesting() && AccountNumber() != AccountNum)

      return(0);

   if(timeprev == Time[0]){

      if (Smart){

         total = CountTrades();

         if(total > 0) return(0);

      }

      else    

         return(0);

   }  

   

   timeprev = Time[0];

   

   init_market_info();

   if (total == 0) flag = FALSE;

   for (cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {

      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

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

      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {

         if (OrderType() == OP_BUY) {

            LongTrade = TRUE;

            ShortTrade = FALSE;

            break;

         }

      }

      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {

         if (OrderType() == OP_SELL) {

            LongTrade = FALSE;

            ShortTrade = TRUE;

            break;

         }

      } 

 
nivam:

Hi all!

My EA only takes Buy OR Sell and not both buy AND Sell at the same time.

I need it to take at the same time.

This is the code for the START order, how do I change it to take both buy and sell? Thanks!! 

 

int start() {

  

   if(!IsTesting() && AccountNumber() != AccountNum)

      return(0);

   if(timeprev == Time[0]){

      if (Smart){

         total = CountTrades();

         if(total > 0) return(0);

      }

      else    

         return(0);

   }  

   

   timeprev = Time[0];

   

   init_market_info();

   if (total == 0) flag = FALSE;

   for (cnt = OrdersTotal() - 1; cnt >= 0; cnt--) {

      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);

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

      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {

         if (OrderType() == OP_BUY) {

            LongTrade = TRUE;

            ShortTrade = FALSE;

            break;

         }

      }

      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {

         if (OrderType() == OP_SELL) {

            LongTrade = FALSE;

            ShortTrade = TRUE;

            break;

         }

      } 

break will exit loop, so only one order will be checked. Try using continue
Reason: