Closing price is not always between the high-low range, how come?

 

Greatings coders,

I've found out that the first closing price from a given period isn't always between the high-low price range of that period.
Can someone tell me if there's anything wrong with my sample code?

Thanks for any feedback!

Jim

double
PriceLow,
PriceHigh;

int start()
  {
  if(Bars < 60)
    {
    return(0);
    }

  RefreshRates();
  PriceLow  = Low [iLowest (NULL, 0, MODE_LOW , 60, 0)];
  PriceHigh = High[iHighest(NULL, 0, MODE_HIGH, 60, 0)];
  Print(Close[60] + ", " + PriceLow + ", " + PriceHigh);
  }

   
 
VirtualReal :

Greatings coders,

I've found out that the first closing price from a given period isn't always between the high-low price range of that period.
Can someone tell me if there's anything wrong with my sample code?

Thanks for any feedback!

Jim

Please correct it: Print ( "Close = ", Close[0], ", PriceLow = ", PriceLow, ", PriceHigh = ", PriceHigh );
 
Boeing747 :
Please correct it: Print ( "Close = ", Close[0], " PriceLow = ", PriceLow, " PriceHigh = ", PriceHigh );



Thanks for your suggestion Boeing, but I want the first closing price from a given period, not the last one.
The Print function was only meant for output validation, so I kept it's syntax simple.

Jim

 
VirtualReal : I've found out that the first closing price from a given period isn't always between the high-low price range of that period.

Can someone tell me if there's anything wrong with my sample code?

 PriceLow  = Low [iLowest (NULL, 0, MODE_LOW , 60, 0)];
 PriceHigh = High[iHighest(NULL, 0, MODE_HIGH, 60, 0)];
 Print(Close[60] + ", " + PriceLow + ", " + PriceHigh);
You are finding the highest high and lowest low from bars 0 to 59. Has nothing to do with Close[60]
 
VirtualReal :



Thanks for your suggestion Boeing, but I want the first closing price from a given period, not the last one.
The Print function was only meant for output validation, so I kept it simple.

Jim

Your indicator count 61 bars for calculation a PriceLow and a PriceHigh . So you should use Close[61] and to use period 60 in it,

Or to use Close[60] and to use period 59.

 
Boeing747 :

Your indicator count 61 bars for calculation a PriceLow and a PriceHigh . So you should use Close[61] and to use period 60 in it,

Or to use Close[60] and to use period 59.



Thanks for pointing this out.

I've slightly changed my sample code into this:

double
PriceLow,
PriceHigh;

int start()
  {
  if(Bars < 61)
    {
    return(0);
    }

  RefreshRates();
  PriceLow  = Low [iLowest (NULL, 0, MODE_LOW , 60, 0)];
  PriceHigh = High[iHighest(NULL, 0, MODE_HIGH, 60, 0)];
  Print(Close[61] + ", " + PriceLow + ", " + PriceHigh);
  }

But... when I validate the log file within Excel, about 7% of the closing prices fall outside the high-low bandwidth. This is strange because this data has a 'modelling quality' of 99%.

 
Asked and answered. You are finding the highest high and lowest low from bars 0 through 59. Has nothing to do with bar 60 or bar 61
 
VirtualReal :



Thanks for pointing this out.

I've slightly changed my sample code into this:

But... when I validate the log file within Excel, about 7% of the closing prices fall outside the high-low bandwidth. This is strange because this data has a 'modelling quality' of 99%.

Do you not joke? )) All closing prise "Close[61]" must be out a range is built by High-Low on a period 60 in 100% cases. Please look at it for an axample:

Search high - low on a period 60 bars is making between bar0 t0 bar60, so we can never see bar61, and all closing prices for bars61 wiil be always without our range.

| 0,1,2,..............58,59 | = 60 namber or 60 bars, so the bar59 has an index 60, and the bar60 has an index 61 . We use bar60 in a Close[61]

 

Boeing747 :

a period 60 bars is making between bar0 t0 bar60, wrong

| 0,1,2,..............58,59 | = 60 namber or 60 bars, so the bar59 has an index 60, wrong

there are 61 bars between 0 and 60 inclusive.
The 60th bar has the index 59. The 1st bar has index 0.