Array out of range? Help?
Page 1 of 842 12 LastLast
Results 1 to 10 of 12

Thread: Array out of range? Help?

  1. #1
    EDIT: This is your fix as a result of Johnvanwijk! Https://www.forexforum.co.za/general...-analysis.html


    Hey men,
    So I've been trying to draw some things however it's giving me the error Array from range.
    It pulls the green arrows absolutely however that the red arrows just won't function.

    If somebody could tell me exactly what I'm doing wrong it would be fantastic.

    It is not because I'm trying to access candles that are not there or at all as far as I know.
    I get that some people might say that it's going past available bars but I have tested even with a limit of 1000 which I'm convinced my chart has and it still gives me from range.

    Here is the code:

    Inserted Code // ------------------------------------------------------------------ //| FractalsExercise.mq4 | //| | //| https://www.mql5.com | //p------------------------------------------------------------------ #property copyright #property link https://www.mql5.com #property version 1.00 #property strict #property indior_chart_window double Highs#91;#93;; dual Lows#91;#93;; // ------------------------------------------------------------------ //| Custom indior initialization function | // ------------------------------------------------------------------ int OnInit() //-- drawing style SetIndexStyle(0, DRAW_ARROW, EMPTY, 1, clrGreen); SetIndexArrow(0, 234); SetIndexStyle(1, DRAW_ARROW, EMPTY, 1, clrRed); SetIndexArrow(1, 233); //-- indior buffers SetIndexBuffer(0, Highs); SetIndexBuffer(1, Lows); //-- return(INIT_SUCCEEDED); // ------------------------------------------------------------------ //| Custom indior iteration serve | // ------------------------------------------------------------------ int OnCalculate(const int rates_total, const int prev_calculated, const datetime time#91;#93;, const double open#91;#93;, const double top#91;#93;, const double non#91;#93;, const double close#91;#93;, const extended tick_volume#91;#93;, const long volume#91;#93;, const int disperse#91;#93;-RRB- //-- int I = 1; int ii = 1; int Restrict = Bars - 1; while(I lt; Restrict) if(High#91;t#93; gt; High#91;t 1#93;-RRB- if(High#91;t#93; gt; High#91;I - 1#93;-RRB- Highs#91;I#93; = High#91;I#93;; I ; while(ii lt; Restrict) if(Low#91;ii#93; lt; Low Cost#91;ii 1#93;-RRB- if(Low#91;ii#93; lt; Low Cost#91;ii - 1#93;-RRB- Tip#91;ii#93; = Low#91;ii#93;; ii ; //-- return value of prev_calculated for next call return(rates_total); // ------------------------------------------------------------------

    Thanks!

  2. #2
    If I split the while loops into two indiors it works perfectly with not a single error but not when they are in there.
    It is not getting anything that is not there either.

    So I'm not certain why it says it's out of range.

  3. #3
    Quote Originally Posted by ;
    Hey guys, So I've been trying to draw some stuff however it's giving me the error Array out of range. It draws the green arrows perfectly however that the arrows just won't work. If someone can tell me what I am doing wrong it would be fantastic. Because I am trying to access at all or candles that aren't there as far as I understand, it's not. I get that some people could say that it's going accessible bars but I have tested even which I am sure my chart has and it gives me out of range. This is the code: / // ------------------------------------------------------------------ ...
    In each loop, try to split it using something like the example below to prevent to go past the Bars accessible:

    Inserted Code if(I gt;= Bars-1) break; Inserted Code if(ii gt;= Bars-1) break;

  4. #4
    Quote Originally Posted by ;
    quote In each loop, try to split it with something similar to the example below to avoid to go beyond the Bars available: if(I gt;= Bars-1) break; if(ii gt;= Bars-1) break;
    From what I could see that is what my Limit does however I inserted it into the code just to test and even tried it in many places however the error persists.

    I am honestly puzzled as to why it's giving me the error.

    This is a picture of the outcome up to Now. It should do the same with red arrows to your Lows.
    You can also observe the mistake just to give people an idea.

  5. #5
    Quote Originally Posted by ;
    quote From what I could see that's exactly what my Limit does nevertheless I inserted it to the code simply to examine and tried it in many positions however the error persists. I'm honestly puzzled as to why it's giving the error to me. This is an image of the result up to now. It should do the same with red arrows to your Lows. You can observe the mistake to give people an idea. picture
    Which line is 71 ?

  6. #6
    Quote Originally Posted by ;
    quote Which line is 71 ?
    That would be Lows[ii] = Low[ii]; at the second while loop.

  7. #7
    Hello AntiVi,

    you should indie the number of buffers are required....

    The following change in the beginning in your code (after #property indior_chart_window) makes it work well....

    #property indior_buffers two

    Cheers Enjoy!

    John


    Inserted Code //p------------------------------------------------------------------ //| FractalsExercise.mq4 | //| AntiVi | //| https://www.mql5.com | //p------------------------------------------------------------------ #property copyright AntiVi #property link https://www.mql5.com #property variant 1.00 #property stringent #property indior_chart_window // START ADDED JvW #property indior_buffers 2 // END ADDED JvW double Highs#91;#93;; dual Lows#91;#93;; // ------------------------------------------------------------------ //| Custom indior initialization function | // ------------------------------------------------------------------ int OnInit() //-- drawing fashion SetIndexStyle(0, DRAW_ARROW, EMPTY, 1, clrGreen); SetIndexArrow(0, 234); SetIndexStyle(1, DRAW_ARROW, EMPTY, 1, clrRed); SetIndexArrow(1, 233); //-- indior buffers SetIndexBuffer(0, Highs); SetIndexBuffer(1, Lows); //-- return(INIT_SUCCEEDED); // ------------------------------------------------------------------ //| Custom indior iteration function | // ------------------------------------------------------------------ int OnCalculate(const int rates_total, const int prev_calculated, const datetime period#91;#93;, const double available#91;#93;, const double top#91;#93;, const double low#91;#93;, const double shut#91;#93;, const extended tick_volume#91;#93;, const long volume#91;#93;, const int spread#91;#93;-RRB- //-- int I = 1; int ii = 1; int Limit = Bars - 1; while(I lt; Limit) if(Top#91;t#93; gt; Top#91;t 1#93;-RRB- if(Top#91;t#93; gt; Top#91;I - 1#93;-RRB- Highs#91;I#93; = High#91;I#93;; I ; while(ii lt; Limit) if(Low#91;93#93; lt; Low Cost#91;93 1#93;-RRB- if(Low#91;ii#93; lt; Low Cost#91;ii - 1#93;-RRB- Tip#91;93#93; = Low#91;93#93;; ii ; //-- return value of prev_calculated for next call yield(rates_total); // ------------------------------------------------------------------

  8. #8
    Quote Originally Posted by ;
    Hello , you should indie the number of buffers are required.... The subsequent change in the beginning in your code (later #property indior_chart_window) makes it work well... #property indior_buffers two Cheers Enjoy! John //p------------------------------------------------------------------ //| FractalsExercise.mq4 | //| | //| https://www.mql5.com | //p------------------------------------------------------------------ #property copyright #property hyperlink https://www.mql5.com #property version 1.00 #property stringent #property...
    You sir are a genius.
    I can't think the fix was really simple.

    I'm going to blame this on my inexperience and do yourself learning.
    I spent a great 5 hours trying to figure it out and all I found were workarounds which didn't fix anything.

    I'll edit the first post to include the fix so people may get the simple answer should they bother looking for it!

    Thank you a lot!

  9. #9
    Quote Originally Posted by ;
    quote You sir are a genius. I can not think the fix was simple. I'm going to blame my own inexperience for this and do it yourself learning. I spent a great five hours trying to find it out and all I found were workarounds which didn't fix anything. I'll edit the post to include the repair if they bother looking for it so people may find the easy answer! Thanks a lot!
    Hi AntiVi,
    In addition to what john has shared, you want to get in the habit of using the data passed as args into the OnCalculate function instead of relying on data from the built-in vars. You ought to make sure you are performing your. You do not have to process the entire loop (all chart data) on each tick. You just have to process the part of the indior data that needs updating. Here's an illuion of how to make use of this OnCalculate function. Inserted Code #property strict #property indior_chart_window // START ADDED JvW #property indior_buffers 2 // END ADDED JvW double Highs#91;#93;; dual Lows#91;#93;; // ------------------------------------------------------------------ //| Custom indior initialization function | // ------------------------------------------------------------------ int OnInit() //-- drawing fashion SetIndexStyle(0,DRAW_ARROW,EMPTY,1,clrGreen); SetIndexArrow(0,234); SetIndexStyle(1,DRAW_ARROW,EMPTY,1,clrRed); SetIndexArrow(1,233); //-- indior buffers SetIndexBuffer(0,Highs); SetIndexBuffer(1,Lows); return(INIT_SUCCEEDED); // ------------------------------------------------------------------ //| Custom indior iteration serve | // ------------------------------------------------------------------ int OnCalculate(const int rates_total, const int prev_calculated, const datetime period#91;#93;, const double open#91;#93;, const double high#91;#93;, const double low#91;#93;, const double close#91;#93;, const long tick_volume#91;#93;, const long volume#91;#93;, const int spread#91;#93;-RRB- //-- int limit = rates_total - prev_calculated - two; limit = limit lt; 1 ? 1 : limitation; for(int I = limitation; I gt; 0; I--) if(high#91;I#93; gt; high#91;I 1#93; high#91;I#93; gt; high#91;i-1#93;-RRB- Highs#91;I#93; = high#91;I#93;; if(low#91;I#93; lt; low-carb91;I 1#93; low-carb91;I#93; lt; low-carb91;i-1#93;-RRB- Lows#91;I#93; = low#91;t#93;; //-- return value of prev_calculated for next call yield(rates_total);

  10. #10
    Genius ??? Thanks, but I wouldn't think so.

    More a bit of a stumbler with experience :--RRB-

    I bet for every single error, omission or code typo that you could reveal here: I've made the exact same previously. . .and likely TWICE!

    Cheerio

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
This website uses cookies
We use cookies to store session information to facilitate remembering your login information, to allow you to save website preferences, to personalise content and ads, to provide social media features and to analyse our traffic. We also share information about your use of our site with our social media, advertising and analytics partners.