How to use iRSI function to get the value of RSI on the last bar in a chart

MT5.2014
59
MT5.2014  

Hi guys,

I used iRSI function  in following format

int  iRSI(
   string              symbol,            // symbol name
   ENUM_TIMEFRAMES     period,            // period
   int                 ma_period,         // averaging period
   ENUM_APPLIED_PRICE  applied_price      // type of price or handle
   );


in an indicator to get the value of RSI on the last bar of a chart, but it did not work, does it need extra code or I am doing something wrong.

Thanks 

Alain Verleyen
41787
Alain Verleyen  
What didn't work ? Please show your code if you need coding help.
MT5.2014
59
MT5.2014  
Alain Verleyen:
What didn't work ? Please show your code if you need coding help.
It does not return the value of RSI, it returns 10 even when I changed the symbol or timeframe
MT5.2014
59
MT5.2014  
MT5.2014:
It does not return the value of RSI, it returns 10 even when I changed the symbol or timeframe
#property indicator_chart_window
#property indicator_buffers 1
#property indicator_plots   1
double iRSIBuffer[];
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])

      
{
         CopyBuffer(iRSI(_Symbol,PERIOD_H4,14,PRICE_CLOSE),0,0,1,iRSIBuffer);
         double irsiv = iRSIBuffer[0];
         Comment (irsiv);

         if(irsiv<30.00)
         {
            Alert("Buy");
         }         
      
   return(rates_total);
}
it shows the comment (irsiv value) correctly, but it does not show the alert correctly (the if clause does not work)
eestrada
5
eestrada  
MT5.2014:
it shows the comment (irsiv value) correctly, but it does not show the alert correctly (the if clause does not work)

Hi dude, I have the same issue, could you make it work?

William Roeder
24800
William Roeder  
eestrada: Hi dude, I have the same issue, could you make it work?

What part of the posted code (MT5.2014 2015.06.14 12:09 ) was unclear?

Skester96
63
Skester96  

I'm having the same proble with my code. It just prints out 10.0 constantly, also if I try it with iMA



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

//| Expert initialization function                                   |

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

int OnInit()

  {

//---

   

//---

   return(INIT_SUCCEEDED);

  }

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

//| Expert deinitialization function                                 |

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

void OnDeinit(const int reason)

  {

//---

   

  }

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

//| Expert tick function                                             |

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

void OnTick()

  {

//---



  

   double rsi = iRSI(NULL,0, 14, PRICE_CLOSE); 

   //double movingAverage = iMA(NULL,0,15,0,MODE_SMA,PRICE_MEDIAN);

   

   Alert(rsi); 

 

   

  }

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


William Roeder
24800
William Roeder  
Skester96: I'm just starting to use MQL5 and when I try to call the rsi, my terminal just prints 10 constanly.

Of course, it does.

  1. What does iRSI return?
  2. Why are you calling it outside of OnInit?
Keith Watford
Moderator
30417
Keith Watford  
Skester96:

I'm just starting to use MQL5 and when I try to call the rsi, my terminal just prints 10 constanly. Here is the sample code:


Read the documentation

https://www.mql5.com/en/docs/indicators/irsi

Documentation on MQL5: Technical Indicators / iRSI
Documentation on MQL5: Technical Indicators / iRSI
  • www.mql5.com
//|                                                    Demo_iRSI.mq5 | //|                        Copyright 2011, MetaQuotes Software Corp. | //|                                             https://www.mql5.com | "The method of creation of the handle is set through the 'type' parameter (function type...
lerche
25
lerche  
Keith Watford:

Read the documentation

https://www.mql5.com/en/docs/indicators/irsi

Unfortunately the example in the documetation is a bit overkill for newbies. I was struggeling with the same issue.


IMHO the following article has a pretty good explanation for this issue:

https://www.mql5.com/en/articles/43

Have a look into the section: Connecting indicators

How to call indicators in MQL5
How to call indicators in MQL5
  • www.mql5.com
In MQL5 there are several ways to call indicators, and they are mostly carried out using IndicatorCreate() and iCustom() functions. Moreover, these functions only return indicator handle, and further work on indicators is done through it. So what is a handle? How to deal with IndicatorCreate() and iCustom() functions? And how your expert will...