//| 穿均线交易.mq4 |
#property copyright "qiu"
#property link "http://www.metaquotes.net"
extern double 幅度 = 10;
extern double 止盈 = 50;
extern double 止损 = 50;
extern double 交易手数 = 0.1;
extern int 均线周期 = 34;
extern int buytisun = 200; //当多单盈利多少点后开启移动止损
extern int selltisun = 200; //当空单盈利多少点后开启移动止损
extern double 移动止损 = 0;
int init()
{
return(0);
}
int deinit()
{
return(0);
}
//+------------------------------------------------------------------+
//| expert start function |
//+------------------------------------------------------------------+
int start()
{
double ma=iMA(NULL,0,均线周期,0,MODE_LWMA,PRICE_TYPICAL,0);
double map=iMA(NULL,0,均线周期,0,MODE_LWMA,PRICE_TYPICAL,1);
if(Close[1]-10*Point>ma&&Open[1]+10*Point<ma&&Close[0]-Open[1]>幅度*Point&& Open[2]<map && Close[2]<map)
{
if(buy(交易手数,止损,止盈,Symbol()+"buy",0)>0) //buy
// if(sell(交易手数,止损,止盈,Symbol()+"sell",0)>0) //sell
{
selltisun=200;
}
}
if(Close[1]+10*Point<ma&&Open[1]-10*Point>ma&&Open[1]-Close[1]>幅度*Point&& Open[2]>map && Close[2]>map)
{
if(sell(交易手数,止损,止盈,Symbol()+"sell",0)>0) //sell
// if(buy(交易手数,止损,止盈,Symbol()+"buy",0)>0) //buy
{
buytisun=200;
}
}
for(int i=0;i<OrdersTotal();i++)
{
//if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true)
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if((OrderComment()==(Symbol()+"buy")))
{
if(((Bid-OrderOpenPrice())/Point)>=buytisun)
{
double buysl=OrderStopLoss();
if(OrderModify(OrderTicket(),OrderOpenPrice(),buysl+移动止损*Point,OrderTakeProfit(),0)==true)
{
buytisun=buytisun+移动止损;
}
}
}
if((OrderComment()==(Symbol()+"sell")))
{
if(((OrderOpenPrice()-Ask)/Point)>=selltisun)
{
double sellsl=OrderStopLoss();
if(OrderModify(OrderTicket(),OrderOpenPrice(),sellsl-移动止损*Point,OrderTakeProfit(),0)==true)
{
selltisun=selltisun+移动止损;
}
}
}
}
}
return(0);
}
//+----------buy的函数封装-----------+
int buy(double lots, double sun,double ying,string comment,int magic)
{
int kaiguan=0;
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if((OrderComment()==comment)&&(OrderMagicNumber()==magic))
{
kaiguan=1;
}
}
}
if(kaiguan==0)
{
int ticket=OrderSend(Symbol(),OP_BUY,lots,Ask,300,0,0,comment,magic,0,Blue);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET)==true)
{
if((sun!=0)&&(ying!=0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-sun*MarketInfo(Symbol(),MODE_POINT),OrderOpenPrice()+ying*MarketInfo(Symbol(),MODE_POINT),0,Blue);
}
if((sun==0)&&(ying!=0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()+ying*MarketInfo(Symbol(),MODE_POINT),0,Blue);
}
if((sun!=0)&&(ying==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()-sun*MarketInfo(Symbol(),MODE_POINT),0,0,Blue);
}
}
}
return(ticket);
}
else
{
return(0);
}
}
//+-------sell的函数封装----------+
int sell ( double lots, double sun,double ying,string comment,int magic)
{
int kaiguan=0;
for(int i=0;i<OrdersTotal();i++)
{
if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
{
if((OrderComment()==comment)&&(OrderMagicNumber()==magic))
{
kaiguan=1;
}
}
}
if(kaiguan==0)
{
int ticket=OrderSend(Symbol(),OP_SELL,lots,Bid,300,0,0,comment,magic,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET)==true)
{
if((sun!=0)&&(ying!=0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+sun*MarketInfo(Symbol(),MODE_POINT),OrderOpenPrice()-ying*MarketInfo(Symbol(),MODE_POINT),0,White);
}
if((sun==0)&&(ying!=0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),0,OrderOpenPrice()-ying*MarketInfo(Symbol(),MODE_POINT),0,White);
}
if((sun!=0)&&(ying==0))
{
OrderModify(OrderTicket(),OrderOpenPrice(),OrderOpenPrice()+sun*MarketInfo(Symbol(),MODE_POINT),0,0,White);
}
}
}
return(ticket);
}
else
{
return(0);
}
}
//+------------------------------------------------------------------+
|