Day 4 - Trigger'ed Automation
I created a daily investment digest customized for my portfolio showing current and 30-day market trends, key news, upcoming IPOs/Earnings and correlating these to provide short/long-term investment guidance.
One thing that required fixing was the indices returning incorrect %change. Yahoo Finance's API doesn't return a clean "today's change" field — regularMarketChange comes back as null, so the original code fell back to chartPreviousClose to calculate the change.
The problem: chartPreviousClose is the closing price from before the 30-day chart window (i.e., ~31 days ago), not yesterday's close. So the math was wrong — it was comparing today's price to a month-old price.
The fix was to ignore those fields entirely and use the raw candle array instead:
  • closes[closes.length - 1] = today's live intraday price (Yahoo always appends today as the last candle)
  • closes[closes.length - 2] = yesterday's actual close
Subtracting those two gives the correct day change.
3
2 comments
Ian Wan
3
Day 4 - Trigger'ed Automation
AI Automation Society
skool.com/ai-automation-society
Learn to get paid for AI solutions, regardless of your background.
Leaderboard (30-day)
Powered by