Hedging EA needs fix. Help!

 

Hi guys! so i've been trying to create a Hedging EA but I can't find the reason why I can't send a pending order once the price reaches the stoploss of the other open order.

Hope you guys can help! A lot of thanks! here is the code.

 if(OpenOrdersThisPair(Symbol())>=2)
   {
      for(b=OpenOrdersThisPair(Symbol())-1;b>=0;b--)
      {
          if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
          if(OrderSymbol()==Symbol())
          if(OrderType()==OP_BUY)
            {
               BuyPrice=OrderOpenPrice();
               BuyLotSize=OrderLots();              
            }
          if(OrderType()==OP_SELL)
            {
               SellPrice=OrderOpenPrice();
               SellLotSize=OrderLots();             
            }
          if(OrderType()==OP_BUYSTOP)
          {
               BuystopPrice=OrderOpenPrice();
               BuystopLots=OrderLots();              
          }
          if(OrderType()==OP_SELLSTOP)
          {
               SellstopPrice=OrderOpenPrice();
               SellstopLots=OrderLots();               
          }
      }
      
      for(b=OpenOrdersThisPair(Symbol())-1;b>=0;b--)
         {  
            if(OrderSelect(b,SELECT_BY_POS,MODE_TRADES))
            if(OrderSymbol()==Symbol())
            if(OrderType()==OP_BUY)
               {  
                  if(Bid==OrderTakeProfit())
                  {
                     CloseAllOrders();                     
                  }
                  if(Bid==OrderStopLoss())
                  {                  
                     OrderSend(Symbol(),OP_BUYSTOP,SellstopLots,(Ask+(PipsBasis*pips)),3,(Ask+(PipsBasis*pips))-((PipsBasis-1)*pips),Ask+(PipsBasis*2*pips),NULL,0,0,clrNONE);                     
                  }         
               }
 
Jacinto Michael:

Hi guys! so i've been trying to create a Hedging EA but I can't find the reason why I can't send a pending order once the price reaches the stoploss of the other open order.

Hope you guys can help! A lot of thanks! here is the code.

Hello !

This instant order shouldn't be a pending one. But anyway if you wish to use pending orders you have to preset the hedge by putting the desired order open at the stoploss of the previous one. 

 

Thanks for your response Icham, been thinking about your idea and i think  I just did just that by placing an ordersend for the pending order if bid=stoploss of the other as seen below... but it does not execute the send function

if(Bid==OrderStopLoss())
                  {                  
                     OrderSend(Symbol(),OP_BUYSTOP,SellstopLots,(Ask+(PipsBasis*pips)),3,(Ask+(PipsBasis*pips))-((PipsBasis-1)*pips),Ask+(PipsBasis*2*pips),NULL,0,0,clrNONE);                     
                  }  
 
Jacinto Michael:

Thanks for your response Icham, been thinking about your idea and i think  I just did just that by placing an ordersend for the pending order if bid=stoploss of the other as seen below... but it does not execute the send function

Place the order @ the stoploss level, before price reach it.