Doubt about iClose..

 

With the following code, using the variable "period" (which can become PERIOD_M5, PERIOD_M1, PERIOD_H1) and the variable "long" (various integers)

c = NormalizeDouble (iClose (NULL, period, length), Digits);

if they were set to PERIOD_H1 and 4, I was sure I would have obtained the closing price of the fifth candle 1 hour. This regardless of the chart view, at 5 min rather than any other time interval.

With my great surprise, the value "c" changes, and very much, based on the view of the graph .. practically canceling the utility of this function for me.. In what I'm wrong?

Thank's

Piero

 
pieroim:

With the following code, using the variable "period" (which can become PERIOD_M5, PERIOD_M1, PERIOD_H1) and the variable "long" (various integers)

c = NormalizeDouble (iClose (NULL, period, length), Digits);

if they were set to PERIOD_H1 and 4, I was sure I would have obtained the closing price of the fifth candle 1 hour. This regardless of the chart view, at 5 min rather than any other time interval.

With my great surprise, the value "c" changes, and very much, based on the view of the graph .. practically canceling the utility of this function for me.. In what I'm wrong?

Thank's

Piero

Nothing wrong with iClose(). Used this :

   Comment(NormalizeDouble (iClose (NULL,PERIOD_H1,4), Digits));

and all works as expected. Check values in your "period" and "length" variables

 
  1. On MT4: Unless the current chart is the specific pair/TF referenced, you must handle 4066/4073 errors.
              Download history in MQL4 EA - MQL4 and MetaTrader 4 - MQL4 programming forum

  2. If you want to see the correct number of digits, convert it to a string.
               question about decima of marketinfo() - MQL4 and MetaTrader 4 - MQL4 programming forum
    Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
 

Dont work..

new code for de called function:

 int trend(string periodo = " ", int lungh = 0)
 {
 // PERIOD_M5, PERIOD_M1, PERIOD_H1
  double c, o, a;
  ResetLastError();

  o = iOpen(Symbol(), periodo, lungh);
  Alert(Symbol() + "   iOpen: " + o + "   Per: " + periodo + "   Lungh: " + lungh + "  Err: " + GetLastError());
  c = iClose(Symbol(), periodo, lungh);
  Alert(Symbol() + "   iClose: " + c + "   Per: " + periodo + "   Lungh: " + lungh + "  Err: " + GetLastError());
  a = (Ask+Bid)/2; // valore sempre positivo

  return (a);

 }


- Aspected Open/Close values for the bar at H1: open 47,96, close 47,88 


---- Results from the alert window: (Main chart at H1 too) - 3 Calls to the function:


CrudeOIL iClose: 47.88    Per: PERIOD_H1   Lungh: 4   Err: 0     > ok!

CrudeOIL iOpen: 47.96    Per: PERIOD_H1   Lungh: 4   Err: 0     > ok!

CrudeOIL iClose: 47.88    Per: PERIOD_M5   Lungh: 4   Err: 0     > Bad!

CrudeOIL iOpen: 47.96    Per: PERIOD_M5   Lungh: 4   Err: 0     > Bad!

CrudeOIL iClose: 48.55    Per: PERIOD_M5   Lungh: 2   Err: 0     > Bad!

CrudeOIL iOpen: 48.01    Per: PERIOD_M5   Lungh: 2   Err: 0     > Bad!



---- Results from the alert window: (Main chart M5) - 3 calls to the function

CrudeOIL iClose: 48.77    Per: PERIOD_H1   Lungh: 4   Err: 0   > Bad!

CrudeOIL iOpen: 48.69    Per: PERIOD_H1   Lungh: 4   Err: 0   > Bad!

CrudeOIL iClose: 48.77    Per: PERIOD_M5   Lungh: 4   Err: 0   > Ok!

CrudeOIL iOpen: 48.69    Per: PERIOD_M5   Lungh: 4   Err: 0   > Ok!

CrudeOIL iClose: 48.89    Per: PERIOD_M5   Lungh: 2   Err: 0   > Ok!

CrudeOIL iOpen: 48.87    Per: PERIOD_M5   Lungh: 2   Err: 0   > Ok!


The function use the main chart time frame.. how is this possible??

 
pieroim:

Dont work..

new code for de called function:

 int trend(string periodo = " ", int lungh = 0)
 {
 // PERIOD_M5, PERIOD_M1, PERIOD_H1
  double c, o, a;
  ResetLastError();

  o = iOpen(Symbol(), periodo, lungh);
  Alert(Symbol() + "   iOpen: " + o + "   Per: " + periodo + "   Lungh: " + lungh + "  Err: " + GetLastError());
  c = iClose(Symbol(), periodo, lungh);
  Alert(Symbol() + "   iClose: " + c + "   Per: " + periodo + "   Lungh: " + lungh + "  Err: " + GetLastError());
  a = (Ask+Bid)/2; // valore sempre positivo

  return (a);

 }


- Aspected Open/Close values for the bar at H1: open 47,96, close 47,88 


---- Results from the alert window: (Main chart at H1 too) - 3 Calls to the function:


CrudeOIL iClose: 47.88    Per: PERIOD_H1   Lungh: 4   Err: 0     > ok!

CrudeOIL iOpen: 47.96    Per: PERIOD_H1   Lungh: 4   Err: 0     > ok!

CrudeOIL iClose: 47.88    Per: PERIOD_M5   Lungh: 4   Err: 0     > Bad!

CrudeOIL iOpen: 47.96    Per: PERIOD_M5   Lungh: 4   Err: 0     > Bad!

CrudeOIL iClose: 48.55    Per: PERIOD_M5   Lungh: 2   Err: 0     > Bad!

CrudeOIL iOpen: 48.01    Per: PERIOD_M5   Lungh: 2   Err: 0     > Bad!



---- Results from the alert window: (Main chart M5) - 3 calls to the function

CrudeOIL iClose: 48.77    Per: PERIOD_H1   Lungh: 4   Err: 0   > Bad!

CrudeOIL iOpen: 48.69    Per: PERIOD_H1   Lungh: 4   Err: 0   > Bad!

CrudeOIL iClose: 48.77    Per: PERIOD_M5   Lungh: 4   Err: 0   > Ok!

CrudeOIL iOpen: 48.69    Per: PERIOD_M5   Lungh: 4   Err: 0   > Ok!

CrudeOIL iClose: 48.89    Per: PERIOD_M5   Lungh: 2   Err: 0   > Ok!

CrudeOIL iOpen: 48.87    Per: PERIOD_M5   Lungh: 2   Err: 0   > Ok!


The function use the main chart time frame.. how is this possible??

"periodo" can not be string

 

ok, I go to test the function using the values instead the string.

 

Perfect! Now it works!!

Thank's a lot!

Piero

 

I have a rather basic question, why didn't iClose specify is it close ask or close bid price, if some one can clarify for me.

Thx!

 
Bid.
Reason: