# Code help looping strategies for MQL4

281

I have 3 strategies and I want my EA to open positions in a loop as follows.

The buy strategies are X , Y and Z.

If  condition X is satisfied, place buy order, then wait until that order is closed. Once order X is closed( in profit or loss) look for condition Y and again wait until this order is closed. When closed, do the same for condition Z.

‌Once Z is done go back to condition X and repeat  process as above. The or function || is not  suitable as a strategy may be repeated many times without giving others a chance.

A‌ very short code like if (x ??? Y??? Z????) ... Open buy order,..  will be appreciated as i'm new in coding.

T‌hanks. ‌

16104

enum strategies {X, Y, Z};
strategies strategy = X;
void OnTick(void){‌
if(get_open_count() == 0){
switch(strategy){
case X: if(testX() ) strategy = Y;
break
case Y: if(testY() ) strategy = Z;
break
case Z: if(testZ() ) strategy = X;
break
}
}
else // handle trailing etc.
}
281

whroeder1:
enum strategies {X, Y, Z};
strategies strategy = X;
void OnTick(void){‌
if(get_open_count() == 0){
switch(strategy){
case X: if(testX() ) strategy = Y;
break
case Y: if(testY() ) strategy = Z;
break
case Z: if(testZ() ) strategy = X;
break
}
}
else // handle trailing etc.
}

Thanks whroeder1

‌My buy code looks like this on void on tick.Note I use MT4 not MT5

‌ if(X. or y.. or z.. condition is met &&Count.Buy() == 0)

{

}

‌ Could ypu explain more where I would place my enumeration for your function above?

T‌hanks.

16104

 prweza: Could ypu explain more where I would place my enumeration for your function above? Your code goes inside the testX, testY, testZ functions.
281

okay thanks where do i put the code

enum strategies {X, Y, Z};
strategies strategy = X;

‌Do  i put this on the input variables section t the beginning of the  programme?

I‌'m getting errors when I do that.

T‌hanks.