Using iclose or Close[]

 

I am trying to cycle on the1Minute time frame the "Closing price of the 1 min candle" only. I have only been able to get the current candle" 0" ,so  it shows every new close price that occurs within the candle being formed (Code below).which is not what I want.

Does anyone know how I can get the closing Price of the candle only Eg: 1 bar ago ,and the Close price for each candle?

 If another function is more appropriate please let me know .Thanks for any assistance.

 

double Y;
  
   for(Y=iClose(NULL,0,PERIOD_M1); Y<=60;Y++)
   {
   Alert("Close",Y);

 

You may use the function Close(1) or Close (2) or Close (N) to get the closing of each bar.

For example, if you want to get the current bar closing, you may use the close (0) to get this, if 1 bar ago, use close(1), if you want 5 bar ago use close(5), vice versa. 

 
barnacle7:

I am trying to cycle on the1Minute time frame the "Closing price of the 1 min candle" only. I have only been able to get the current candle" 0" ,so  it shows every new close price that occurs within the candle being formed (Code below).which is not what I want.

Does anyone know how I can get the closing Price of the candle only Eg: 1 bar ago ,and the Close price for each candle?

 If another function is more appropriate please let me know .Thanks for any assistance.

 

double Y;
  
   for(Y=iClose(NULL,0,PERIOD_M1); Y<=60;Y++)
   {
   Alert("Close",Y);

First of all candle "0" is closed when it has become candle "1" so last close price on "0" is last tick but bar still open

and you are using function iClose wrong or in a way it proofs you don't understand the meaning of shift 

you getting useless allert with your coding until Y bigger then 60 

.

klik this link      iClose     

  Try out what you get with

Y=iClose("USDCHF",PERIOD_H1,0);Alert("iClose H1 0",Y);
Y=iClose("USDCHF",PERIOD_H1,1);Alert("iClose H1 1",Y);
Y=iClose("USDCHF",PERIOD_H1,2);Alert("iClose H1 2",Y);
Y=iClose("USDCHF",PERIOD_H1,3);Alert("iClose H1 3",Y);
Y=iClose("USDCHF",PERIOD_M1,1);Alert("iClose M1 1",Y);
Y=iClose("USDCHF",PERIOD_M1,2);Alert("iClose M1 2",Y);
Y=iClose("USDCHF",PERIOD_M1,3);Alert("iClose M1 3",Y);
//
Y=Close[0];Alert("Close 0",Y);
Y=Close[1];Alert("Close 1",Y);
Y=Close[2];Alert("Close 2",Y);
Y=Close[3];Alert("Close 3",Y);

//Check the bars for close price
 
chapmann:

You may use the function Close(1) or Close (2) or Close (N) to get the closing of each bar.

For example, if you want to get the current bar closing, you may use the close (0) to get this, if 1 bar ago, use close(1), if you want 5 bar ago use close(5), vice versa. 

 Thanks, Chapmann, I tried to put in "N" using both Close[N]; or iClose(NULL,PERIOD_M1,N); but I get a compile Error "  'N' - Variable not defined". Can you let me know more about that or post a Link where I can read more on that ?

When I run the close cycle it shows as per below which is omitting the the beggining of EURUSD being "1."  and should be showing 1.3445 with preferably the 5th digit as well.

 2013.01.29 18:29:40 Stoch and Top Trend EURUSD,M1: Alert: Close8.3445
2013.01.29 18:29:40 Stoch and Top Trend EURUSD,M1: Alert: Close7.3445

 

 The one below here omitted the "1." as well as rounding up and omitting 2 digits, the close price for this was 1.34396 but for some reason it only shows it as Close8.344. My expectation is to see it read "Close8.1.34396"

2013.01.29 18:30:33 Stoch and Top Trend EURUSD,M1: Alert: Close8.344
2013.01.29 18:30:33 Stoch and Top Trend EURUSD,M1: Alert: Close7.344

 Does anyone know I can get it to show the full price ?
 

 

barnacle7:

 Thanks, Chapmann, I tried to put in "N" using both Close[N]; or iClose(NULL,PERIOD_M1,N); but I get a compile Error "  'N' - Variable not defined". Can you let me know more about that or post a Link where I can read more on that ? 

Declaring variables is a basic of most,  if not all, programming languages.  Book - Variables
 

 DeVries your response was very helpful ,Thanks ,

I tried it and have found that below is happening (Rounding up,and Omitting ).

 

When I run the close cycle it shows as per below which is omitting the the beggining of EURUSD being "1." and should be showing 1.3445 with preferably the 5th digit as well.

2013.01.29 18:29:40 Stoch and Top Trend EURUSD,M1: Alert: Close8.3445
2013.01.29 18:29:40 Stoch and Top Trend EURUSD,M1: Alert: Close7.3445

The one below here omitted the "1." as well as rounding up and omitting 2 digits, the close price for this was 1.34396 but for some reason it only shows it as Close8.344. My expectation is to see it read "Close8.1.34396"

2013.01.29 18:30:33 Stoch and Top Trend EURUSD,M1: Alert: Close8.344
2013.01.29 18:30:33 Stoch and Top Trend EURUSD,M1: Alert: Close7.344

Does anyone know I can get it to show the full price ?

 
barnacle7:

 

 DeVries your response was very helpful ,Thanks ,

I tried it and have found that below is happening (Rounding up,and Omitting ).

 

When I run the close cycle it shows as per below which is omitting the the beggining of EURUSD being "1." and should be showing 1.3445 with preferably the 5th digit as well.

2013.01.29 18:29:40 Stoch and Top Trend EURUSD,M1: Alert: Close8.3445
2013.01.29 18:29:40 Stoch and Top Trend EURUSD,M1: Alert: Close7.3445

The one below here omitted the "1." as well as rounding up and omitting 2 digits, the close price for this was 1.34396 but for some reason it only shows it as Close8.344. My expectation is to see it read "Close8.1.34396"

2013.01.29 18:30:33 Stoch and Top Trend EURUSD,M1: Alert: Close8.344
2013.01.29 18:30:33 Stoch and Top Trend EURUSD,M1: Alert: Close7.344

Does anyone know I can get it to show the full price ?

Show your code . . . .  and please use the SRC button to do so.

 

Read the Documentation for Alert() ,   it tells you that . . .  "Data of double type output with 4 decimal digits after point."   and what you can do to get all Digits

 
RaptorUK:

Show your code . . . .  and please use the SRC button to do so.

 

Read the Documentation for Alert() ,   it tells you that . . .  "Data of double type output with 4 decimal digits after point."   and what you can do to get all Digits

 

Thanks RaptoUk, I put in digits and that seems so have helped. I a not sure how I have 5 digits after the decimal place , I agree with you re the 4decimal places. (O'well I won't complain).

But it is still omitting and rounding, the Closing price was 1.34306 but its showing ".34315" ?


2013.01.29 21:06:50     Stoch and Top Trend EURUSD,M1: Alert: close3.34315
2013.01.29 21:06:50     Stoch and Top Trend EURUSD,M1: Alert: close2.34315
2013.01.29 21:06:50     Stoch and Top Trend EURUSD,M1: Alert: close1.34315


  
   
  

 

Here is the code.

double Y;
  
   for(Y=iClose(NULL,PERIOD_M1,1); Y<=4; Y++)
  
   {
   
   Alert("close",Y,Digits); 
   }
 
barnacle7:

Thanks RaptoUk, I put in digits and that seems so have helped. I a not sure how I have 5 digits after the decimal place , I agree with you re the 4decimal places. (O'well I won't complain).

You obviously didn't read the Documentation . . .   it says this . . .  "Data of double type output with 4 decimal digits after point. To output with more precision use DoubleToStr() function."

Try this:

int Y;
  
for(Y = 1; Y <= 4; Y++)
   {
   
   Alert("Close ", Y, " ", DoubleToStr(iClose(NULL, PERIOD_M1, Y), Digits) );  
   }

The index of a standard   for   loop has to be an integer not a double,  how can you have 3.1267 loops ??  you can have 0, 1, 2, 3, 4  loops,  you can't have  fractional parts of a loop,  just whole numbers,  hence integers.

 
RaptorUK:

You obviously didn't read the Documentation . . .   it says this . . .  "Data of double type output with 4 decimal digits after point. To output with more precision use DoubleToStr() function."

Try this:

The index of a standard   for   loop has to be an integer not a double,  how can you have 3.1267 loops ??  you can have 0, 1, 2, 3, 4  loops,  you can't have  fractional parts of a loop,  just whole numbers,  hence integers.

 

Thanks RaptorUK, That works well, this is very useful. I notice that you have used,   " " . In the sample for "Alert" they use, both quotation marks and Exclamation marks. Are they only used in void, where can I find when and where they can be used and what they do ?

Reason: