Arbie
Arbie

Reputation: 91

Is it possible to get the high and low of a stock price during the day over a specific timeframe?

Like the title says, is there a way to get the highs and lows of a stock price during the day after a certain time? There's a way to get the days high and low over a period of time:

=GOOGLEFINANCE("AMZN","high","05/01/2020","05/10/2020","DAILY")

=GOOGLEFINANCE("AMZN","low","05/01/2020","05/10/2020","DAILY")

But what about during the day during a specific time period? For example from 9:12AM PST to 11:23AM PST?

Upvotes: 1

Views: 869

Answers (4)

Mike Steelson
Mike Steelson

Reputation: 15318

Solution#3 : you can use Alpha Vantage by 2 ways, add-on GSheets or a custom function i.e. :

// mike steelson
var apikey = 'xxxxxxxxxxxxxx'
function getAllDataJSONv2(code) {
  var url = 'https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol='+code+'&interval=5min&apikey='+apikey
  var data = JSON.parse(UrlFetchApp.fetch(url).getContentText())['Time Series (5min)']
  var resultat = []
  for (var elem in eval(data)){
    resultat.push([elem,eval(data[elem]['1. open']),eval(data[elem]['2. high']),eval(data[elem]['3. low']),eval(data[elem]['4. close']),eval(data[elem]['5. volume'])])
  }
  return resultat
}

the apikey is free for up to 500 requests a day. https://rapidapi.com/alphavantage/api/alpha-vantage enter image description here

Upvotes: 1

Mike Steelson
Mike Steelson

Reputation: 15318

Solution#2 : you can build your own data based on yahoo finance https://docs.google.com/spreadsheets/d/1QlqpPkIMjE8_jT6kNME1cLrMmQZ9cSzG-SR2Jjivvqo/edit?usp=sharing

//Mike Steelson 
var histo = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('historic')
var code = histo.getRange('B1').getValue()
//put a trigger on historic
function historic(){
  if (testDateHour()==true) {histo.appendRow([new Date(),marketPrice(code)])}
}
function marketPrice(code) {
  var source = UrlFetchApp.fetch('https://finance.yahoo.com/quote/'+code).getContentText()
  var data = JSON.parse(source.match(/(?<=root.App.main = ).*(?=}}}})/g) + '}}}}') 
  return data.context.dispatcher.stores.StreamDataStore.quoteData[code].regularMarketPrice.raw
}
function testDateHour(){
  var d = new Date();
  // not on sunday and saturday and between 10am and 4pm
  if (d.getDay()!=0 && d.getDay()!=6 && d.getHours()>=10 && d.getHours()<=16) {return true}else{return false}
}

Configure your local settings (PST) + update if necessary the period when you want to retrieve the information. Then put the trigger (1min)

Upvotes: 0

Mike Steelson
Mike Steelson

Reputation: 15318

Solution1 : You can use Yahoo Finance to retrieve the information you want

function getHistoric(url){
  var source = UrlFetchApp.fetch(url).getContentText()
  var jsonString = source.match(/(?<=root.App.main = ).*(?=}}}})/g) + '}}}}'
  var data = JSON.parse(jsonString).context.dispatcher.stores.HistoricalPriceStore.prices
  var result = []
  data.forEach(function(elem){
    result.push([elem.date,elem.open,elem.high,elem.low,elem.close])
  })
  return result
}

https://docs.google.com/spreadsheets/d/1Kly5-Vu5jBfrl6xFljdICFJW369X-OCjB22z3Ouzt4Y/copy

Upvotes: 0

player0
player0

Reputation: 1

no, not possible with GOOGLEFINANCE. you can get only the daily value which is usually from 16:00:00

your only other option is to find some website (which doesn't use JavaScript) that holds values you wish for and scrape it into google sheets

Upvotes: 0

Related Questions