下载MetaTrader 5
要添加评论,请登录注册
如何选择最合适的信号并立刻订阅
nimrod
18
nimrod 2007.03.31 11:24 
请问mq4 的MACD Sample例程中
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吗?
Rashid Umarov
管理员
6601
Rashid Umarov 2007.03.31 12:30  
See https://docs.mql4.com/cn/constants/trading

Constant Value Description
OP_BUY0Buying position.
OP_SELL1Selling position.
OP_BUYLIMIT2Buy limit pending position.
OP_SELLLIMIT3Sell limit pending position.
OP_BUYSTOP4Buy stop pending position.
OP_SELLSTOP5Sell 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());
nimrod
18
nimrod 2007.03.31 14:47  
thank you!谢谢你!
Rashid Umarov
管理员
6601
Rashid Umarov 2007.03.31 21:29  
You're welcome.
/
要添加评论,请登录注册