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 !

Andre

//+------------------------------------------------------------------+

//|                                                       André .mq5 |

//|                                          Copyright 2016, Andre   |

//|                                             https://www.mql5.com |

//+------------------------------------------------------------------+

#property copyright "Copyright 2016, Andre"

#property link      "https://www.mql5.com"

string signal;

string EURUSD;

int zaehler;

extern int MagicNumber = 55557;

int ticket;

//+------------------------------------------------------------------+

//| Expert initialization function                                   |

//+------------------------------------------------------------------+

int OnInit()

  {

//---

//---

   return(INIT_SUCCEEDED);

  }

//+------------------------------------------------------------------+

//| 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";

      }

   return(0);

}
Automated Trading and Strategy Testing
Automated Trading and Strategy Testing
  • www.mql5.com
MQL5: language of trade strategies built-in the MetaTrader 5 Trading Platform, allows writing your own trading robots, technical indicators, scripts and libraries of functions
 
Your code is for MT4 ( even the name is .mq5 ), do you want to use it for MT4 or MT5?
 
Thanks for your reply. I did not know that there is such a big difference. If this is the case then of course I would like to continue my existing coding which means Mql4. 
Reason: