版主看看这个EA

楼主  收藏   举报   帖子创建时间:  2019-05-05 15:07 回复:0 关注量:801
俺看不懂EA源码,试了一下,感觉这个EA还是有一点点的用处的,发出来源码和大家一起分享,
  还得请求版主给解决一个问题,源码我是看不明白,问题如下:
  
  问题1:我想给这个EA问题1:我想给这个EA在交易的时候(比如:买单,卖单,平仓的时候),添加一个发邮件的功能,原程序不知道有没有编写进去,(因为我看不明白所以不知道)如果没有的话请版主帮忙写进去,
  
  问题2:我在测试这个EA的时候为什么每次交易的时候总是重复的连下3单,我只想让他下一单,请版主给我改成美次只下一单的。
  
        谢谢版主   谢谢版主//<div class="blockcode"><div id="code_yEC"><ol>
//+------------------------------------------------------------------+
//|                                                         ssss.mq4 |
//|                                                           sss |
//|                                            http://www.ssss.net |
//+------------------------------------------------------------------+
#property copyright "sdf"
#property link      "http://www.ssss.net"


  
#define OrderStr ""

extern double  Lots = 200;//
extern int  StopLoss = 0;//
extern int   TakeProfit = 0;
extern bool  TradeAtCloseBar = true;
extern int   TrailingStop = 0;
extern int   TrailingStep = 1;      //Trailing step
extern int     BreakEven = 0;
extern int    MagicNumber=0;
//For alerts:
extern int     Repeat=3;
extern int     Periods=5;
extern bool    Usealert=false;
extern bool    SendEmail=true;
extern string
    TradeLog="MasterMind3";
  

extern int  Slippage = 3;//滑点
  
int           mm = -1;
double         Risk = 1;
int           Crepeat=0;
int            alertTime=0;
double         AheadTradeSec = 0;
double         AheadExitSec = 0;
int        TradeBar = 0;
double         MaxTradeTime = 300;
  
extern string  
          Indicator_Setting = "---------- Indicator Setting";
extern   bool     Crash = false;
extern   int      Timeframe = 0;
extern   int      Length = 5;
extern   int      Method = 3;
extern   int      Smoothing = 1;
extern   int      Filter = 5;
  
extern   bool     RealTime = true;
extern   bool     Steady  = false;
extern   bool     Color = true;
extern   bool     alerts = true;
extern   bool     EmailON = false;
extern   bool     SignalPrice = true;
extern   color    SignalPriceBUY = Yellow;
extern   color    SignalPriceSELL = Aqua;
extern   int      CountBars = 1485;
  
int
      NumberOfTries  = 5, //Number of tries to set, close orders;
      RetryTime   = 1;
  
  
  
double
    Ilo     = 0;
  
int DotLoc=7;
static int TradeLast=0;
  
string sound="alert.wav";
  
double sig_buy=0, sig_sell=0, sig_high=0, sig_low=0;
  
int Spread=0;
string filename="";
  
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
   {
//----
  

Crepeat=Repeat;   
//----
    return(0);
   }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
   {
//----
   
//----
    return(0);
   }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
   {
if (TradeAtCloseBar) TradeBar=1;
else TradeBar=0;
  
filename=Symbol() + TradeLog + "-" + Month() + "-" + Day() + ".log";
  

Spread=MarketInfo(Symbol(),MODE_SPREAD);
  

//----
int   i=0;
  
double   BuyValue=0, SellValue=0;
BuyValue=0; SellValue=0;
  

if (CntOrd(OP_BUY,MagicNumber)>0) TradeLast=1;
if (CntOrd(OP_SELL,MagicNumber)>0) TradeLast=-1;
  
sig_buy=iWPR(NULL,0,11,0);
sig_sell=iWPR(NULL,0,12,0);
sig_high=iWPR(NULL,0,13,0);
sig_low=iWPR(NULL,0,14,0);
  
  
//Comment("sig_buy=",sig_buy," sig_sell=",sig_sell);
  

if (sig_buy-0.01) {     
  SellValue=1;
}
  
  
  
int  cnt=0,OpenPos=0,OpenSell=0,OpenBuy=0,CloseSell=0,CloseBuy=0;
double mode=0,Stop=0,NewBarTime=0;
  
//Here we found if new bar has just opened
static int prevtime=0;  
int NewBar=0,FirstRun=1;
  
if (FirstRun==1) {
FirstRun=0;
prevtime=Time[0];
}
if ((prevtime == Time[0]) &&  (CurTime()-prevtime)>MaxTradeTime) {
NewBar=0;
}
else {
prevtime = Time[0];
NewBar=1;
}
  

int   AllowTrade=0,AllowExit=0;
//Trade before bar current bar closed
if (CurTime()>= Time[0]+Period()*60-AheadTradeSec) AllowTrade=1; else AllowTrade=0;
if (CurTime()>= Time[0]+Period()*60-AheadExitSec) AllowExit=1; else AllowExit=0;
if (AheadTradeSec==0) AllowTrade=1;
if (AheadExitSec==0) AllowExit=1;

Ilo=Lots;
if (mm1) Ilo=MathCeil(Ilo);
     if (Ilo0.1) Ilo=0.1;
  
OpenPos=0;
for(cnt=0; cnt=1) {
   OpenSell=0; OpenBuy=0;
}
  
  
  
OpenBuy=0; OpenSell=0;
CloseBuy=0; CloseSell=0;
  
//Conditions to open the position
//
if (SellValue>0) {
  OpenSell=1;
  OpenBuy=0;
}
  
if  (BuyValue>0) {
  OpenBuy=1;
  OpenSell=0;
  
}
  
//Print("OpenSell=",OpenSell," OpenBuy=",OpenBuy);
  

//Conditions to close the positions
if (SellValue>0) {
  CloseBuy=1;
}
  

if (BuyValue>0) {
  CloseSell=1;
}
  
subPrintDetails();
  

for(cnt=0; cnt0)
     {
        SetText(Time[0],High[0]+1*DotLoc*Point,("CloseBuy"+DoubleToStr(Time[0],0)),CharToStr(251),Magenta);
        PlaySound("alert.wav");
        OrdClose(OrderTicket(),OrderLots(),Bid,Slippage,Red);  
      alerts(0, 0, CloseBuy, CloseSell,Bid,0,0,OrderTicket());
      return(0);
     }
     if (TradeBar==0)
     {  
        SetText(Time[0],High[0]+1*DotLoc*Point,("CloseBuy"+DoubleToStr(Time[0],0)),CharToStr(251),Magenta);
        PlaySound("alert.wav");
        OrdClose(OrderTicket(),OrderLots(),Bid,Slippage,Red);
      alerts(0, 0, CloseBuy, CloseSell,Bid,0,0,OrderTicket());
      return(0);
     }
   
   }
  }
  
  if (OrderType()==OP_SELL && OrderSymbol()==Symbol() && ((OrderMagicNumber () == MagicNumber) || MagicNumber==0)) {
   if (CloseSell==1 && AllowExit==1) {
    if (NewBar==1 && TradeBar>0)
    {
        SetText(Time[0],High[0]-0.3*DotLoc*Point,("CloseSell"+DoubleToStr(Time[0],0)),CharToStr(251),Magenta);
        PlaySound("alert.wav");
        OrdClose(OrderTicket(),OrderLots(),Ask,Slippage,Red);
      alerts(0, 0, CloseBuy, CloseSell,Ask,0,0,OrderTicket());
      return(0);
    }
    if (TradeBar==0)
    {
                SetText(Time[0],High[0]-0.3*DotLoc*Point,("CloseSell"+DoubleToStr(Time[0],0)),CharToStr(251),Magenta);      
        PlaySound("alert.wav");
        OrdClose(OrderTicket(),OrderLots(),Ask,Slippage,Red);
      alerts(0, 0, CloseBuy, CloseSell,Ask,0,0,OrderTicket());
      return(0);
    }
  

   }
  }
  
}
  
double MyStopLoss=0, MyTakeProfit=0;
int ticket=0;
  
  
  
//Should we open a position?
if (OpenPos0)
   {
       SetText(Time[0],High[0]+1*DotLoc*Point,("Sell"+DoubleToStr(Time[0],0)),CharToStr(234),Red);
       if (TakeProfit==0) MyTakeProfit=0; else MyTakeProfit=Bid-TakeProfit*Point;
    if (StopLoss==0) MyStopLoss=0; else MyStopLoss=Bid+StopLoss*Point;  
       PlaySound("alert.wav");
       ticket=OrdSend(Symbol(),OP_SELL,Ilo,Bid,Slippage,MyStopLoss,MyTakeProfit,OrderStr,MagicNumber,0,Red);
   alerts(OpenBuy, OpenSell, 0, 0,Bid,MyStopLoss,MyTakeProfit,ticket);
   OpenSell=0;
   return(0);
   }
   if (TradeBar==0)
   {
   SetText(Time[0],High[0]+1*DotLoc*Point,("Sell"+DoubleToStr(Time[0],0)),CharToStr(234),Red);  
       if (TakeProfit==0) MyTakeProfit=0; else MyTakeProfit=Bid-TakeProfit*Point;
    if (StopLoss==0) MyStopLoss=0; else MyStopLoss=Bid+StopLoss*Point;  
       PlaySound("alert.wav");
       ticket=OrdSend(Symbol(),OP_SELL,Ilo,Bid,Slippage,MyStopLoss,MyTakeProfit,OrderStr,MagicNumber,0,Red);  
   alerts(OpenBuy, OpenSell, 0, 0,Bid,MyStopLoss,MyTakeProfit,ticket);
   OpenSell=0;
   return(0);  
   }
  }
  if (OpenBuy==1 && AllowTrade==1) {
   if (NewBar==1 && TradeBar>0)
   {
       SetText(Time[0],Low[0]-0.3*DotLoc*Point,("Buy"+DoubleToStr(Time[0],0)),CharToStr(233),Lime);
       if (TakeProfit==0) MyTakeProfit=0; else MyTakeProfit=Ask+TakeProfit*Point;
       if (StopLoss==0) MyStopLoss=0; else MyStopLoss=Ask-StopLoss*Point;        
       PlaySound("alert.wav");
       ticket=OrdSend(Symbol(),OP_BUY,Ilo,Ask,Slippage,MyStopLoss,MyTakeProfit,OrderStr,MagicNumber,0,Lime);
   alerts(OpenBuy, OpenSell, 0, 0,Ask,MyStopLoss,MyTakeProfit,ticket);
   OpenBuy=0;
   return(0);
   }
   if (TradeBar==0)
   {
       SetText(Time[0],Low[0]-0.3*DotLoc*Point,("Buy"+DoubleToStr(Time[0],0)),CharToStr(233),Lime);
       if (TakeProfit==0) MyTakeProfit=0; else MyTakeProfit=Ask+TakeProfit*Point;
       if (StopLoss==0) MyStopLoss=0; else MyStopLoss=Ask-StopLoss*Point;        
       PlaySound("alert.wav");
       ticket=OrdSend(Symbol(),OP_BUY,Ilo,Ask,Slippage,MyStopLoss,MyTakeProfit,OrderStr,MagicNumber,0,Lime);
   alerts(OpenBuy, OpenSell, 0, 0,Ask,MyStopLoss,MyTakeProfit,ticket);
   OpenBuy=0;
   return(0);
   }
   
  }
  
}
  
  
  
for (i=0; i0 && (CurTime()-alertTime)>Periods)
    {
    if (_buy==1) {
    alertStr=alertStr+"Buy @ "+DoubleToStr(_op,Digits)+"; SL: "+DoubleToStr(_sl,Digits)+"; TP: "+DoubleToStr(_tp,Digits)+" at "+CurDate+" Order:"+DoubleToStr(_ticket,0)+".";
    alert(Symbol()," ",Period(), ": ",alertStr);
    if (SendEmail)
    {
       SendMail(Symbol()+" "+Period()+ ": ",Symbol()+" "+Period()+": "+alertStr);
    }
  

       Crepeat=Crepeat-1;
       alertTime=CurTime();
    }
  
    }
}
  
if (_sell==1)
{
    if (Crepeat==Repeat)
    {
       alertTime=0;
    }
    if (Crepeat>0 && (CurTime()-alertTime)>Periods)
    {
    if (_sell==1) {
       alertStr=alertStr+"Sell @ "+DoubleToStr(_op,Digits)+"; SL: "+DoubleToStr(_sl,Digits)+"; TP: "+DoubleToStr(_tp,Digits)+" at "+CurDate+" Order:"+DoubleToStr(_ticket,0)+".";
    alert(Symbol()," ",Period(), ": ",alertStr);
    if (SendEmail)
    {
       SendMail(Symbol()+" "+Period()+ ": ",Symbol()+" "+Period()+": "+alertStr);
    }
  

       Crepeat=Crepeat-1;
       alertTime=CurTime();
    }
  
    }
}
  
if (_exitsell==1)
{
    if (Crepeat==Repeat)
    {
    alertTime=0;
    }
  
if (Crepeat>0 && (CurTime()-alertTime)>Periods)
{
    if (_exitsell==1) {
    alertStr=alertStr+" Close Sell @ "+DoubleToStr(_op,Digits)+" at "+CurDate+" Order:"+DoubleToStr(_ticket,0)+".";
    alert(Symbol()," ",Period(), ": ", alertStr);
    if (SendEmail)
    {
       SendMail(Symbol()+" "+Period()+ ": ",Symbol()+" "+Period()+": "+alertStr);
    }
  

    Crepeat=Crepeat-1;
    alertTime=CurTime();
    }
  
}
  
}
  

if (_exitbuy==1)
{
    if (Crepeat==Repeat)
    {
       alertTime=0;
    }
    if (Crepeat>0 && (CurTime()-alertTime)>Periods)
    {
    if (_exitbuy==1) {
    alertStr=alertStr+" Close Buy @ "+DoubleToStr(_op,Digits)+" at "+CurDate+" Order:"+DoubleToStr(_ticket,0)+".";
    alert(Symbol()," ",Period(), ": ",alertStr);
    if (SendEmail)
    {
       SendMail(Symbol()+" "+Period()+ ": ",Symbol()+" "+Period()+": "+alertStr);
    }
  

       Crepeat=Crepeat-1;
       alertTime=CurTime();
    }
  
    }
}
  
if (_exitbuy==0 && _exitsell==0 && _buy==0 && _sell==0)  
{
    Crepeat=Repeat;
    alertTime=0;
}
  
}
//
  
  
  

//----
return;
}
  

//----------------------- PRINT COMMENT FUNCTION
void subPrintDetails()
{
    string sComment   = "";
    string sp         = "----------------------------------------n";
    string NL         = "n";
  string sDirection = "";
    sComment = "ccccccc" + NL;
    sComment = sComment + "StopLoss=" + DoubleToStr(StopLoss,0) + " | ";
    sComment = sComment + "TakeProfit=" + DoubleToStr(TakeProfit,0) + " | ";
    sComment = sComment + "TrailingStop=" + DoubleToStr(TrailingStop,0) + NL;   
    sComment = sComment + sp;   
    sComment = sComment + "Lots=" + DoubleToStr(Ilo,2) + " | ";
    sComment = sComment + "LastTrade=" + DoubleToStr(TradeLast,0) + NL;
    sComment = sComment + "sig_buy=" + DoubleToStr(sig_buy,Digits) + NL;
    sComment = sComment + "sig_sell=" + DoubleToStr(sig_sell,Digits) + NL;
    sComment = sComment + sp;  
    Comment(sComment);
}
  
  
  

int CntOrd(int Type, int Magic) {
//return number of orders with specific parameters
int _CntOrd;
_CntOrd=0;
for(int i=0;i
打赏