Unexpected return

Pretty new to AFL, not new to programming. Why am I getting a unexpected return on both return statements.
Can I not put two returns in conditionals?

function candleOpenToHighWithinPercent(percent) {
	candleHeight = High-Low;
	openToHeight = High - Open;
	
//	return IIf(candleHeight == 0, False, openToHeight / candleHeight <= (percent / 100))
	if (candleHeight == 0) {
		return False;
	} else {
		return openToHeight / candleHeight <= (percent / 100);
	}
}

Update:
I got it to work with the commented out IIF line, it has something to do with arrays doesn't it? Would appreciate someone explaining how it works.

I'm calling it like this:

PlotShapes( IIf(isFullCandle() || isAlmostFullCandle(10), shapeUpArrow, shapeNone ), colorGreen );

No, in AFL you have to do this way

function candleOpenToHighWithinPercent(percent) {
	candleHeight = High-Low;
	openToHeight = High - Open;
	
//	return IIf(candleHeight == 0, False, openToHeight / candleHeight <= (percent / 100))
	if (candleHeight == 0) {
		result = False;
	} else {
		result = openToHeight / candleHeight <= (percent / 100);
	}
	return result;
}

Or simply

function candleOpenToHighWithinPercent(percent) {
	candleHeight = High-Low;
	openToHeight = High - Open;
	return  openToHeight / (candleHeight+1e-9) <= (percent / 100);
}
4 Likes