It's no misunderstanding, but just 2 different mistakes:

In the first script you get no output because you've quit the script before even loading price history, which happens after the first run.

In the second script you get no output because "\n" is like a carriage return on a typewriter: It jumps back to the begin of the line. For starting at a new line, you must place the "\n" _before_ and not after the rest of the line.