Create Google Sheets Email Trigger Based on Stock Price

by Eyes0ftheworld   Last Updated January 09, 2018 04:03 AM

I'm trying to create an email trigger in Google Sheets that will send me an email anytime the Price Fair Value Ratio for any stock is less than 1 (meaning the stock is undervalued). The Ratio is in column 6 and I pull in other corresponding columns into the email that is sent. However, when I set it up the trigger to run on edit, it does not send the intended emails. Any help would be great, thanks!

function FairValueNotification(e) {
  var r = e.range;
  var s = r.getSheet();
  var ss = e.source;
  var sName = s.getSheetName();
  //Price Fair Value Ratio
  if(sName != "Brokerage" || r.getColumn() != 6) return;
  var value = e.value;
  if(value < 1) return;
    //Stock Name
  var value2 = s.getRange(r.getRow(), 1).getValue();
    //Stock Current Price
  var value3 = s.getRange(r.getRow(), 9).getValue();
    //Price Fair Value $
  var value3 = s.getRange(r.getRow(), 5).getValue();
    //Stock Ticker
  var value4 = s.getRange(r.getRow(), 2).getValue();
  value = value.toString();
  var email = Session.getActiveUser().getEmail();
  GmailApp.sendEmail("EMAIL", 'STOCK PRICE ALERT: ' + value2 + ' (' + value4 + ') - Brokerage', 'The following stock is currently undervalued:' + '\n\n' + 'Stock: ' + value2 + '\n' + 'Ticker: ' + value4 + '\n' + 'Current Price: ' + value3 + '\n' + 'Stock Fair Value: ' + value3 + '\n' + 'Stock Value Ratio: ' + value);
}


Related Questions


How to format the time in this Google Docs script

Updated July 12, 2018 14:03 PM

How to Process Rows of Google Sheet Singly?

Updated April 05, 2018 19:03 PM

Syntax error. (line 13, file "Code")Dismiss

Updated February 09, 2018 09:03 AM

Extract email address from gmail message body

Updated February 28, 2018 16:03 PM