iRSI not working MQL5 Help please

 

Hi this code is not working and I am not sure why. any insight would be appreciated thanks.

#include<Trade\Trade.mqh>

CTrade trade;

void OnTick()
{
   int rsiValue=iRSI(NULL, NULL,14,PRICE_CLOSE); //also tried double
  
   if(rsiValue>50) 
   {
        trade.Buy(0.01,NULL,0.0,0.0,0.0,NULL);
   }

}
 
CodeBerries: Hi this code is not working and I am not sure why. any insight would be appreciated thanks.

In MQL5, iRSI or any other indicator function, does not return an indicator buffer value. It returns an Indicator Handle which you then use with the function CopyBuffer to obtain the buffer values of the indicator.

You should initialise and obtain the indicator handles in the OnInit() event handler and then use the CopyBuffer in the OnTick() handler.

Please read the documentation carefully and review the examples.
 
  1. Please edit your (original) post and use the CODE button (or Alt+S)! (For large amounts of code, attach it.)
              General rules and best pratices of the Forum. - General - MQL5 programming forum (2019)
              Messages Editor

  2. Perhaps you should read the manual, especially the examples.
       How To Ask Questions The Smart Way. (2004)
          How To Interpret Answers.
             RTFM and STFW: How To Tell You've Seriously Screwed Up.

    They all (including iCustom) return a handle (an int). You get that in OnInit. In OnTick/OnCalculate (after the indicator has updated its buffers), you use the handle, shift and count to get the data.
              Technical Indicators - Reference on algorithmic/automated trading language for MetaTrader 5
              Timeseries and Indicators Access / CopyBuffer - Reference on algorithmic/automated trading language for MetaTrader 5
              How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 (2020)
              How to start with MQL5 - MetaTrader 5 - General - MQL5 programming forum - Page 7 #61 (2020)
              MQL5 for Newbies: Guide to Using Technical Indicators in Expert Advisors - MQL5 Articles (2010)
              How to call indicators in MQL5 - MQL5 Articles (2010)

 
Fernando Carreiro #:

In MQL5, iRSI or any other indicator function, does not return an indicator buffer value. It returns an Indicator Handle which you then use with the function CopyBuffer to obtain the buffer values of the indicator.

You should initialise and obtain the indicator handles in the OnInit() event handler and then use the CopyBuffer in the OnTick() handler.

Please read the documentation carefully and review the examples.

Hey I was wondering if you could help me with my code I tried to send you a message it did not work.

Thanks I have the code finished but there is an error, it is not a long code. 

 
CodeBerries #: Hey I was wondering if you could help me with my code I tried to send you a message it did not work. Thanks I have the code finished but there is an error, it is not a long code. 

I do not offer private services, nor do I currently code for anyone but myself. If you need help, then please use the forum, not private messages.

So, post your code and describe the issue you need help with. Provide full details, such as error code, line-number on which the error occurs and output in the Journal and/or Experts log files.

EDIT: And please use the "</>" code icon or Alt-S to insert your code in your post. Don't just copy/paste as normal text.

Code Button

 
Ilyas Shamadin Khan #:

Hey I was wondering if you could help me with my code I tried to send you a message it did not work.

Thanks I have the code finished but there is an error, it is not a long code. 

Hi Ilyas, did you finalize the code in the end?
I've created one myself which is working fine in the strategy tester but not on live trading

Reason: