Low[] and High[] details please?

 

Hi all, since trading is closed with my broker for the weekend, I have no way to test this reliably. I want to draw horizontal lines at the highest high and lowest low of the last five completed bars while the 6th bar is in progress. In other words, I want to draw the lines for data from times, say, 5:00, 5:01, 5:02, 5:03, and 5:04 during 5:05. I wrote an EA for this (intend to write a script but since I've only coded EAs, this'll do for now).

My question is: if I take Low[0], will this give me the current Low for 5:05 (in the example above, subject to change) or the last completed bar Low (as in 5:04 in the example above)?

The code:

int init() {
   double low = Low[0]; //init vars to 0
   double high = High[0];
   for (int i = 1; i < 5; i++) { //loop through 4 other bars
      if (low > Low[i]) low = Low[i];
      if (high < High[i]) high = High[i];
   }
   //mark the found levels
   ObjectCreate("highlevel",OBJ_HLINE,0,iTime(NULL,0,1),high);
   ObjectCreate("lowhlevel",OBJ_HLINE,0,iTime(NULL,0,1),low);
   //============ NOTE =========
   //
   // Work out putting the lines 5 pips above/below high/below later
   //
   //
   return(0);
}

Only the init() function has code.

 

ubuntuboy

My question is: if I take Low[0], will this give me the current Low for 5:05

This... 0 indexes the currently forming bar.

Also, this might be better than doing the loop.


double     low=iLow(NULL,0,iLowest(NULL,0,MODE_LOW,5,1));
double     high=iHigh(NULL,0,iHighest(NULL,MODE_HIGH,5,1));

HTH

V

 
Thanks V! So for the last five completed bars, I'd want 1...5, inclusive? I'll keep the loop, but thanks for the information about the functions. I assume the functions simply do the loop anyways. More important to me, though, is readability. Sooner or later I'll want to come back and edit this code (for whatever reason), and a simple for loop is easier to interpret than a function within a function, not to mention the enums! Thanks again for the speedy reply.
 

No probs.... yes, you would want 1-5, but it's easy enough to experiment with.... and if readability's the game... :)

int        lowestbar=iLowest(NULL,0,MODE_LOW,5,1);
double     low = Low[lowestbar];
V