Problem managing orders when one curve crosses the other (ADX)

 

Hello! Im a total newbie, and I need a tip how to solve my (really easy) problem. I built a very simple EA in which, an open order is set, when in ADX indicator the Di+ crosses Di- from the bottom, and closes the order when either SL/TP is triggered, or Di- crosses the Di+ from above. The problem is that, once the SL or TP level is hit, and the Di+ curve is still above Di-, another trade is opened. What I want to do, is to make the EA to wait until the DI- goes over Di+ and trigger the trade again when Di+ goes above Di-. ( I thought about using the "while" to create a cycle). Can somebody give me a hint how can I solve this problem? I hope I was clear in explaining my problem, here is the code to my EA


int start()
{


double main; // main line
double plusDi; // line +DI
double minusDi; // line -DI
int ticket; // ticket number

main=iADX(0,0,14,PRICE_CLOSE,MODE_MAIN,0); // formula for the main line
plusDi=iADX(0,0,14,PRICE_CLOSE,MODE_PLUSDI,0); // fornmula for plus d
minusDi=iADX(0,0,14,PRICE_CLOSE,MODE_MINUSDI,0); // formula for minus d

if (main>20 && plusDi>minusDi && OrdersTotal() == 0) //condition

{ticket = OrderSend(Symbol(),OP_BUY,0.1, Ask,1, Bid-10*Point,
Bid+20*Point);}


if (plusDi<minusDi && OrdersTotal() == 1)// condition for closing the open trade

{OrderClose(ticket,0.1,Ask,1, Red);}

while(plusDi>minusDi)
Sleep(1000);


return(0);}


 
tomekbuka:

make the EA to wait until the DI- goes over Di+ and trigger the trade again when Di+ goes above Di-.


  1. https://www.mql5.com/en/forum/132351
 

Thanks William, I hope now I ll be able to cope with that!

 

Just one more thing William, I tried by all means to understand that code, you posted in the other article, but it is still quite vague for me, could you please make it a bit more explicit?

int start(){
   static int lastType=-1;
   if (BuyCondition  && lastType != OP_BUY){ lastType=OP_BUY; orderSend(buy); }
   if (SellCondition && lastType != OP_SELL){

 
No Slaves here, learn to code or pay someone.
Reason: