iRSI indicator changes close price inside. It causes different indicator values

 

HI,


I am working on own automatic trading system and I have tested RSI idicator - I would like to change it a bit.

In MT4, there is RSI indicator and it has below source:

//+------------------------------------------------------------------+
//| Relative Strength Index                                          |
//+------------------------------------------------------------------+
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[])
  {
   int    i,pos;
   double diff;
//---
   if(Bars<=InpRSIPeriod || InpRSIPeriod<2)
      return(0);

   for (int l = 0; l < rates_total; l++)	// MY OWN LOOP
   {
       Print("passed variable to func: time[" + l + "] = " + time[l] + ", close[" + l + "] = " + close[l]);		// in this place, both prints have the same values of close price
       Print("Global variable: Time[" + l + "] = " + Time[l] + ", Close[" + l + "] = " + Close[l]);			// in this place, both prints have the same values of close price
   }

//--- counting from 0 to rates_total
   ArraySetAsSeries(ExtRSIBuffer,false);
   ArraySetAsSeries(ExtPosBuffer,false);
   ArraySetAsSeries(ExtNegBuffer,false);
   ArraySetAsSeries(close,false);

   for (int l = 0; l < rates_total; l++)	// MY OWN LOOP
   {
       Print("passed variable to func: time[" + l + "] = " + time[l] + ", close[" + l + "] = " + close[l]);		// the close values are DIFFERENT then before
       Print("Global variable: Time[" + l + "] = " + Time[l] + ", Close[" + l + "] = " + Close[l]);			// the Close values are THE SAME as before
   }

//--- preliminary calculations



Could you explain me how it could changed?
It is very important for me. 

Thank you in advance,

Best Regards

 

montepasy:

In MT4, there is RSI indicator and it has below source:

Could you explain me how it could changed?
  1. Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. The code you posted is not an RSI.
  3. How should we know how to change the code, when you haven't even stated what it should do?  There are no mind readers here and our crystal balls are cracked.

  4. passed variable to func: time[" + l + "] = " + time[l] + ", close[" + l + "] = " + close[l]); // in this place, both prints have the same values of close price
    Global variable: Time[" + l + "] = " + Time[l] + ", Close[" + l + "] = " + Close[l]);         // in this place, both prints have the same values of close price
    The passed arrays to OnCalculate (e.g. low[],) have no default direction. The predefined variables (e.g. Low[],) all ordered AsSeries
    To determine the indexing direction of time[], open[], high[], low[], close[], tick_volume[], volume[] and spread[], call ArrayGetAsSeries(). In order not to depend on default values, you should unconditionally call the ArraySetAsSeries() function for those arrays, which are expected to work with.
               Event Handling Functions - Functions - Language Basics - MQL4 Reference
 
montepasy:

HI,


I am working on own automatic trading system and I have tested RSI idicator - I would like to change it a bit.

In MT4, there is RSI indicator and it has below source:



Could you explain me how it could changed?
It is very important for me. 

Thank you in advance,

Best Regards

Don't do this :

   ArraySetAsSeries(close,false);

Imagine this :

0,1,2,3,4,5,6,7,8,9

And when you invert how the code is accessing array elements (and that is what you have done with that line) , what is the results going to be?

 
whroeder1:
  1. Why did you post your MT4 question in the Root / MT5 EA section instead of the MQL4 section, (bottom of the Root page?)
              General rules and best pratices of the Forum. - General - MQL5 programming forum
    Next time post in the correct place. The moderators will likely move this thread there soon.

  2. The code you posted is not an RSI.
  3. How should we know how to change the code, when you haven't even stated what it should do?  There are no mind readers here and our crystal balls are cracked.

  4. The passed arrays to OnCalculate (e.g. low[],) have no default direction. The predefined variables (e.g. Low[],) all ordered AsSeries

1. I am so sorry, I did not notice that fact. I will be remember in the future about that.

2. Why do you say that? In my MT4 there is a window on the left and there are indicators. One of them is RSI file. What is more, there is a comment like "Relative Strength Index" inside the file.
    Is it not a iRsi() indicator?
    Can I get know the iRsi() indicator? It is very important for me..

3. I do not know you understanding is what I meant.
    In the above snippet I printed passed arrays to the function onCalculate(e.g. low[]) and predefined(e.g. Low) twice. One is at the beggining of the function and the second is after executions of ArraySetAsSeries functions. In the first time, close values are the same in both cases. In the second, the values from (passed) close array are different then values from predefined Close array. Do you mean, it results from usage of ArraySetAsSeries function?

4. I will read about mentioned two functions. 


Thank you for you replay very much.

 
Mladen Rakic:

Don't do this :

Imagine this :

0,1,2,3,4,5,6,7,8,9

And when you invert how the code is accessing array elements (and that is what you have done with that line) , what is the results going to be?


Thank you for the response.


Unfortunately, mentioned code is not my code, but it is a content of RSI indicator file from MT4.

You can find it in attachments.

Files:
RSI.mq4  5 kb
 
montepasy: 2. Why do you say that? In my MT4 there is a window on the left and there are indicators. One of them is RSI file. What is more, there is a comment like "Relative Strength Index" inside the file.

    Is it not a iRsi() indicator?

The code you posted in originally and the file you posted in  № 4 are completely different.
 

@whroeder1 - do you suppose why the passed close array has different values between first and second printing in the code snippet?

I understand the following invocation determines direction of indexing but the values of the array should be the same. Am I right?

ArraySetAsSeries(close,false);
 
montepasy:

@whroeder1 - do you suppose why the passed close array has different values between first and second printing in the code snippet?

I understand the following invocation determines direction of indexing but the values of the array should be the same. Am I right?

They remain the same

But element with index 0, when the series is set to true, is the last element in the array (value 9 in the case of the array I gave you as an example) and it would return value 0 in the case when array is set to false

 
Mladen Rakic:

They remain the same

But element with index 0, when the series is set to true, is the last element in the array (value 9 in the case of the array I gave you as an example) and it would return value 0 in the case when array is set to false


Are you sure?
I did not attach the logs from the test, but changes, NEW values (after execution of ArraySetAsSeries function) are do not occur in the close array before. So, they are not values with exchanged place in the array, as you say. I can not find such values during printing the right values at the first time...

 
montepasy:

Are you sure?
I did not attach the logs from the test, but changes, NEW values (after execution of ArraySetAsSeries function) are do not occur in the close array before. So, they are not values with exchanged place in the array, as you say. I can not find such values during printing the right values at the first time...

Oh, but I am sure :) Working with arrays for years now - it is almost like second nature by now. In any case, all it takes a couple of seconds of coding to check what I have told you in that post.

_______________________________________________________________________

PS: I never ttoldl that the array elements are going to change places as a result of  ArraySetAsSeries(close,whatever) function call - please show me one single sentence where I told that. What I have told is that same index (to quote myself "element with index 0") will return values of different array element when array is set as series and when it is not (did not mention the obvious case when it is not so : when an array has just one element). Please read my posts again - I usually do not tell nonsense :)

PPS: read this too https://www.mql5.com/en/docs/array/arraysetasseries



All the best

Documentation on MQL5: Array Functions / ArraySetAsSeries
Documentation on MQL5: Array Functions / ArraySetAsSeries
  • www.mql5.com
//| Custom indicator initialization function                         | //| Custom indicator iteration function                              |