The upperShadow is calculated by subtracting the higher of the open or close price from the high of the candle. This measures the length of the upper shadow, which is a crucial element of the Inverted Hammer pattern.