下载MetaTrader 5
要添加评论,请登录注册
分享来自其他资源的链接。现在它们都有描述。
sidney
39
sidney 2010.08.17 02:15 

在MT4,可以实现一键平仓吗?一键平掉所有的仓

WANGGUANG
81
WANGGUANG 2010.08.17 02:47  

可以的,代码如下:

int start()
{
double myAsk;
double myBid;
int myTkt;
double myLot;
int myTyp;

int i;
bool result = false;

for(i=OrdersTotal();i>=0;i--)
{
OrderSelect(i, SELECT_BY_POS);

myAsk=MarketInfo(OrderSymbol(),MODE_ASK);
myBid=MarketInfo(OrderSymbol(),MODE_BID);
myTkt=OrderTicket();
myLot=OrderLots();
myTyp=OrderType();

switch( myTyp )
{
//Close opened long positions
case OP_BUY :result = OrderClose(myTkt, myLot, myBid, 3, Red);
break;

//Close opened short positions
case OP_SELL :result = OrderClose(myTkt, myLot, myAsk, 3, Red);
break;

//Close pending orders
case OP_BUYLIMIT :
case OP_BUYSTOP :
case OP_SELLLIMIT:
case OP_SELLSTOP :result = OrderDelete( OrderTicket() );
}

if(result == false)
{
Alert("Order ", myTkt, " failed to close. Error:", GetLastError() );
Print("Order ", myTkt, " failed to close. Error:", GetLastError() );
Sleep(3000);
}

Sleep(1000);

} //for
//----
return(0);
}

如果还不了解,请联系我 QQ:1031130533

/
要添加评论,请登录注册