See https://docs.mql4.com/cn/constants/trading
and https://docs.mql4.com/cn/trading/OrderType
Returns order operation type for the currently selected order. It can be any of the following values:
OP_BUY - buying position,
OP_SELL - selling position,
OP_BUYLIMIT - buy limit pending position,
OP_BUYSTOP - buy stop pending position,
OP_SELLLIMIT - sell limit pending position,
OP_SELLSTOP - sell stop pending position.
Note: order must be selected by OrderSelect() function.
Constant | Value | Description |
---|---|---|
OP_BUY | 0 | Buying position. |
OP_SELL | 1 | Selling position. |
OP_BUYLIMIT | 2 | Buy limit pending position. |
OP_SELLLIMIT | 3 | Sell limit pending position. |
OP_BUYSTOP | 4 | Buy stop pending position. |
OP_SELLSTOP | 5 | Sell stop pending position. |
and https://docs.mql4.com/cn/trading/OrderType
Returns order operation type for the currently selected order. It can be any of the following values:
OP_BUY - buying position,
OP_SELL - selling position,
OP_BUYLIMIT - buy limit pending position,
OP_BUYSTOP - buy stop pending position,
OP_SELLLIMIT - sell limit pending position,
OP_SELLSTOP - sell stop pending position.
Note: order must be selected by OrderSelect() function.
Sample:
int order_type;
if(OrderSelect(12, SELECT_BY_POS)==true)
{
order_type=OrderType();
// ...
}
else
Print("OrderSelect() returned error - ",GetLastError());
thank you!谢谢你!
You're welcome.
for(cnt=0;cnt<total;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
if(OrderType()==OP_BUY) // long position is opened
{
// should it be closed?
if(MacdCurrent>0 && MacdCurrent<SignalCurrent && MacdPrevious>SignalPrevious &&
MacdCurrent>(MACDCloseLevel*Point))
{
OrderClose(OrderTicket(), OrderLots(), Bid, 3,Violet); // close position
return(0); // exit
}
// check for trailing stop
if(TrailingStop>0)
{
if(Bid-OrderOpenPrice()>Point*TrailingStop)
{
if(OrderStopLoss()<Bid-Point*TrailingStop)
{
OrderModify(OrderTicket(), OrderOpenPrice(), Bid-Point*TrailingStop, OrderTakeProfit(), 0,Green);
return(0);
}
}
}
}
else // go to short position
的OrderType()<=OP_SELL为什么要用<=,而不用==.用<=就是指返回OP_SELL或OP_BUY吗?