还是不懂,请帮忙看下我的程序。谢谢各位。

 

我现在有两个EA程序,分别运行两种货币对,程序中用红色画出来的部分,在两个程序中是完全一样的,我想分别执行两种货币,就是每种货币各开一单,按照他们各自的EA程序操作。

但问题出现了,有时候一种货币连续的开两单,比如说13:00,欧元就连续开两单,这样另外一种货币就不开仓了。我是刚刚在学写EA的,所以,有人建议我管理symbol的数量,小于1就不开这种货币的单。可是我不懂应该加在哪一段。请大家帮忙一下了。十分感谢。

totalopen=OrdersTotal();
if (totalopen<2)
{
if((MacdPPrevious-SignalPPrevious)<0 && diff>dea)
{
ticket=OrderSend(Symbol(),OP_BUY,Lots,ask,3,0,0,"try2 sample",999,0,Green);
if(ticket<0)
{RefreshRates();}
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("BUY order opened : ",OrderOpenPrice());

}

else Print("Error opening BUY order : ",GetLastError());
return(0);
}

if((MacdPPrevious-SignalPPrevious)0 && diff<dea)
{
ticket=OrderSend(Symbol(),OP_SELL,Lots,bid,3,0,0,"try2 sample",999,0,Red);
if(ticket>0)
{
if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES)) Print("SELL order opened : ",OrderOpenPrice());
}

else Print("Error opening SELL order : ",GetLastError());
return(0);
}
return(0);
}
// it is important to enter the market correctly,
// but it is more important to exit it correctly...

for(cnt=0;cnt<totalopen;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS,MODE_TRADES);
if(OrderType()<=OP_SELL && // check for opened position
OrderSymbol()==Symbol()) // check for symbol
{
if(OrderType()==OP_BUY) // long position is opened
{
if((diffpprevious-deapprevious)<0 && diff<dea )
{
OrderClose(OrderTicket(),OrderLots(),bid,3,Violet);
Print("30mins buy cross",OrderClosePrice());
return(0); // exit
}
if((MacdPPrevious-SignalPPrevious)>0 && diff>dea &&(TimeCurrent()-OrderOpenTime())>300)
{
if( OrderStopLoss()!=NormalizeDouble(open-modifysl*point,digits)&& OrderTakeProfit()!=NormalizeDouble(open+modifytp*point,digits))
}

}
else
{
if(OrderType()==OP_SELL)
{
if((diffpprevious-deapprevious)*(diffprevious-deaprevious)<0 && diff>dea &&(TimeCurrent()-OrderOpenTime())>300)
{
OrderClose(OrderTicket(),OrderLots(),ask,3,Violet);
Print("30mins sell cross",OrderClosePrice());
return(0); // exit
}

if((MacdPPrevious-SignalPPrevious)<0 && diff<dea &&(TimeCurrent()-OrderOpenTime())>300)
{
if( OrderStopLoss()!=NormalizeDouble(open+modifysl*point,digits )

{
OrderModify(OrderTicket(),OrderOpenPrice(),NormalizeDouble(open+modifysl*point,digits),NormalizeDouble(open-modifytp*point,digits),0,Green);
}
}
}

return(0);
} ..........

 

把第二行

if (totalopen<2)

换为下面的代码, 就行了

int canbs =0;

for(cnt=0;cnt<totalopen;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol()) // check for symbol 判断已开的单数

canb++;

}

if (canb==0) // 每种货币最多开一单

 
DxdCn 写道 >>

把第二行

if (totalopen<2)

换为下面的代码, 就行了

int canbs =0;

for(cnt=0;cnt<totalopen;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol()) // check for symbol 判断已开的单数

canb++;

}

if (canb==0) // 每种货币最多开一单

帮人帮到家,赞一个!

 
DxdCn 写道 >>

把第二行

if (totalopen<2)

换为下面的代码, 就行了

int canbs =0;

for(cnt=0;cnt<totalopen;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol()) // check for symbol 判断已开的单数

canb++;

}

if (canb==0) // 每种货币最多开一单

或许上述代码尚不能解决您的问题。
因为代码:
for(cnt=0;cnt<totalopen;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol()) // check for symbol 判断已开的单数

canb++;

}
在二个图表中都会运算,并且结果相同,而且变量canb在start()函数体内定义不利于对不同货币对的识别。

因此,我建议您在程序的一开始就定义二个变量来统计不同货币的开仓情况,比如canbEUR和canbGBP,然后把上述canb++;代码行改为:

if(Symbol()=="EURUSD") { canbEUR++; }
if(Symbol()=="GBPUSD") { canbGBP++; }

其他方面相信您能够完善了。而且它还能扩大到更多的货币对,供参考。

 
DxdCn 写道 >>

把第二行

if (totalopen<2)

换为下面的代码, 就行了

int canbs =0;

for(cnt=0;cnt<totalopen;cnt++)
{
OrderSelect(cnt, SELECT_BY_POS,MODE_TRADES);
if(OrderSymbol()==Symbol()) // check for symbol 判断已开的单数

canb++;

}

if (canb==0) // 每种货币最多开一单

谢谢您,我在试一下吧。十分感谢!
 
hexinchen 写道 >>

帮人帮到家,赞一个!

还是好人多嘛,,您也一样,,谢了,,

 
if(OrderSymbol()==Symbol()) // check for symbol 判断已开的单数

canb++;

}
在二个图表中都会运算,并且结果相同 ???

BBL 你好像没看懂代码,

都会运算,但结果不同, if 判断 已开仓是当前图表窗口的货币时,才canb++; 的

 
DxdCn 写道 >>
if(OrderSymbol()==Symbol()) // check for symbol 判断已开的单数

canb++;

}
在二个图表中都会运算,并且结果相同 ???

BBL 你好像没看懂代码,

都会运算,但结果不同, if 判断 已开仓是当前图表窗口的货币时,才canb++; 的

你说得对,谢谢!

原因: