请教一下各位大声,我想根据以下代码,在相关条件下平掉锁仓的单子,这个代码应该怎么写,请赐教。
void lock(int Ordertype)
{
double Price1,Lot1,Price2,Lot2;
bool locked;
if(Ordertype == OP_BUY)
{
OrderSend(Symbol(), OP_BUY, GetsellLots()-GetbuyLots(), Ask, 3, 0, 0, 0, 0, 0, BlueViolet);
locked = TRUE;
}
if(Ordertype == OP_SELL)
{
OrderSend(Symbol(), OP_SELL, GetbuyLots()-GetsellLots(), Bid, 3, 0, 0, 0, 0, 0, BlueViolet);
locked = TRUE;
}
return (0);
}
//+------------------------------------------------------------------+/
//+-------------------------计算开单数-------------------------------+
int GetOrdersTotal(int intOrderType)
{
int buy=0,sell=0,total=0;
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
continue;
if(OrderSymbol()!=Symbol())
continue;
//---- check order type
if(OrderType()==OP_BUY)
{
buy++;
}
if(OrderType()==OP_SELL)
{
sell++;
}
total++;
}
if(intOrderType==OP_BUY)
return(buy);
if(intOrderType==OP_SELL)
return(sell);
if(intOrderType==6)
return(total);
return(99999);
}
//+------------------------------------------------------------------+
//+-------------------------计算buy下单量---------------------------+
double GetbuyLots()
{
datetime lasttime=Time[Bars-1];
double buylots,selllots;
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
continue;
if(OrderSymbol()!=Symbol())
continue;
if(OrderType()==OP_BUY)
{
buylots=OrderLots()+buylots;
}
}
return(buylots);
}
//+------------------------------------------------------------------+
//+-------------------------计算sell下单量---------------------------+
double GetsellLots()
{
datetime lasttime=Time[Bars-1];
double selllots;
for(int i=0; i<OrdersTotal(); i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==false)
continue;
if(OrderSymbol()!=Symbol())
continue;
if(OrderType()==OP_SELL)
{
selllots=OrderLots()+selllots;
}
}
return(selllots);
}
//+--------------------------------------------------------------
//+------------------------------------------------------------------+
|