Fining High open low close of the previous candle

 

This is my code, could anyone explain or give any reasons as to why it doesnt just print the high low open and close of the previous candle, it just produces other incorrect values.

candleIndex is set to 1

double openPrice = iOpen(NULL, 0, 1); // Open price of the specified indexed candle
double closePrice = iClose(NULL, 0, candleIndex); // Close price of the specified indexed candle
double highPrice = iHigh(NULL, 0, candleIndex); // High price of the specified indexed candle
double lowPrice = iLow(NULL, 0, candleIndex); // Low price of the specified indexed candle

Print("Open is ",openPrice," close is ",closePrice, " high is ", highPrice, " low is ",lowPrice);
 
JamesFrost: This is my code, could anyone explain or give any reasons as to why it doesnt just print the high low open and close of the previous candle, it just produces other incorrect values.

Show some more info what is being printed?

Print candleIndex to confirm if its value is 1 (previous candle) and not invalid

you can also troubleshoot like this

if(openPrice==0) 
Print(GetLastError()); 
else Print("Open is ",openPrice);
 

Improperly formatted code edited by moderator. Please use the CODE button (Alt-S) when inserting code.

Code button in editor

 
Rajesh Kumar Nait #:

Show some more info what is being printed?

Print candleIndex to confirm if its value is 1 (previous candle) and not invalid

you can also troubleshoot like this


I figured out my mistake, which didnt actually lie in the coding, I was checking my OHLC values with candlestick data from 2023 instead of 2024.

Bit of a silly error, but thanks for coming back to me nonetheless