下载MetaTrader 5
要添加评论,请登录注册
他们已经使用工作服务获得利润。您可以加入他们!
wangjh2004
40
wangjh2004 2007.05.30 14:35 
首先,感谢ROSH先生上几次给予的答复. 其次,上一次的答复没有解决这个下单的问题,以下这段代码是计算累计净多(空)单量的, 加入到程序中后,程序不能交易(若删除掉可以交易),我是新手,找不出原因,再请教,谢谢!
//==================================================================================================
int res =0;
int buyNumber =0;
int sellNumber=0;
for (int i=OrdersTotal()-1;i>=0;i--)
{
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);

//==================================================================================================
Rashid Umarov
管理员
6605
Rashid Umarov 2007.05.30 15:42  
It is need write OrderSelect() before other trading functions. See https://docs.mql4.com/cn/trading/OrderSelect

nt 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);
wangjh2004
40
wangjh2004 2007.05.30 17:00  

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);
}
}

/
要添加评论,请登录注册