在 int
tic=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),20,Magenta)之前加了printf("OrderTicket()=%d,OrderLots()=%f,OrderClosePrice()=%f",OrderTicket(),OrderLots(),OrderClosePrice())
运行时出现了比如OrderTicket()=224308378 OrderLots()=0.010000 OrderClosePrice()=0.643890
但是tic=OrderClose一句有时正常平仓有时不能正常平仓 为什么??
打印出错误原因就知道了
yi wen:
打印出错误原因就知道了
以printf打印getlasterror没有得到任何结果
打印出错误原因就知道了
//+------------------------------------------------------------------+ //| CloseOrder Function | //+------------------------------------------------------------------+ #define MaxTry 10 void CloseOrder(string _symbol,long _ticket,int _MaxDeviration) { double price; int total = OrdersTotal(); if(_ticket == 0) //不指定订单,遍历平仓所有 { int order_ticket[]; ArrayResize(order_ticket,total); //-----将所有持仓订单号保存到数组---- for(int i=0;i<total;i++) { if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES)==false) { Print(__FUNCTION__,"OrderSelect failed error code is ",GetLastError()); } order_ticket[i] = OrderTicket(); } //-------------------- for(int i=0;i<total;i++) { if(OrderSelect(order_ticket[i],SELECT_BY_TICKET,MODE_TRADES)==false) { Print(__FUNCTION__,"#1 OrderSelect failed error code is ",GetLastError()); break; } if(OrderMagicNumber()!=MAGIC ) continue; if(_symbol!="")//""所有货币对 { if(OrderSymbol()!=_symbol) continue; } if(OrderType()<=1) { int maxTry = MaxTry; while(maxTry>0) { if(OrderType()==OP_BUY) price = MarketInfo(OrderSymbol(),MODE_BID); else price = MarketInfo(OrderSymbol(),MODE_ASK); if(OrderClose(OrderTicket(),OrderLots(),price,_MaxDeviration,CLR_NONE)) { Print("Order closed successfully~"); break; } else { Print("maxTry = ",maxTry," Order close error~",GetLastError()); maxTry--; } } } } } else if(_ticket >0) // 针对指定订单 { if(OrderSelect(_ticket,SELECT_BY_TICKET,MODE_TRADES)==false) { Print(__FUNCTION__,"#2 OrderSelect failed error code is ",GetLastError()); return; } if(OrderType()<=1) { int maxTry = MaxTry; while(maxTry>0) { if(OrderType()==OP_BUY) price = MarketInfo(OrderSymbol(),MODE_BID); else price = MarketInfo(OrderSymbol(),MODE_ASK); if(OrderClose(_ticket,OrderLots(),price,_MaxDeviration,CLR_NONE)) { Print("Order closed successfully~"); break; } else { Print("maxTry = ",maxTry," Order close error~",GetLastError()); maxTry--; } } } } else {Print("wrong _ticket ",_ticket);} }
通用鲁棒性形式
jocojohn:
在 int tic=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),20,Magenta)之前加了printf("OrderTicket()=%d,OrderLots()=%f,OrderClosePrice()=%f",OrderTicket(),OrderLots(),OrderClosePrice()) 运行时出现了比如OrderTicket()=224308378 OrderLots()=0.010000 OrderClosePrice()=0.643890 但是tic=OrderClose一句有时正常平仓有时不能正常平仓 为什么??
在 int tic=OrderClose(OrderTicket(),OrderLots(),OrderClosePrice(),20,Magenta)之前加了printf("OrderTicket()=%d,OrderLots()=%f,OrderClosePrice()=%f",OrderTicket(),OrderLots(),OrderClosePrice()) 运行时出现了比如OrderTicket()=224308378 OrderLots()=0.010000 OrderClosePrice()=0.643890 但是tic=OrderClose一句有时正常平仓有时不能正常平仓 为什么??
参数中能用OrderClosePrice()吗?