Sequential precedence of indicators in an EA ? Who can help ?


Hi to you all in the forum,

I am now experimenting and studying mql5 for several months and despite a lot of research I could not find an example for my problem.

The trading idea is that a buy signal occurs if one of two moving average signals are positive and the RSI has first fallen below 30, then risen above 60 and then fallen to below 45 again before it rises to 50 or above.

The problem is to determine that the RSI conditions have to be fulfilled one after the other in a sequential precedence. Has anyone of you an idea how to solve this problem? I have copied my EA for you so that you can see my coding. Thanks a lot !



//|                                                       André .mql4|

//|                                          Copyright 2016, Andre   |

//|                                    |


#property copyright "Copyright 2016, Andre"

#property link      ""

string signal;

string EURUSD;

int zaehler;

extern int MagicNumber = 55557;

int ticket;


//| Expert initialization function                                   |


int OnInit()







//| Expert deinitialization function                                 |


void OnDeinit(const int reason)





//| Expert tick function                                             |


void OnTick()






//| expert start function                                            |


int start()




//| Buy Signal                                                          |


double ma = iMA(EURUSD,0,135,0,MODE_SMA,PRICE_CLOSE,1);

double mat1 = (iMA(EURUSD,0,135,0,MODE_SMA,PRICE_CLOSE,0))/(iMA(NULL,0,135,1,MODE_SMA,PRICE_CLOSE,1));

double mat30 = (iMA(EURUSD,0,135,30,MODE_SMA,PRICE_CLOSE,0))/(iMA(NULL,0,135,31,MODE_SMA,PRICE_CLOSE,1));

double r30 = iRSI(EURUSD,30,18,PRICE_CLOSE,0);

double r60 = iRSI(EURUSD,0,18,PRICE_CLOSE,0);

double r45 = iRSI(EURUSD,0,18,PRICE_CLOSE,0);

double r50 = iRSI(EURUSD,0,18,PRICE_CLOSE,0);

int r30min = iLowest(r30,0,3,100,25);

int r60max = iHighest(r60,0,3,80,10);

int r40min = iLowest(r45,0,3,20,1);

if(mat1 > 0 || mat30 > 0 && r30min <= 30 && r60max >= 60 && r40min <= 45 && r50 > 50)


    signal = "long";


     else   {

   signal = "no buy";



Keith Watford  
int r30min = iLowest(r30,0,3,100,25);

int r60max = iHighest(r60,0,3,80,10);

int r40min = iLowest(r45,0,3,20,1);

The 1st parameter is a string(the symbol) you have doubles.

Why do you have OnTick() AND start() ??

string EURUSD;

Where do you assign a value to this ??

Sorry to be blunt, but you are trying to code way beyond your knowledge threshold. Try something simpler first.

Fernando Carreiro  

Why are you double post/thread? You had already started a thread with the same thing here:

On that thread, both WHRoeder and myself posted, yet you decided to ignore it and now you have started a new thread with just slightly different post (use of SRC and using "mq4" extension), but the rest is the same and you chose to ignore most of our original comments.

Please don't just start new threads on a whim. You should continue with the line of thought of a single thread so that there is a continual evolution to the conversation and the poster's comments.

Also, Gumrai is correct! Your level of knowledge and experience is not sufficient to attempt what you are trying. You should first learn the basics and study the many examples available in the Code Base before trying to code something of your own. Also pay special attention to updated elements of MQL4.

Mary Clark  

You will need a bunch of booleans.

 RSI has first fallen below 30, then risen above 60 and then fallen to below 45 again before it rises to 50 or above. 

 if (!rsiIsBelow30 && rsiValue<30)

    rsiIsBelow30 = true;

if (rsiIsBelow30 && !rsiIsAbove60 && rsiValue > 60)

    rsiIsAbove60 = true; 

if (rsiIsBelow30 && rsiIsAbove60 && rsiValue < 45)

    rsiIsBelow45 = true;

// then check you entry logic and reset the booleans for the next signal

 if (rsiIsBelow30 && rsiIsAbove60 && rsiIsBelow45 && rsiValue > 50)



      rsiIsBelow30 = false;rsiIsAbove60=false;rsiIsBelow45 = false;