 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
We will consider the OrderTakeProfit() function and refine our example. For some reason from the first lines of the code we undoubtedly believe in the fact that the position was closed namely by Stop Loss or Take Profit of the order. And what if it isn’t so?
- If for a long position the closing price is not lower than the level of Take Profit, then the position is closed by Take Profit.
- If for a short position the closing price is not higher that the level of Take Profit, the position is closed by Take Profit.
We know that the level of Stop Loss order of the selected position or order can be determined with the help of the OrderStopLoss() function. Similarly the level of Take Profit is determined with the help of the OrderTakeProfit() function:
double OrderTakeProfit()
The order must be previously selected by the OrderSelect() function.
We will modify our example in order to make sure that the position is closed by order and not from the market:
//---- we select order/position with ticker 77777
if ( OrderSelect (77777, SELECT_BY_TICKET) == true)
{
// is it a position and not a pending order?
if ((OrderType() == OP_BUY) || (OrderType() == OP_SELL))
{
// is it a closed or an open position?
if ( OrderCloseTime() != 0 )
{
if ( ((OrderClosePrice() <= OrderStopLoss()) && (OrderType() == OP_BUY)) ||
((OrderClosePrice() >= OrderStopLoss()) && (OrderType() == OP_SELL)) )
{
// position closed by Stop Loss
// ...
}
else
{
if ( ((OrderClosePrice() >= OrderTakeProfit()) && (OrderType() == OP_BUY)) ||
((OrderClosePrice() <= OrderTakeProfit()) && (OrderType() == OP_SELL)) )
{
// position closed by Take Profit
// ...
}
else
Print("Error: position is closed not by the order");
}
}
else
Print("Error: it is an open and not a closed position");
}
else
Print("Error: it isn’t a closed position, it is a pending order");
}
else
Print("OrderSelect() вернул ошибку - ",GetLastError());
Next article: " OrderSymbol function"
|
|
|
|
|
|
 |
|
|
|
|
|
|
|
|
|
|
|
|
|
+7 (495) 710-76-76
|
© 1998—2008 «Alpari» |
|