- int orderopen(string sym,string direction,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 err=0;
- int huadian=10;
- double amount;
- int i;
- if(lot<lot_min)
- {
- Print("lot is too small");
- return(1);
- }
- else 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=="BUY")
- {
- do
- {
- check=OrderSend(sym,OP_BUY,lot_max,MarketInfo(sym,
- MODE_ASK),huadian,sl,tp,comment,mag,0,clrBlue);
- if(check==-1)
- {
- err=GetLastError();
- }
- else
- {
- break;
- }
- }while(err==146 || err==135);
- }
- else if(direction=="SELL")
- {
- do
- {
- check=OrderSend(sym,OP_SELL,lot_max,MarketInfo(sym,
- MODE_BID),huadian,sl,tp,comment,mag,0,clrRed);
- if(check==-1)
- {
- err=GetLastError();
- }
- else
- {
- break;
- }
- }while(err==146 || err==135);
- }
- }
- else
- {
- if(direction=="BUY")
- {
- do
- {
- check=OrderSend(sym,OP_BUY,lot_last,MarketInfo(sym,
- MODE_ASK),huadian,sl,tp,comment,mag,0,clrBlue);
- if(check==-1)
- {
- err=GetLastError();
- }
- else
- {
- break;
- }
- }while(err==146 || err==135);
- }
- else if(direction=="SELL")
- {
- do
- {
- check=OrderSend(sym,OP_SELL,lot_last,MarketInfo(sym,
- MODE_BID),huadian,sl,tp,comment,mag,0,clrRed);
- if(check==-1)
- {
- err=GetLastError();
- }
- else
- {
- break;
- }
- }while(err==146 || err==135);
- }
- }
- }
- }
- else
- {
- if(direction=="BUY")
- {
- do
- {
- check=OrderSend(sym,OP_BUY,lot,MarketInfo(sym,
- MODE_BID),huadian,sl,tp,comment,mag,0,clrBlue);
- if(check==-1)
- {
- err=GetLastError();
- }
- else
- {
- break;
- }
- }while(err==146 || err==135);
- }
- if(direction=="SELL")
- {
- do
- {
- check=OrderSend(sym,OP_SELL,lot,MarketInfo(sym,
- MODE_BID),huadian,sl,tp,comment,mag,0,clrRed);
- if(check==-1)
- {
- err=GetLastError();
- }
- else
- {
- break;
- }
- }while(err==146 || err==135);
- }
- }
- return(0);
- }
-
复制代码