RSI entry.

 

Hello I am requesting your help on this piece of code. The idea is the EA should open both long and sell when the rsi is at 50 level. Note 50 level not greater or less than the level. Below is my code but if I use the equals sign (==) the orders are not triggered. Someone help

string GetEntrySignal()
 {
       string signal = "";
       double prev_rsi = 0;
       double curr_rsi = 0;
    
       double rsi = iRSI(_Symbol,PERIOD_CURRENT,RSIperiod,RSIprice,0);
     
       //buy
      if(rsi == rsi_level) signal = BUYSIGNAL;
      
      //sell
      if(rsi == rsi_level)signal= SELLSIGNAL;
      
   
     
                                         
               
       return signal;
 }  
 
      if(rsi == rsi_level) signal = BUYSIGNAL;

Doubles are rarely equal. Understand the links in:
          The == operand. - MQL4 programming forum #2 (2013)

 
Ernest Akoyi:

Hello I am requesting your help on this piece of code. The idea is the EA should open both long and sell when the rsi is at 50 level. Note 50 level not greater or less than the level. Below is my code but if I use the equals sign (==) the orders are not triggered. Someone help

Like William rightly said, the probability of getting rsi == 50 is low 
You can try coding it as a cross , that’s what I do 
 
William Roeder #:

Doubles are rarely equal. Understand the links in:
          The == operand. - MQL4 programming forum #2 (2013)

Thank you

 
Chioma Obunadike #:
Like William rightly said, the probability of getting rsi == 50 is low 
You can try coding it as a cross , that’s what I do 

This is what I have done and it's working. Thank you

 
Ernest Akoyi:
string GetEntrySignal() {        string signal = "";        double prev_rsi = 0;        double curr_rsi = 0;             double rsi = iRSI(_Symbol,PERIOD_CURRENT,RSIperiod,RSIprice,0);             //buy       if(rsi == rsi_level) signal = BUYSIGNAL;              //sell       if(rsi == rsi_level)signal= SELLSIGNAL;                                                                               return signal; }  
string GetEntrySignal()
 {
       string signal = "";
       double prev_rsi = 0;
       double curr_rsi = 0;
      double rsi_Buy_Level=70;
      double rsi_Sell_Level=30;
    
       double rsiprev = iRSI(_Symbol,PERIOD_CURRENT,RSIperiod,RSIprice,1);
       double rsicurr = iRSI(_Symbol,PERIOD_CURRENT,RSIperiod,RSIprice,0);

     
       //buy
     if(rsiprev<rsi_Buy_Level && rsicurr>rsi_Buy_Level) signal = BUYSIGNAL;
// Sell
     if(rsiprev>rsi_Sell_Level && rsicurr<rsi_Sell_Level) signal = SELLSIGNAL;


   
      //if(rsi == rsi_level) signal = BUYSIGNAL;
      
      //sell
      i//f(rsi == rsi_level)signal= SELLSIGNAL;
      
   
     
                                         
               
       return signal;
 }  
 
Mehmet Bastem #:

Thank you for your assistance I got the solution

Reason: