根据股票价格创建Google表格电子邮件触发器

时间:2018-01-09 17:17:42

标签: email google-sheets gmail google-finance

我试图在Google表格中创建一个电子邮件触发器,只要任何股票的价格公允价值比率低于1(意味着股票被低估),我们就会向我发送电子邮件。比率在第6列,我将其他相应的列拉入发送的电子邮件中。但是,当我将其设置为在编辑时运行的触发器时,它不会发送预期的电子邮件。任何帮助都会很棒,谢谢!

    function FairValueNotification(e) {
      var r = e.range;
  var s = r.getSheet();
  var ss = e.source;
  var sName = s.getSheetName();
  if(sName != "Brokerage" || r.getColumn() != 6) return;
     //Price Fair Value Ratio
  var value = e.value;
     //Target Number of Shares
  var value6 = s.getRange(r.getRow(), 13).getValue();
    //Current Number of Shares
  var value7 = s.getRange(r.getRow(), 12).getValue();
    //Number of Shares to Buy
  var value8 = value6 - value7
  if(value > 1) return;
  if(value7 > value6) 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 value4 = s.getRange(r.getRow(), 5).getValue();
    //Stock Ticker
  var value5 = s.getRange(r.getRow(), 2).getValue();
  value = value.toString();
  var email = Session.getActiveUser().getEmail();
  GmailApp.sendEmail("EMAIL", 'STOCK PRICE ALERT: ' + value2 + ' (' + value5 + ') - Brokerage', 'The following stock is currently undervalued:' + '\n\n' + 'Stock: ' + value2 + '\n' + 'Ticker: ' + value5 + '\n' + 'Current Price: $' + value3 + '\n' + 'Stock Fair Value: $' + value4 + '\n' + 'Stock Value Ratio: ' + value + '\n\n' + 'You should buy ' + value8 + ' shares.' + '\n' + 'You currently own ' + value7 + ' shares and have a target of ' + value6 + ' shares.');
}

0 个答案:

没有答案