 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The OrderType() function returns a value which determines the type of operation of the order which was previously selected by the OrderSelect() function:
- OP_BUY — long position,
- OP_SELL — short position,
- OP_BUYLIMIT — pending order Buy Limit,
- OP_BUYSTOP — pending order Buy Stop,
- OP_SELLLIMIT — pending order Sell Limit,
- OP_SELLSTOP — pending order Sell Stop.
In the previous article I gave an example which determined how the position was closed — by Stop Loss order or by Take Profit order. At the same time in this example there is a small mistake: if the selected order is a pending order then this portion of the code will erroneously consider that the position was closed by Take Profit. We will modify our example to exclude this mistake:
//---- select order/position with ticker 77777
if ( OrderSelect (77777, SELECT_BY_TICKET) == true)
{
if ((OrderType() == OP_BUY) || (OrderType() == OP_SELL))
{
// position is selected successfully
if ( ((OrderClosePrice() <= OrderStopLoss()) && (OrderType() == OP_BUY)) ||
((OrderClosePrice() >= OrderStopLoss()) && (OrderType() == OP_SELL)) )
{
// position closed by Stop Loss
// ...
}
else
{
// position closed by Take Profit
// ...
}
}
else
Print("Error: it’s not a closed position, it’s a pending order");
}
else
Print("OrderSelect() returned error - ",GetLastError());
By means of an additional checking we manage to separate closed positions from pending orders:
if ((OrderType() == OP_BUY) || (OrderType() == OP_SELL))
Next article: " OrderCloseTime function"
|
|
|
|
|
|
 |
|
|
|
|
|
|
|
|
|
|
|
|
|
+7 (495) 710-76-76
|
© 1998—2008 «Alpari» |
|