Code help

 

Hi this is my 1st code I've complied without errors or warnings, however this EA code doesn't seem to work, any advise?

//+------------------------------------------------------------------+
//|                                                           MA.mq4 |
//|                                                          The One |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "The One"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
//+------------------------------------------------------------------+
//| Expert initialization function                                   |
//+------------------------------------------------------------------+
extern int TakeProfit = 200;
extern int StopLoss = 50;
extern int FastMa = 8;
extern int SlowMa = 21;
extern int RSI = 10;
extern int LotSize = 005;

int OnInit()
  {
//---
//---
  return(INIT_SUCCEEDED);
  }

void OnDeinit(const int reason)
  {
//---
  }
   
void OnTick()
  {
double PreviousSlowMA = iMA (NULL, 0, SlowMa, 0, MODE_EMA, PRICE_CLOSE, 2);
double CurrentSlowMA = iMA (NULL, 0, SlowMa, 0, MODE_EMA, PRICE_CLOSE, 1);
double PreviousFastMA = iMA (NULL, 0, FastMa, 0, MODE_EMA, PRICE_CLOSE, 2);
double CurrentFastMA = iMA (NULL, 0, FastMa, 0, MODE_EMA, PRICE_CLOSE, 1);
double PreviousRSI = iRSI (NULL, 0, RSI, PRICE_MEDIAN, 2);
double CurrentRSI = iRSI (NULL, 0, RSI, PRICE_MEDIAN, 1);

if(PreviousFastMA < PreviousSlowMA && CurrentFastMA > CurrentSlowMA)
{
if(PreviousRSI < 50.0 && CurrentRSI > 50.00)
{
int ticket=OrderSend(Symbol(), OP_BUY, LotSize, Ask, 5, Ask-(StopLoss*Point), Ask + (TakeProfit*Point), NULL);
if(ticket<0)
{
 Print("OrderSend failed with error #",GetLastError()); 
     } 
   else 
      Print("OrderSend placed successfully");  
}}

if(PreviousFastMA > PreviousSlowMA && CurrentFastMA < CurrentSlowMA)
{
if(PreviousRSI > 50.0 && CurrentRSI < 50.00)
{
int ticket=OrderSend(Symbol(), OP_SELL, LotSize, Bid, 5, Bid + (StopLoss*Point), Bid-(TakeProfit*Point), NULL);
if(ticket<0)
{
 Print("OrderSend failed with error #",GetLastError()); 
     } 
   else 
      Print("OrderSend placed successfully");  
}}

  }
//-----------------------------------------------------------+     
 

Please explain what you mean by "doesn't work"

Are all conditions satsified, but it doesn'y open a trade?

If so, what was the error?

 
  1. "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
  2. Your condition is that the MA cross and the RSI cross must occur on the same bar, which is unlikely.
    if(PreviousFastMA < PreviousSlowMA && CurrentFastMA > CurrentSlowMA)
    {
    if(PreviousRSI < 50.0 && CurrentRSI > 50.00)
    What you want is both conditions correct and open on a change of signal (to prevent multiple opens.)
    static bool isBuy=false, isSell=false;
    bool wasBuy=isBuy, wasSell=isSell;
    isBuy  = CurrentFastMA > CurrentSlowMA && CurrentRSI > 50.00;
    isSell = CurrentFastMA < CurrentSlowMA && CurrentRSI < 50.00;
    if(isBuy && !wasBuy)
 
WHRoeder:
  1. "Doesn't work" is meaningless - just like saying the car doesn't work. Doesn't start, won't go in gear, no electrical, missing the key, flat tires - meaningless. There are no mind readers here.
  2. Your condition is that the MA cross and the RSI cross must occur on the same bar, which is unlikely.
    What you want is both conditions correct and open on a change of signal (to prevent multiple opens.)
Thanks for your help, I've tried to alter this with your code above but I'm still having problems with this, I'm going to take this code back to the drawing board.
 
if(PreviousFastMA < PreviousSlowMA && CurrentFastMA > CurrentSlowMA)
{
if(PreviousRSI < 50.0 && CurrentRSI > 50.00)
{
In this case you need double cross at same bar. MA and rsi. Try like this
if(PreviousFastMA < PreviousSlowMA && CurrentFastMA > CurrentSlowMA)
{
if(CurrentRSI > 50.00)
{
Reason: