Why my EA doesn't trade - RSI divergence

 

Hi,


you will find here-attached my last EA.

It is coded exactly on the same scheme as all my others EA that are running correctly.

This one has no alert and no error but does not trade or stops after the first trade.


There is something somewhere that I do not see and that makes it fail.


It's only a first draft and the parameters have to be adjusted but I want to explore this way.


Thanks for your help


Lionel

Files:
 
Could you have a look and tell me what's wrong that I don't see.
When you work too much on an EA you do not see the evidence

no error, no alert, but stops after the first trade or do not trade at all

Thank's for your help

Lionel




//+------------------------------------------------------------------+
//|                                               Divergence RSi.mq4 |
//|                                                     Lionel HOUBA |
//+------------------------------------------------------------------+
//|                                                    HOUBA trading |
//+------------------------------------------------------------------+
#property copyright "HOUBA trading."
#property link      "HOUBA trading."

//---- input parameters

extern double lotsize             = 0.1;
extern double MAXORDERS           = 1;
int ticket;
extern double fastMovingPeriod    = 5;
extern double fastmovingshift     = 0;
extern double RSI_value           = 14;
extern double hour_start          = 0;
extern double hour_end            = 24;
extern double stop_loss           = 0.015;
extern double take_profit         = 0.015;
double RSI;

return;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
//----
   return(0);
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
   int start()
  {
//---- go trading only for first tiks of new bar

   if(Volume[0]>1 ) return;
    
//---- BUY CONDITIONS-------------------------------------------------     

//----definition of RSI :

   RSI=(iRSI(NULL,0,RSI_value,PRICE_OPEN,0));
   
//---- limitation of the number of open positions  

   if(OrdersTotal() < MAXORDERS)

//---- check trading hours GMT

   if (Hour()>= hour_start)
   if (Hour()<= hour_end) 
     
//---- if the MA decreases :
   
   if (iMA(NULL,0,fastMovingPeriod,fastmovingshift,MODE_EMA,PRICE_OPEN,1)
   >iMA(NULL,0,fastMovingPeriod,fastmovingshift,MODE_EMA,PRICE_OPEN,0))
   
//---- and if the RSI increases and then creates a divergence with the MA :

   if(iRSI(NULL,0,RSI_value,PRICE_OPEN,1)

//---- and if the RSI is over 70

   if (RSI>=70)
   
   //----send the order buy (long)  
   
   ticket=OrderSend(Symbol(),OP_BUY,lotsize,Ask,3,Open[0]-stop_loss,Open[0]+take_profit,"",0,0,Green);
  
//---- close open position buy (long) if the MA increases
 
   if (iMA(NULL,0,fastMovingPeriod,fastmovingshift,MODE_EMA,PRICE_OPEN,1)
   

   if (ticket>0)
   
   if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
   
   OrderClose(OrderTicket(),OrderLots(),Bid,3,Red);
         
  
  
//---- SELL CONDITIONS------------------------------------ 

//----definition of RSI :

   RSI=(iRSI(NULL,0,RSI_value,PRICE_OPEN,0));
   
//---- limitation of the number of open positions 
 
   if(OrdersTotal() < MAXORDERS)    
   
//---- check trading hours GMT

   if (Hour()>= hour_start)
   if (Hour()<= hour_end) 

//---- if the MA increases

   if (iMA(NULL,0,fastMovingPeriod,fastmovingshift,MODE_EMA,PRICE_OPEN,1)
   
   
//---- and if the RSI decrease and then creates a divergence with the MA : 

   if(iRSI(NULL,0,RSI_value,PRICE_OPEN,1)>iRSI(NULL,0,RSI_value,PRICE_OPEN,0)) 
   
//---- and if the RSI is under 30

   if (RSI<=30)
  
//----send an order sell  
   
   ticket=OrderSend(Symbol(),OP_SELL,lotsize,Bid,3,Open[0]+stop_loss,Open[0]-take_profit,"",0,0,Green);
  
//---- close open position sell
   
   if (iMA(NULL,0,fastMovingPeriod,fastmovingshift,MODE_EMA,PRICE_OPEN,1)
   >iMA(NULL,0,fastMovingPeriod,fastmovingshift,MODE_EMA,PRICE_OPEN,0))
  
   if (ticket>0)
   
   if(OrderSelect(ticket,SELECT_BY_TICKET,MODE_TRADES))
  
   OrderClose(OrderTicket(),OrderLots(),Ask,3,Red);
   
  
   
    }
 
leyoye1 wrote >>

Hi

I see that you have : if(OrdersTotal() < MAXORDERS) and have set MAXORDERS = 1; which means you can never have a second order opened.

As to why it never opens any orders, it maybe that other conditions are not satisfied.

HTH

Keith

 

Hi Keith,


Thank you for your post.


I think this line means

"no more than one (1) order in same time"

it's the maximum number of simultaneous open position you can have.


I have it in all my other EAs, and that's the way it worked till today, but maybe am I wrong, I'm not a professional programmer.


Lionel

 
leyoye1 wrote >>

Hi Keith,

Thank you for your post.

I think this line means

"no more than one (1) order in same time"

it's the maximum number of simultaneous open position you can have.

I have it in all my other EAs, and that's the way it worked till today, but maybe am I wrong, I'm not a professional programmer.

Lionel

Yeah I wish I was a professional programmer, life would be so much easier. None the less, as I interpret it means "no more than one order ever",once you have one open position OrdersTotal() returns one which is not less than Maxorders and therefore your "if" will return false and you will exit your logic routine.

Easy test change Maxorders to 3 or 4 and see what happens,

good luck

Keith

 

OK I found my mistake, I forgot a comparison here :


//---- and if the RSI increases and then creates a divergence with the MA :


if(iRSI(NULL,0,RSI_value,PRICE_OPEN,1)________________________


But anyhow, this way to calculate a divergence is wrong, I must use some tops and bottoms certainly with the function ihighest() and lowest.


Keith, I confirm ordertotal() gives the number of simultaneous order, and not the max ever : see underneath the meta editor definition:


int OrdersTotal( )

Returns market and pending orders count.


MAXORDER is an extern value I enter myself, it is not a function.


Nevertheless I appreciate your post.

We learn by our mistakes...


Lionel

France