Property strict causing indicator to not work

 

Hi , I am working on this indicator with the goal to multiply the RSI value with the (body) size of the current candle (or the equivalent of what was the current candle for the previous bars).

It works in mt4, but when I add property strict the code still compiles but no longer outputs the buffer (displays no data). 

I have checked and found that in my for loop, the line where the buffer gets the value, the problem is that I multiply by (Close[i]-  Close[i+1]);

Could someone please tell me why this is and what I should do? The code does work if I remove the above mentioned. (or if I do not include property strict)


 i=Bars-Counted_bars-1;           
   while(i>=0)                      
     {
    RSIxCandleBuffer[i]=(iRSI(Symbol(),0,RSI_Period,PRICE_CLOSE,i)) * (Close[i]-  Close[i+1]);
   i--;} 
 

Brian Rumbles:

It works in mt4, but when I add property strict the code still compiles but no longer outputs the buffer (displays no data). 

the problem is that I multiply by (Close[i]-  Close[i+1]);

Could someone please tell me why this is and what I should do?

  1. Why did you post your MT4 question in the Root / MT5 Indicators 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. Did you set the buffer type? In build 1090 buffers no longer defaults to DRAW_LINE. You must explicitly set them:
    #property   indicator_typeX   DRAW_LINE                  // Bug 1090 must set.
    ⋮
    SetIndexStyle(X-1, DRAW_LINE);                           // Or in OnInit().
    

  3. Why is that a problem?

  4. There are no mind readers here.
 

Firstly, thanks for your reply. When I compiled the code it worked and when I added property strict it stopped working.

1. Sorry I did not see that, as far as I knew it was in the indicators section

2. I have done that as far as I can tell, I will attach a file.

3. I don't know why its the problem, but I found that if I remove that line, the code does display the buffer. So it is my question if anyone knows what I did wrong.

4. I'm not sure what you mean but I will attach my code, I was just trying to point out the problem instead of posting the entire code and asking if anyone knows what's wrong with it , I figured that would be more difficult.

Files:
 
  1. Had you bothered to look in the log (experts tab) you would have found
    2019.08.14 10:05:11.440    RSI_x_Candle AUDCAD,H1: array out of range in 'RSI_x_Candle.mq4' (48,86)
    Had you bothered to run it on the debugger, you would have found that Counted_bars is zero.
       i=Bars-Counted_bars-1;           // Èíäåêñ ïåðâîãî íåïîñ÷èòàííîãî
       while(i>=0)                      // Öèêë ïî íåïîñ÷èòàííûì áàðàì
         {
        RSIxCandleBuffer[i]=iRSI(Symbol(),0,RSI_Period,PRICE_CLOSE,i) * (Close[i]-  Close[i+1]);
    

    When Counted_bars is zero (first run), i equals Bars-1, and i+1 equals Bars. Close[Bars] does not exist and Updated MQL4 - Language Basics - MQL4 Reference states:

    Old MQL4 compiler

    New MQL4 compiler

    New MQL4 with #property strict

    "Array out of range" does not cause a critical error

    Ditto, except for the arrays of structures and classes, for which this error is critical one

    "Array out of range" is a critical error causing the program to stop

  2. Your lookback is RSI_Period-1.
              How to do your lookbacks correctly.

  3. You should stop using the old event handlers and IndicatorCounted and start using the new ones.
              Event Handling Functions - Functions - Language Basics - MQL4 Reference
              How to do your lookbacks correctly.

 

Thank you William. The Table you added helps to understand the reason why this happens.

I did not know about the log in the experts tab, I did not even have terminal on screen. Debugger I still don't know how to work it yet.

I was unsure what the array out of range was caused by when you first pointed it out, but as you said it is referring to a non existing reference.

I used your lookback code in the "Old" section, and it worked from the moment I clicked compile.


I am looking into the new even handlers, this was my first indicator I did myself, but with the file provided on this site as a tutorial as my starting point. That is where I got the lookback code from in the first place.


The "Had you bothered phrase above" I found that not very satisfactory.

Anyway, You have helped me to solve my problem and no one else did , so thank you very much.