Array out of range? Help? - Page 2
Page 2 of 842 FirstFirst 12
Results 11 to 12 of 12

Thread: Array out of range? Help?

  1. #11
    Quote Originally Posted by ;
    quote Hi , In addition to what john has shared, you wish to get in the habit of using the information passed as args into the OnCalculate function rather than relying on information from the built-in vars. Also, you want to be certain you're doing your look-backs correctly. 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 is an example of how to make use of the OnCalculate function. #property stringent #property indior_chart_window...
    Alright so it took me a little while to figure out what precisely everything meant however once I set in the code and set a print it within the for loop it would continue to print each tick no matter what.

    It appears to be fixed when I change this bit of code:
    limit = limit lt; 1) ? 1 : limitation;

    To this:
    limit = limit lt; 1) ? 0 : limitation;

    Because otherwise it appears that Limit would be no matter what.
    Allow me to know if I am wrong here.

    It also seems like it's not drawing new arrows but maybe that is because of the change I made so I will test that.

    EDIT:
    so that it appears I altering that changed the ability for it to attract new ones.

    EDIT 2:
    So I changed it back to what it was and it is drawing new arrow however it's printing them wrong because it's thinking the currently forming candle is currently complete.

    EDIT 3:
    I change this bit of code: limit = limit lt; 1) ? 1 : limitation;
    To this: limit = limit lt; 1) ? 2 : limitation;

    Which changes it to just use finished candles which means that it will not be printing any arrows using a candle that is currently forming and it's currently printing correctly.
    Correct me if I am mistaken.

  2. #12
    Alright here's a little update!

    So in order to fix it always running that I assessed by printing things I put in an if statement that is this one:
    if(rates_total gt; prev_calculated){}

    This prevents anything from running if there isn't a new candle.
    I am not sure if that makes the rest obsolete but there should be some things I can do to clean this up code somewhat and make it simpler.

    Additionally, it prints correctly on account of this previous mentioned change in my third Edit on the previous article.

    Inserted Code // ------------------------------------------------------------------ //| FractalsExercise.mq4 | //| | //| https://www.mql5.com | //p------------------------------------------------------------------ #property copyright #property Hyperlink https://www.mql5.com #property version 1.00 #property strict #property indior_chart_window #property indior_buffers 2 dual Highs#91;#93;; dual Lows#91;#93;; // ------------------------------------------------------------------ //| Custom indior initialization function | // ------------------------------------------------------------------ int OnInit() //-- drawing fashion SetIndexStyle(0, DRAW_ARROW, EMPTY, 1, clrGreen); SetIndexArrow(0, 226); SetIndexStyle(1, DRAW_ARROW, EMPTY, 1, clrRed); SetIndexArrow(1, 225); //-- 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 available#91;#93;, const double high#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 limit = rates_total - prev_calculated - 2; limit = limit lt; 1 ? 2 : limit; for(int I = limit; t gt; 1; I--) if(rates_total gt; prev_calculated) Printing(=== NEW CANDLE ===); if(Top#91;t#93; gt; Top#91;I 1#93; Top#91;I#93; gt; Top#91;I - 1#93;-RRB- Tip#91;I#93; = High#91;I#93; 0.0001; Print(NEW HIGH DETECTED , I); if(Low#91;I#93; lt; Low#91;I 1#93; Low Cost#91;I#93; lt; Low Cost#91;I - 1#93;-RRB- Tip#91;I#93; = Low#91;s#93; - 0.0001; Print(NEW LOW DETECTED , I); //-- 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.