RSI Comment not moving but staying fixed value when running Strategy Tester

 

Hi All

This is my first post and I'm new to all this.

I am looking into Expert Advisors in Mt4 and created a simple script (see below).

However, when I run it the RSI value shown as a comment on the chart just seems to stay at e.g. 10 and not move at all - see attached screenshot

Is there something I am missing or doing wrong?

Regards

EliteTechFX


void OnTick()

{

   // Create a string variable for the signal

   string signal = "";

   // Calculate the RSI Value

   double RSIvalue = iRSI(_Symbol, _Period, 7, PRICE_CLOSE);

   // If the RSI value is below 20

   if (RSIvalue < 20)

   {

      // Create a BUY signal

      signal = "BUY";

   }

   // If the RSI value is above 80

   if (RSIvalue > 80)

   {

      // Create a SELL signal

      signal = "SELL";

   }

   Comment ("RSI Value: ",RSIvalue,"\n","Signal: ", signal);

}
Files:
 
EliteTechFX:

I am looking into Expert Advisors in Mt4 and created a simple script (see below).

EA or script?

For mt4/mql4, look here for the right way to call iRSI().

iRSI - Technical Indicators - MQL4 Reference
iRSI - Technical Indicators - MQL4 Reference
  • docs.mql4.com
iRSI - Technical Indicators - MQL4 Reference
 
Seng Joo Thio:

EA or script?

For mt4/mql4, look here for the right way to call iRSI().

That didn't work for me.

If I add another parameter at the end e.g. 0 as 5th element within brackets such as double RSIvalue = iRSI(_Symbol, _Period, 7, PRICE_CLOSE,0);

and when I compile it, it complains that iRSI - Wrong parameters count

 
EliteTechFX:

That didn't work for me.

If I add another parameter at the end e.g. 0 as 5th element within brackets such as double RSIvalue = iRSI(_Symbol, _Period, 7, PRICE_CLOSE,0);

and when I compile it, it complains that iRSI - Wrong parameters count

No it doesn't. The parameter count is correct. You probably still have your old code where you did have the wrong count.

Edit: sorry, I got confused.

 
Keith Watford:

No it doesn't. The parameter count is correct. You probably still have your old code where you did have the wrong count.

What is the 7 in the code? Use the proper ENUM_APPLIED_PRICE.

The 7 was the candle period.  Ok I will use that what you suggested.

I commented the old code out

 
EliteTechFX:

The 7 was the candle period.  Ok I will use that what you suggested.

I commented the old code

It's saying syntax error now.  I'm not sure what is going on!

double RSIvalue = iRSI(NULL, 0, ENUM_APPLIED_PRICE, PRICE_CLOSE, 0);

It does not like the 0 at the end as saying too many parameters.

 
double RSIvalue = iRSI(Symbol(),PERIOD_CURRENT, 7, PRICE_CLOSE, 0);

Sorry your code before was Ok, so it was not that line of code giving the error.

You must have had the old line in there still.

 
EliteTechFX: It does not like the 0 at the end as saying too many parameters.

Then you must be running MT5 not MT4. (Help → About)

 
William Roeder:

Then you must be running MT5 not MT4. (Help → About)

Thanks.  It seems MetaQuotes website has a bug.  I downloaded MT4 and installed it.  However, it seems it still installs MT5 instead even though there is an option to install either on their website.

Anyway, got FXCM MT4 now installed and using MQL4 and RSI code working fine.

Is there any further information on here or help where I can understand better that if RSI is oversold or overbought but crosses another level e.g. 50, then do this?

 

I'm using onTick() and in there I have code to get current RSI.

As this is constantly moving and therefore RSI value changes, what do I need to do to differentiate between two RSI values and once I know this, then do this....etc

To explain it in more detail, I want to:

1) Check if RSI value i.e. level is below 30.  If so, store this as a Flag or value in variable perhaps?

2) See if it touches or crosses RSI level 50.  Somehow store this information somewhere also.

3) See if it comes back towards RSI level 30.  If so, replace this RSI value now with what was stored for point 1).

Hope that makes sense!

 
Make up your mind which version you want to run and code in.
  1. EliteTechFX: I am looking into Expert Advisors in Mt4
    Why did you post your MT5 question in the MT4 forum? № 3.

  2. EliteTechFX: I'm using onTick() and in there I have code to get current RSI.
    No you don't. № 3.

  3. EliteTechFX: It does not like the 0 at the end as saying too many parameters.

    You are running on MT5.

    If you had used this you would have found (among 100+) Where to download MT4? - General - MQL5 programming forum 2017.04.31

    It has been years since you could download MT4 from Metaquotes. You can only get it from a broker's website.
              Where to download the orginal MT4 installer - MQL4 programming forum 2018.01.29

    Or the "clean MT4" download link:
              MT4 download - MT4 - General - MQL5 programming forum #2

  4. Perhaps you should read the manual, especially the examples. On MT5, they all return a handle (an int.) 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

    Creating an iMA indicator handle, getting indicator values.
              How to start with MQL5 - General - MQL5 programming forum - Page 3 #22 2020.03.08

    Also see my example for encapsulating calls
              Detailed explanation of iCustom - MQL4 programming forum


Reason: