# I want to Open a Pending order when a trade is opened

39855
2016.06.22 21:35

I want to open a BUYSTOP when a new buy trade is opened and a SELLSTOP when a new sell trade is opened

```double trigger_price = Ask; //-- Modify this variable to your prefered method of detecting new order open price, ie price when your ea trigger new order.

bool   orderopen = 1;

for (int o=OrdersTotal(); o>=0; o--)
{

if (trigger_price == OrderOpenPrice())
{
orderopen = 1;
}

}

if (orderopen == 0 && OrderType() == OP_BUY)
{
lotsize=OrderLots();
double price = trigger_price+(Distance*pips);
if(StopLoss>0){stop_loss = (price - (StopLoss * pips));}else{stop_loss=0;}
if(TakeProfit>0){take_profit = (price + (TakeProfit * pips));}else{take_profit=0;}

}```
1385
2016.06.22 23:56

In this case, you have to count the number of Buy/sell and BuyStop / SellStop orders.

Then use the logic you want the EA to do according to the exist orders.

Please note that your code is not practically effecient for 2 reasons,

- In case of slippage,  trigger_price will never equal to OrderOpenPrice() !.

- OrderOpenPrice() for Buy and Sell orders are not the same (Ask !) ... So, for sure  you will get 50% of orders have the same as the slippage case.

39855
2016.06.23 10:49
Osama Shaban:

In this case, you have to count the number of Buy/sell and BuyStop / SellStop orders.

Then use the logic you want the EA to do according to the exist orders.

Please note that your code is not practically effecient for 2 reasons,

- In case of slippage,  trigger_price will never equal to OrderOpenPrice() !.

- OrderOpenPrice() for Buy and Sell orders are not the same (Ask !) ... So, for sure  you will get 50% of orders have the same as the slippage case.

am trying to count buys and sells seperately
/