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
-
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 - 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 forumDo NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong- SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 and MetaTrader 4 - MQL4 programming forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 and MetaTrader 4 - MQL4 programming forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 and MetaTrader 4 - MQL4 programming forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 and MetaTrader 4 - MQL4 programming forum
- Lot size must also be adjusted to a multiple of LotStep and check against min and max. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
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??
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
Perfect! Now it works!!
Thank's a lot!
Piero

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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