MT4四 EA多单空单与平仓

//做多单
//lots下单手数 sp 止损点数 tp获利点数 comment注释 magic标识号
int buy(double lots,int sp,int tp,string comment,int magic)
{
bool exist = false;
for(int i=0;i {
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)true)
{
string comm = OrderComment();
int magicNum = OrderMagicNumber();
if(OrderSymbol()Symbol() && OrderTypeOP_BUY && comm
comment && magicNum = magic)
{
exist=true;
break;
}
}
}
//
int order = -1;
if(!exist)
{
if(sp!=0 && tp!=0)
order = OrderSend(Symbol(),OP_BUY,lots,Ask,50,Ask-spPoint,Ask+tpPoint,comment,magic,0,clrRed);
if(sp0 && tp0)
order = OrderSend(Symbol(),OP_BUY,lots,Ask,50,0,0,comment,magic,0,clrRed);
if(sp0 && tp!=0)
order = OrderSend(Symbol(),OP_BUY,lots,Ask,50,0,Ask+tp*Point,comment,magic,0,clrRed);
if(sp!=0 && tp
0)
order = OrderSend(Symbol(),OP_BUY,lots,Ask,50,Ask-sp*Point,0,comment,magic,0,clrRed);
}
return order;
}

//做空单
//lots下单手数 sp 止损点数 tp获利点数 comment注释 magic标识号
int sell(double lots,int sp,int tp,string comment,int magic)
{
bool exist = false;
for(int i=0;i {
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)true)
{
string comm = OrderComment();
int magicNum = OrderMagicNumber();
if(OrderSymbol()Symbol()&& OrderTypeOP_SELL&& comm
comment && magicNum = magic)
{
exist=true;
break;
}
}
}
//
int order = -1;
if(!exist)
{
if(sp!=0 && tp!=0)
order = OrderSend(Symbol(),OP_SELL,lots,Bid,50,Bid+spPoint,Bid-tpPoint,comment,magic,0,clrGreen);
if(sp0 && tp0)
order = OrderSend(Symbol(),OP_SELL,lots,Bid,50,0,0,comment,magic,0,clrGreen);
if(sp0 && tp!=0)
order = OrderSend(Symbol(),OP_SELL,lots,Bid,50,0,Bid-tp*Point,comment,magic,0,clrGreen);
if(sp!=0 && tp
0)
order = OrderSend(Symbol(),OP_SELL,lots,Bid,50,Bid+sp*Point,0,comment,magic,0,clrGreen);
}
return order;
}

bool close(int ticket,double lots)
{
bool closed = false;
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)==true)
{
closed = OrderClose(ticket,lots,OrderClosePrice(),50,clrGray);
}
return closed;
}

你可能感兴趣的:(MT4)