Mr.ROSH:谢谢你的热心帮助,但是这个EA仍然没有交易,能否帮我整体的代码检查一下?为多次打搅而万分谢谢!

 

Mr.ROSH:
谢谢你的热心帮助,加了第三段代码后,尽管在您的帮助下,修正了多次, 但是这个EA仍然没有交易, 我没办法恢复它的交易功能,能否帮我整体的代码检查修改一下?谢谢!
extern int MagicNumber=123456;

extern int K1 = 19;
extern int D1 = 7;
extern int S1 = 9;
extern double a = 30;

extern int TakeProfit = 10;

extern double Lots = 0.1;
extern int maxopen = 5;
extern int maxlots = 20;

int myBars;
double k0, d0, k1, d1;
string text="EA10#, M1";
//=============================================================================================================
int start()
{
k0 =iStochastic(NULL,0,K1,D1,S1,MODE_SMA,0,MODE_MAIN,1);
d0 =iStochastic(NULL,0,K1,D1,S1,MODE_SMA,0,MODE_SIGNAL, 1);
k1 =iStochastic(NULL,0,K1,D1,S1,MODE_SMA,0,MODE_MAIN,2);
d1 =iStochastic(NULL,0,K1,D1,S1,MODE_SMA,0,MODE_SIGNAL, 2);
//==================================================================================================
int res =0;
int buyNumber =0;
int sellNumber=0;
for (int i=OrdersTotal()-1;i>=0;i--)
{
if (!OrderSelect(i,SELECT_BY_POS)) continue;
if (MagicNumber==0 || (OrderMagicNumber()==MagicNumber && MagicNumber!=0))
{
switch(OrderType())
{
case OP_BUY: buyNumber++;break;
case OP_SELL: sellNumber++;break;
}
}
}
res=MathAbs(buyNumber-sellNumber);
return(res);

//==================================================================================================
if(Bars!=myBars)
{
myBars=Bars;
if( res>maxopen &&
OrdersTotal()>maxlots) return(0);

if( k1<a && d1<a && k1<d1 && k0>d0 )
{ OrderSend(Symbol(), OP_BUY, Lots,Ask, 3, 0,Ask+TakeProfit*Point, text,2006, 3, Red);
PlaySound("alert. wav");
}

if( k1>100-a && d1>100-a && k1>d1 && k0<d0 )
{ OrderSend(Symbol(), OP_SELL, Lots, Bid,3, 0,Bid-TakeProfit*Point, text, 2006, 3,Blue);
PlaySound("alert. wav");
}
return(0);
}
}

 
Why you don't use MQL4 button?

extern int MagicNumber=123456;
 
extern int       K1        = 19;
extern int       D1        = 7;
extern int       S1        = 9;
extern double    a         = 30;
 
extern int   TakeProfit    = 10;
 
extern double  Lots        = 0.1;
extern int    maxopen      = 5;
extern int    maxlots      = 20;
 
int myBars;
double k0, d0, k1, d1;
string text="EA10#, M1";
 
//==================================================================================================
int GetOrdersNumber()
{
int res =0;
int buyNumber =0;
int sellNumber=0;
   for (int i=OrdersTotal()-1;i>=0;i--)
         {
         if (!OrderSelect(i,SELECT_BY_POS)) continue;
         if (MagicNumber==0 || (OrderMagicNumber()==MagicNumber && MagicNumber!=0))
             {
               switch(OrderType())
                {
                 case OP_BUY: buyNumber++;break;
                 case OP_SELL: sellNumber++;break;
                }
             }
         }
   res=MathAbs(buyNumber-sellNumber);
   return(res);
}
//============================================================================================================= 
int start()  
{
   k0   =iStochastic(NULL,0,K1,D1,S1,MODE_SMA,0,MODE_MAIN,1);
   d0   =iStochastic(NULL,0,K1,D1,S1,MODE_SMA,0,MODE_SIGNAL,1);
   k1   =iStochastic(NULL,0,K1,D1,S1,MODE_SMA,0,MODE_MAIN,2);
   d1   =iStochastic(NULL,0,K1,D1,S1,MODE_SMA,0,MODE_SIGNAL,2);
 
 
 
//==================================================================================================
   if(Bars!=myBars)
      {
      myBars=Bars;
      if(  GetOrdersNumber()>maxopen ) return(0);
     
      if(  k1<a && d1<a && k1<d1 && k0>d0  )
            {  OrderSend(Symbol(),OP_BUY,Lots,Ask,3,0,Ask+TakeProfit*Point,text,2006,3,Red);
               PlaySound("alert.wav");
            }
 
      if(  k1>100-a && d1>100-a && k1>d1 && k0<d0   )
            {  OrderSend(Symbol(),OP_SELL,Lots,Bid,3,0,Bid-TakeProfit*Point,text,2006,3,Blue);
               PlaySound("alert.wav");
            }
      return(0);
      }
}