Open order if price goes up or down

 

Hi all,

I'm looking to open orders every time bid increase or decrease.

Issue; If price starts to go in sell direction sell orders are opening, but if starts to bounce back no orders (buy) are opening. 

Do I need to have a code to open opposite orders or is a way to do that around the present code ?

 

extern double PriceStep            =   10.0;
double price = 0;

 jijij

//Buy Order Condition to Open
    
             
   if(price == 0)
     {
      price = Bid;
     }
   else
   if((Bid - price)/Point >= PriceStep)  
     {//5       
                 RefreshRates();                               
       BuyTicket = OrderSend(Symbol(),OP_BUY,InitialLots,Ask,Slippage*pips2points,0,0,"Initial Buy Order",MagicNumber,0,Green);
       price = Bid;
       if(BuyTicket > -1)     
        {//6         
          Print(" Initial Buy Order Placed - BuyTicket: ",BuyTicket," Open Buy Price: ",DoubleToStr(OrderOpenPrice(),Digits)," Spread: ",DoubleToStr(Spread,Digits));                                                                                                
        }//6
     else
        {//7
          ErrorCode = GetLastError();
          string ErrDesc = ErrorDescription(ErrorCode); 
                 
          string ErrAlert = StringConcatenate(" Initial Buy Order Failed: ",ErrorCode, ": ",ErrDesc);
          Alert(ErrAlert);
         
          string ErrLog = StringConcatenate(" Initial Buy Order Failed -  Ask: ",DoubleToStr(Ask,Digits)," Open Buy Price: ",DoubleToStr(OrderOpenPrice(),Digits)," Spread: ",DoubleToStr(Spread,Digits)," Lots: ",InitialLots," Ticket: " ,BuyTicket," Stop Level: ",StopLevel," Freeze Level: ",FreezeLevel);        
          Print(ErrLog);
         }//7 
    return(0);
     }//5
//+------------------------------------------------------------------+     
     // Sell Order Condition to Open
     
             
     if(price == 0)
       {
        price = Bid;
       }
     else
     if((price - Bid)/Point >= PriceStep)
      {//8                                       
                  RefreshRates();                                                       
             SellTicket = OrderSend(Symbol(),OP_SELL,InitialLots,Bid,Slippage*pips2points,0,0,"Initial Sell Order",MagicNumber,0,Red);
             price = Bid;                 
             if(SellTicket > -1)
                   {//9
                     Print(" Initial Sell order Placed: ", SellTicket," Open Sell Price: ",DoubleToStr(OrderOpenPrice(),Digits)," Spread: ",DoubleToStr(Spread,Digits));                                                                             
         }//9
      else
         {//10
           ErrorCode = GetLastError();
           ErrDesc =ErrorDescription(ErrorCode);
                   
           ErrAlert = StringConcatenate(" Initial Sell Order Failed: ",ErrorCode, ": ",ErrDesc);
           Alert(ErrAlert);
         
          ErrLog = StringConcatenate(" Initial Sell Order Failed -  Bid: ",DoubleToStr(Bid,Digits)," Open Sell Price: ",DoubleToStr(OrderOpenPrice(),Digits)," Spread: ",DoubleToStr(Spread,Digits)," Lots: " , InitialLots," Ticket: " ,SellTicket," Stop Level: ",StopLevel," Freeze Level: ", FreezeLevel);
          Print(ErrLog);
         }//10          
      }//8                  
//----
   }// 

 Thank you in advance for any support provided.

Luis 

 
luisneves: but if starts to bounce back no orders (buy) are opening.
As you've been told before, add PRINT statements (including variable values) before and inside your IFs so you find out why.