Array out of range? Help?
Results 1 to 9 of 9

Thread: Array out of range? Help?

  1. #1
    EDIT: This is your fix thanks to Johnvanwijk! Https://www.nigeriaforextrading.com/...dom-calls.html


    Hey men,
    So I've been attempting to draw some things however it is giving me the error Array out of range.
    It pulls the green arrows absolutely however the red arrows just won't function.

    If someone could tell me what I am doing wrong it would be fantastic.

    It is not because I am attempting to get candles that aren't there yet or at all as far as I know.
    I get that some people might say that it is going past accessible bars but I've tested even with a limit of 1000 which I am sure my chart has and it still gives me out of range.

    This is the code:

    Inserted Code // ------------------------------------------------------------------ //| FractalsExercise.mq4 | //| | //| https://www.mql5.com | //p------------------------------------------------------------------ #property copyright #property Hyperlink https://www.mql5.com #property variant 1.00 #property strict #property indior_chart_window 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 time#91;#93;, const double available#91;#93;, const double high#91;#93;, const double non#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 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- Tip#91;I#93; = High#91;I#93;; I ; while(ii lt; Restrict) if(Low#91;93#93; lt; Low Cost#91;93 1#93;-RRB- if(Low#91;91#93; lt; Low Cost#91;91 - 1#93;-RRB- Tip#91;93#93; = Low#91;93#93;; ii ; //-- return value of prev_calculated for next call return(rates_total); // ------------------------------------------------------------------

    Thanks!

  2. #2
    If I divide the while loops to two indiors it works with not one error but not when they're in there together.
    It is not accessing anything that's not there either.

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

  3. #3
    Quote Originally Posted by ;
    Hey guys, So I've been attempting to draw some things however it's giving me the error Array out of range. It pulls the green arrows absolutely that the arrows just won't function. If someone could tell me exactly what I'm doing wrong it would be fantastic. Because I'm attempting to get at all or candles that are not there yet as far as I understand, it's not. I get that some people could say that it's going beyond available bars but I have tested even which I'm convinced my chart contains and it provides me out of range. Here is the code: / // ------------------------------------------------------------------ ...
    In each loop, try to break it with something like the illuion below to prevent to go beyond the Bars available:

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

  4. #4
    Quote Originally Posted by ;
    quote In every loop, try to split it using something like the example below to prevent to go past the Bars available: if(I gt;= Bars-1) break; should(ii gt;= Bars-1) break;
    From what I could see that is what my Limit does already however I inserted it into the code just to examine and 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 arrows for the Lows.
    You might also see the mistake just to give folks an idea.

  5. #5
    Quote Originally Posted by ;
    quote From what I can see that is exactly what my Limit does already however I inserted it into the code just to examine and tried it in several places however the error continues. I am honestly puzzled as to why it is giving me the error. This is a picture of the result thus far. It must do the same with arrows pointing up to your Lows. You can also observe the mistake simply to give an idea to folks. picture
    Which line is 71 ?

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

  7. #7
    Hi AntiVi,

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

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

    #property indior_buffers 2

    Cheers Enjoy!

    John


    Inserted Code // ------------------------------------------------------------------ //| FractalsExercise.mq4 | //| AntiVi | //| https://www.mql5.com | // ------------------------------------------------------------------ #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 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 function | // ------------------------------------------------------------------ int OnCalculate(const int rates_total, const int prev_calculated, const datetime period#91;#93;, const double open#91;#93;, const double top#91;#93;, const double low#91;#93;, const double shut#91;#93;, const long 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;93#93; lt; Low#91;93 1#93;-RRB- if(Low#91;ii#93; lt; Low#91;ii - 1#93;-RRB- Lows#91;93#93; = Low#91;93#93;; ii ; //-- return value of prev_calculated for second call yield(rates_total); // ------------------------------------------------------------------

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

    I will blame this on my own inexperience and do it yourself learning.
    I spent a good 5 hours trying to find it out and all I found were workarounds that didn't fix anything.

    I'll edit the first post to add the fix so that people can find the simple answer if they bother looking for it!

    Thank you a lot!

  9. #9
    Quote Originally Posted by ;
    quote You sir are a genius. I can't believe the fix was straightforward. Do it yourself studying and I'm going to blame my own inexperience for this. I spent a good 5 hours trying to figure it out and all I found were workarounds which didn't fix anything. I'll edit the post to add the fix so people can find the answer should they bother looking for it! Thank you a lot!
    Hi AntiVi,
    Along with that which john has shared, you also wish to get in the habit of using the information passed as args into the OnCalculate purpose instead of relying on information from the built in vars. Also, you want to be sure you are performing your. You don't need to process the entire loop (all chart data) on every tick. You only need to process the portion of the indior data that requires updating. Here's a good 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;; double handed#91;#93;; //ADDED------------------------------------------------------------------ //| 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 open#91;#93;, const double high#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 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; large#91;I 1#93; large#91;I#93; gt; large#91;i-1#93;-RRB- Highs#91;I#93; = large#91;s#93;; should(low#91;I#93; lt; low-carb91;I 1#93; low-carb91;I#93; lt; low-carb91;i-1#93;-RRB- Tip#91;I#93; = low#91;t#93;; //-- return value of prev_calculated for second call yield(rates_total);

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.