本帖最后由 ldf 于 2019-9-26 23:05 编辑
#property copyright "Z---EA"
#property link "Z---EA"
enum 做单方向
{
多空都开=0, 开多=1,开空=2,
};
extern 做单方向 开仓方向=0;
extern int 魔术号A=61501;
extern double 下单手数A=0.01;
extern int 下单周期=1;
extern int MACD周期=1;
extern double MACD快EMA大=12;
extern double MACD慢EMA大=26;
extern double MACDSMA大=20;
extern double MACD快EMA细=12;
extern double MACD慢EMA细=26;
extern double MACDSMA细=9;
extern int 布林周期=1;
extern double 布林参数=13;
extern double 布林转换=0;
extern double 布林偏差=1.3;
extern int 均布最大持仓单数量A=1;
extern double 大于点差不开单=50;
extern double 止损点数=1500;
extern double 止盈点数=1500;
int 滑点=50;
string 注释A="M布";
//+------------------------------------------------------------------+
//| Expert initialization function |
//+------------------------------------------------------------------+
int OnInit()
{
//---
//---
return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| Expert deinitialization function |
//+------------------------------------------------------------------+
void OnDeinit(const int reason)
{
//---
}
//+------------------------------------------------------------------+
//| Expert tick function |
//+------------------------------------------------------------------+
void OnTick()
{
int Ticket=OrdersTotal();
double Lots = 0.0;
double Mzhu1大=iMACD(NULL,MACD周期,MACD快EMA大,MACD慢EMA大,MACDSMA大,PRICE_CLOSE,MODE_MAIN,1);
double Mzhu2大=iMACD(NULL,MACD周期,MACD快EMA大,MACD慢EMA大,MACDSMA大,PRICE_CLOSE,MODE_MAIN,2);
double Mxian1大=iMACD(NULL,MACD周期,MACD快EMA大,MACD慢EMA大,MACDSMA大,PRICE_CLOSE,MODE_SIGNAL,1);
double Mxian2大=iMACD(NULL,MACD周期,MACD快EMA大,MACD慢EMA大,MACDSMA大,PRICE_CLOSE,MODE_SIGNAL,2);
double Mzhu1细=iMACD(NULL,MACD周期,MACD快EMA细,MACD慢EMA细,MACDSMA细,PRICE_CLOSE,MODE_MAIN,1);
double Mzhu2细=iMACD(NULL,MACD周期,MACD快EMA细,MACD慢EMA细,MACDSMA细,PRICE_CLOSE,MODE_MAIN,2);
double Mxian1细=iMACD(NULL,MACD周期,MACD快EMA细,MACD慢EMA细,MACDSMA细,PRICE_CLOSE,MODE_SIGNAL,1);
double Mxian2细=iMACD(NULL,MACD周期,MACD快EMA细,MACD慢EMA细,MACDSMA细,PRICE_CLOSE,MODE_SIGNAL,2);
double B2Z=iBands(NULL,布林周期,布林参数,布林偏差,布林转换,PRICE_CLOSE,0,2);
double B2S=iBands(NULL,布林周期,布林参数,布林偏差,布林转换,PRICE_CLOSE,1,2);
double B2X=iBands(NULL,布林周期,布林参数,布林偏差,布林转换,PRICE_CLOSE,2,2);
double B1Z=iBands(NULL,布林周期,布林参数,布林偏差,布林转换,PRICE_CLOSE,0,1);
double B1S=iBands(NULL,布林周期,布林参数,布林偏差,布林转换,PRICE_CLOSE,1,1);
double B1X=iBands(NULL,布林周期,布林参数,布林偏差,布林转换,PRICE_CLOSE,2,1);
double B0Z=iBands(NULL,布林周期,布林参数,布林偏差,布林转换,PRICE_CLOSE,0,0);
double B0S=iBands(NULL,布林周期,布林参数,布林偏差,布林转换,PRICE_CLOSE,1,0);
double B0X=iBands(NULL,布林周期,布林参数,布林偏差,布林转换,PRICE_CLOSE,2,0);
double M30C0=iClose(NULL,下单周期,0);
double M30O0=iOpen(NULL,下单周期,0);
double M30L0=iLow(NULL,下单周期,0);
double M30H0=iHigh(NULL,下单周期,0);
double M30C1=iClose(NULL,下单周期,1);
double M30O1=iOpen(NULL,下单周期,1);
double M30L1=iLow(NULL,下单周期,1);
double M30H1=iHigh(NULL,下单周期,1);
double M30C2=iClose(NULL,下单周期,2);
double M30O2=iOpen(NULL,下单周期,2);
double M30L2=iLow(NULL,下单周期,2);
double M30H2=iHigh(NULL,下单周期,2);
double M30C3=iClose(NULL,下单周期,3);
double M30O3=iOpen(NULL,下单周期,3);
double M30L3=iLow(NULL,下单周期,3);
double M30H3=iHigh(NULL,下单周期,3);
if( Mxian1细>Mxian1大 &&M30C0<B0X &&买持仓单数量A()<均布最大持仓单数量A&&(Ask-Bid)/Point<大于点差不开单&&IsNewTFbarA()&&(开仓方向==0||开仓方向==1))
{ Ticket=OrderSend(Symbol(),OP_BUY,下单手数A,Ask,滑点,Ask-止损点数*Point,Ask+止盈点数*Point,注释A,魔术号A,0,clrRed);
if (True) SendMail("[Signal Alert]"+"[ Symbol() ]", "开单提醒" );
}
if( Mxian1细<Mxian1大 &&M30C0>B0S &&卖持仓单数量A()<均布最大持仓单数量A&&(Ask-Bid)/Point<大于点差不开单&&IsNewTFbarA()&&(开仓方向==0||开仓方向==2))
{ Ticket=OrderSend(Symbol(),OP_SELL,下单手数A,Bid,滑点,Bid+止损点数*Point,Bid-止盈点数*Point,注释A,魔术号A,0,clrBlue);
if (True) SendMail("[Signal Alert]"+"[ Symbol() ]", "开单提醒" );
}
}
//+------------------------------------------------------------------+
void 平手工买仓()
{
int total = OrdersTotal();
for(int i=total-1;i>=0;i--)
{
if( OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
if(OrderSymbol()=="GBPUSDc"&&OrderType()==OP_BUY&&OrderMagicNumber()==0){
bool result = false;
result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 30, Red );
if(result) Print(Symbol()+"平多单成功!!");
if(result == false)
{
Print("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
}
}}}
}
void 平手工卖仓()
{
int total = OrdersTotal();
for(int i=total-1;i>=0;i--)
{
if( OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
if(OrderSymbol()=="GBPUSDc"&&OrderType()==OP_SELL&&OrderMagicNumber()==0){
bool result = false;
result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 30, Red );
if(result) Print(Symbol()+"平空单成功!!");
if(result == false)
{
Print("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
}
}}}
}
bool IsNewTFbarA()
{
static datetime t=0;
if(t!=iTime(NULL,下单周期,0))
{
t=iTime(NULL,下单周期,0);
return(true);
}
return (false);
}
bool IsNewTFbarB()
{
static datetime t=0;
if(t!=iTime(NULL,下单周期,0))
{
t=iTime(NULL,下单周期,0);
return(true);
}
return (false);
}
void 平买仓A()
{
int total = OrdersTotal();
for(int i=total-1;i>=0;i--)
{
if( OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
if(OrderSymbol()==Symbol()&&OrderType()==OP_BUY&&OrderMagicNumber()==魔术号A){
bool result = false;
result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 30, Red );
if(result) Print(Symbol()+"平多单成功!!");
if(result == false)
{
Print("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
}
}}}
}
void 平卖仓A()
{
int total = OrdersTotal();
for(int i=total-1;i>=0;i--)
{
if( OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
if(OrderSymbol()==Symbol()&&OrderType()==OP_SELL&&OrderMagicNumber()==魔术号A){
bool result = false;
result = OrderClose( OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 30, Red );
if(result) Print(Symbol()+"平空单成功!!");
if(result == false)
{
Print("Order " , OrderTicket() , " failed to close. Error:" , GetLastError() );
}
}}}
}
int 买持仓单数量A()
{ int k=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if( OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
if(OrderType() == OP_BUY &&OrderSymbol()==Symbol()&&OrderMagicNumber()==魔术号A)
{k++;}
}
} return(k);
}
int 卖持仓单数量A()
{ int k=0;
for(int i=OrdersTotal()-1;i>=0;i--)
{
if( OrderSelect(i, SELECT_BY_POS, MODE_TRADES)){
if(OrderType() == OP_SELL &&OrderSymbol()==Symbol()&&OrderMagicNumber()==魔术号A)
{k++;}
}
} return(k);
}
|