I recommend pasting the code in here using the SRC button above.
Hello ubzen just had an thought over it think, we should give the condition twice then it might execute well.
Here : if (((EMA20>EMA50 && EMA20<=EMA50))){
OpenBuy(EMA50);
return(0);
}
if (((EMA20<EMA50 && EMA20>=EMA50 ))){
OpenSell(EMA50);
return(0);
}
}
if (prevCountBars != Bars && prevCountBars !=0 && ExistPositions()) {
if(OrderType()==OP_BUY){
if(EMA20<EMA50){
CloseBuy();
}
}
if(OrderType()==OP_SELL){
if(EMA20>EMA50){
CloseSell();
}
And here is the code previously was mention :
ticket=OrderSend(Symbol(),OP_BUY,ldLot,Ask,0,0,0,lsComm,MAGIC,0,Blue);
Sleep(1000);
OrderSelect(ticket,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),ldStop,ldTake,0,Blue);
//for buy
//for sell
ticket=OrderSend(Symbol(),OP_SELL,ldLot,Bid,0,0,0,lsComm,MAGIC,0,Red);
Sleep(1000);
OrderSelect(ticket,SELECT_BY_TICKET);
OrderModify(OrderTicket(),OrderOpenPrice(),ldStop,ldT
Or paste it without the SRC button I guess...
Try removing the return(0); after your Buy and Sell... once these are executed, the EA goes back to wait for the next tick so will never go onto the conditions to close... or once a buy is triggered, select all Sells and close them inside that condition.
hth
V
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello friends this is checkmail and am trying to build an simple EA based on MA curves, but the problem is that the EA
is not opening order in other direction when at cross it only closes the current position.
Means if have an open order buy, at an cross it will close the buy but doesn't open an sell immediately.
Can anyone give me expert advice in it, will send the order() code.Am also using sleep() function is it affecting it.