Reputation: 53
I have the following google and yahoo finance queries that generate a simple graph for the last 5 days. How would I go about modifying it to look at last 5 trading days. Simply Monday to Friday only.
=IFERROR(sparkline(query(googlefinance($A16, "price", today()-5, today()), "select Col2 label Col2 ''", 1),{"color",if( INDEX(googlefinance($A16,"price",today()-5),2,2) < INDEX(googlefinance($A16, "price", today()-2),2,2),"green","red");"linewidth",2}))
=SPARKLINE(QUERY(IMPORTHTML(
"https://finance.yahoo.com/quote/AAPL/history?period1=“&86400*(
TODAY()-5)-2209161600&"&period2=“&86400*TODAY()-2209161600&
"&interval=1d&filter=history&frequency=1d”,
"table", 1),
“select Col5 order by Col1 asc offset 1”, 0), {“color”, IF(INDEX(SORT(IMPORTHTML(
"https://finance.yahoo.com/quote/AAPL/history?period1="&86400*(
TODAY()-5)-2209161600&"&period2="&86400*TODAY()-2209161600&
"&interval=1d&filter=history&frequency=1d",
"table", 1), 1, 1), 1, 5) < INDEX(IMPORTXML(
"https://finance.yahoo.com/quote/AAPL",
"//*[@id='quote-header-info']//span"), 2),
"green", "red"); "linewidth", 2})
Upvotes: 1
Views: 975
Reputation: 1
if you run this formula you will get:
so to get last 5 values you need:
therefore:
=SPARKLINE(QUERY(QUERY(IMPORTHTML(
"https://finance.yahoo.com/quote/AAPL/history?period1="&86400*(
TODAY()-15)-2209161600&"&period2="&86400*TODAY()-2209161600&
"&interval=1d&filter=history&frequency=1d",
"table", 1), "limit 5", 1),
"select Col5 order by Col1 offset 1", 0), {"color", IF(QUERY(QUERY(IMPORTHTML(
"https://finance.yahoo.com/quote/AAPL/history?period1="&86400*(
TODAY()-15)-2209161600&"&period2="&86400*TODAY()-2209161600&
"&interval=1d&filter=history&frequency=1d",
"table", 1), "limit 5", 1),
"select Col5 order by Col1 limit 1 offset 1", 0) < INDEX(IMPORTXML(
"https://finance.yahoo.com/quote/AAPL",
"//*[@id='quote-header-info']//span"), 2),
"green", "red"); "linewidth", 2})
Upvotes: 1