How to stop openning orders?
Pawel_Partyka:
The OrderSend function is opening orders over and over because all EAs basically
loop.I want to open long position every time trend is upward and Ask price is at some
particular level (eg. USDCHF, Ask = 1.2275). I want to have only one position open
with the same open price.
1. Function "OrderSend" opens dozens of orders at the same time. Pls, tell how to make it open only one order, and only if there is no order opened with the same price.
2. How to indicate the trend must be upward?
I thank you kindly for any advice.
Brgds
Pawel
You need to have code to check if current order exists, if it does then do nothing, if it doesn't then place the order.
This is the way I do it but there are probably better ways. I simplified the code a bit.
//loops through open orders
total = OrdersTotal(); //total open orders
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderMagicNumber() == 11111 && OrderType()==OP_BUY)//this particular example looks for open buy orders with magic number 11111
{
//place order
}
}
I want to open long position every time trend is upward and Ask price is at some particular level (eg. USDCHF, Ask = 1.2275). I want to have only one position open with the same open price.
1. Function "OrderSend" opens dozens of orders at the same time. Pls, tell how to make it open only one order, and only if there is no order opened with the same price.
2. How to indicate the trend must be upward?
I thank you kindly for any advice.
Brgds
Pawel