|
|
挂单模块一般来说不会存在延迟的问题,所以它只需要解决拆单的问题,但是需要解决价格错误的问题,比如说挂突破买单,当挂单的价格小于当前买价时,挂单是挂不了的,所以要排除这种价格错误的情况。代码如下:
int pendingorder(string sym,string direction,double price,double lot,double sl,
double tp,int mag,string comment)
{
int check;
double lot_min=MarketInfo(sym,MODE_MINLOT);
double lot_max=MarketInfo(sym,MODE_MAXLOT);
double lot_last=0;
int huadian=10;
double amount;
int i;
if(lot<lot_min)
{
Print("lot is too small");
return(1);
}
if(direction=="BUYSTOP" && price<MarketInfo(sym,MODE_ASK)+
MarketInfo(sym,MODE_SPREAD)*MarketInfo(sym,MODE_POINT))
{
Print(" rice is too low for BUYSTOP order");
return(1);
}
else if(direction=="BUYLIMIT" && price>MarketInfo(sym,MODE_ASK)-
MarketInfo(sym,MODE_SPREAD)*MarketInfo(sym,MODE_POINT))
{
Print(" rice is too high for BUYLIMIT order");
return(1);
}
else if(direction=="SELLSTOP" && price>MarketInfo(sym,MODE_BID)-
MarketInfo(sym,MODE_SPREAD)*MarketInfo(sym,MODE_POINT))
{
Print(" rice is too high for SELLSTOP order");
return(1);
}
else if(direction=="SELLLIMIT" && price<MarketInfo(sym,MODE_BID)+
MarketInfo(sym,MODE_SPREAD)*MarketInfo(sym,MODE_POINT))
{
Print(" rice is too low for SELLLIMIT order");
return(1);
}
if(lot>lot_max)
{
amount=MathCeil(lot/lot_max);
lot_last=lot-(amount-1)*lot_max;
for(i=(int)amount;i>0;i--)
{
if (i!=1)
{
if(direction=="BUYSTOP")
{
check=OrderSend(sym,OP_BUYSTOP,lot_max,price,huadian,sl,tp,
comment,mag,0,clrBlue);
}
else if(direction=="BUYLIMIT")
{
check=OrderSend(sym,OP_BUYLIMIT,lot_max,price,huadian,sl,tp,
comment,mag,0,clrBlue);
}
else if(direction=="SELLSTOP")
{
check=OrderSend(sym,OP_SELLSTOP,lot_max,price,huadian,sl,tp,
comment,mag,0,clrRed);
}
else if(direction=="SELLLIMIT")
{
check=OrderSend(sym,OP_SELLLIMIT,lot_max,price,huadian,sl,tp,
comment,mag,0,clrRed);
}
}
else
{
if(direction=="BUYSTOP")
{
check=OrderSend(sym,OP_BUYSTOP,lot_last,price,huadian,sl,tp,
comment,mag,0,clrBlue);
}
else if(direction=="BUYLIMIT")
{
check=OrderSend(sym,OP_BUYLIMIT,lot_last,price,huadian,sl,tp,
comment,mag,0,clrBlue);
}
else if(direction=="SELLSTOP")
{
check=OrderSend(sym,OP_SELLSTOP,lot_last,price,huadian,sl,tp,
comment,mag,0,clrRed);
}
else if(direction=="SELLLIMIT")
{
check=OrderSend(sym,OP_SELLLIMIT,lot_last,price,huadian,sl,tp,
comment,mag,0,clrRed);
}
}
}
}
else
{
if(direction=="BUYSTOP")
{
check=OrderSend(sym,OP_BUYSTOP,lot,price,huadian,sl,tp,
comment,mag,0,clrBlue);
}
else if(direction=="BUYLIMIT")
{
check=OrderSend(sym,OP_BUYLIMIT,lot,price,huadian,sl,tp,
comment,mag,0,clrBlue);
}
else if(direction=="SELLSTOP")
{
check=OrderSend(sym,OP_SELLSTOP,lot,price,huadian,sl,tp,
comment,mag,0,clrRed);
}
else if(direction=="SELLLIMIT")
{
check=OrderSend(sym,OP_SELLLIMIT,lot,price,huadian,sl,tp,
comment,mag,0,clrRed);
}
}
return(0);
}
复制代码 |
|