iClose Function error

 

Hi,

I am trying to build a script that prints some info on the instruments when run, but I have a small problem.

When running

bidPLN=iClose("USDPLN",PERIOD_M1,0);

for the first time I get no quote. (bidPLN=0). USDPLN isn't quoted on request, it is automatic. I get the same error when using another pair.

If I run the script again on the same instrument it will work just fine.

Do you have any ideea why this error appears on the first time I run the script?

Thanks .

 

I may be wrong here but how can you get a close value for a candle that is still open?

you are asking for the close value of the current candle...but the current candle has not closed yet so i dont see how it can return a value.


you must ask for the close value of the last candle...like this :


bidPLN=iClose("USDPLN",PERIOD_M1,1); -- the index should be set for the last candle as that is the most current candle to have a close value

 

"I may be wrong here but how can you get a close value for a candle that is still open?"

Close[0] = Bid for the charted pair

iClose(...,..., 0) = Bid for the specified pair

 
23510:

I may be wrong here but how can you get a close value for a candle that is still open?

you are asking for the close value of the current candle...but the current candle has not closed yet so i dont see how it can return a value.


you must ask for the close value of the last candle...like this :


bidPLN=iClose("USDPLN",PERIOD_M1,1); -- the index should be set for the last candle as that is the most current candle to have a close value

I need to transform some info from PLN denominated to USD denominated so I use the quote from the platform. Using shift 1, would give me an obsolete value.

As phy already said, the Close[0] function will always be the Bid of a currency pair. The problem is that at first use the script will not work because iClose[0] returns value 0 and not a real quote.

If I try using the same script again it will work fine every time.


I tried using the iClose function twice in a row,with RefreshRates() between uses, still this won't fix the problem.

 
Xtrdr:

I need to transform some info from PLN denominated to USD denominated so I use the quote from the platform. Using shift 1, would give me an obsolete value.

As phy already said, the Close[0] function will always be the Bid of a currency pair. The problem is that at first use the script will not work because iClose[0] returns value 0 and not a real quote.

If I try using the same script again it will work fine every time.


I tried using the iClose function twice in a row,with RefreshRates() between uses, still this won't fix the problem.

Ok I am going to learn something from you now please...tell me why do you use the iClose to get the bid off that pair? why not use :


double bid =MarketInfo("USDPLN",MODE_BID);

I know you must have a good reason so please explain to me so i can understand...thanx, i always look forward to learning about the

intricacies of MQL4.


thanx

 
23510 wrote >>

Ok I am going to learn something from you now please...tell me why do you use the iClose to get the bid off that pair? why not use :

double bid =MarketInfo("USDPLN",MODE_BID);

I know you must have a good reason so please explain to me so i can understand...thanx, i always look forward to learning about the

intricacies of MQL4.

thanx

Actually I am just a beginner in programing MQL and I don't know all the functions yet, using iClose was the first thing that came up to my mind.

You just solved my problem. I will try using MarketInfo.

Thanks. :)

Reason: