Code Help to look at open and close of candles.

 

Hi,

I was wanting to see if there was some quick coding shortcuts to find the 3 most recent DOWN and to be able to see if I can find the highest open of these 3 candles. These candles do not necessarily have to follow each other. Alternatively I wish to find the Lowest Open of the three most recent UP candles. I want to be able to look at say 20 candles back and only take the value of the most recent 3 UP or DOWN arrows.

See image for a better explanation.

 
int candlesFound=0;
int candleIndexes[3];

for(int i=1;i<21;++i)
{
if(Close[i]<Open[i])
{
candleIndexes[candlesFound++]=i;
if(candlesFound==3) break;
}
}
if(candlesFound<3)
Print("no 3 candles found");
else
Print(MathMax(Open[candleIndexes[0]],MathMax(Open[candleIndexes[1]],Open[candleIndexes[2]])));

I am on smartphone right now, but maybe you get the idea...

 
daybyter:
int candlesFound=0;
int candleIndexes[3];

for(int i=1;i<21;++i)
{
if(Close[i]<Open[i])
{
candleIndexes[candlesFound++]=i;
if(candlesFound==3) break;
}
}
if(candlesFound<3)
Print("no 3 candles found");
else
Print(MathMax(Open[candleIndexes[0]],MathMax(Open[candleIndexes[1]],Open[candleIndexes[2]])));

I am on smartphone right now, but maybe you get the idea...

Hi daybyter, I'm not quite sure I follow the code. I'm not great at coding as I am teaching myself. Are you able to comment of what the code does at each line. Thanks in advance