1

When I send this POST using POSTMAN the text 'Hello World' is added to a Google Sheet.

https://script.google.com/macros/s/AKfycbwXdAoAnggrOL2NXhyIi7L2uQKKv4bmZjg_Z67VYi6jUuNp5HmiTw78ARGVZWSHYaM7/exec?gid=2061&Message=Hello World



I have tried to use this as webhook URL in TradingView:

https://script.google.com/macros/s/AKfycbwXdAoAnggrOL2NXhyIi7L2uQKKv4bmZjg_Z67VYi6jUuNp5HmiTw78ARGVZWSHYaM7/exec?

and add the gid and Message as message in the Pine script alert function but without success. I have tried a lot of different ways but nothing gets written to the Google sheet.

if DiffCloseMA > 0
    alert ("gid=2061&Message=Buy", alert.freq_once_per_bar)
else if DiffCloseMA < 0
    alert ("gid=2061&Message=Sell", alert.freq_once_per_bar)

Have someone solved something similar? Thanks!

EDIT: Got it to work using this script

//@version=5
indicator("My script", overlay = true)
DiffCloseMA = close-ta.sma(close,10)

datanew = '{"Message": "Hello World"}'

if DiffCloseMA > 0
    alert (datanew, alert.freq_once_per_bar)
else if DiffCloseMA < 0
    alert (datanew, alert.freq_once_per_bar)

plot(ta.sma(close,5))

and this as web hook URL
https://script.google.com/macros/s/AKfycbzqdmXRkOQ5HiBegwKnQMg_kO7o5OFGmdM_aW8IRapSD-5k-wVGLeMG7mAwJ6A/exec
Paddy
  • 15
  • 4

1 Answers1

0

The TradingView server, from which the POST is done, as no authorization to post to your google sheet.

For posting from pinescript, I format my message like this (be carefull it is not a message for a google sheet) :

datanew = '{
              "client": client_id, 
              "apiKey": client_API_Key, 
              "secretKey": client_Secret_Key,
              "command": "batch_cancel_active_order",
              "symbol": symbol,
              "side": side,
              "orderCategory" : orderCategory 
              }'
alert(datanew, alert.freq_once_per_bar)
G.Lebret
  • 2,826
  • 2
  • 16
  • 27
  • I have reinstalled the Google Drive extension that creates the web hook and set the permissions on the Google sheet so that anyone can edit. Still noting gets written. When I use Postman I can write no matter what permission is set on the sheet. And I am not logged on to Postman using the Google account. I assume anyone having access to the long code (AKfycbwXdAoAnggrOL2NXhyIi7L2uQKKv4bmZjg_Z67VYi6jUuNp5HmiTw78ARGVZWSHYaM7) can send data. But some how the message from Trading View is not formatted correct I guess. – Paddy Jan 09 '23 at 09:25
  • This is the extension I am using: https://workspace.google.com/marketplace/app/webhooks_for_sheets/860288437469 – Paddy Jan 09 '23 at 09:27
  • @Paddy I update my answer with how I form message in pinescript for the webhook. – G.Lebret Jan 09 '23 at 11:34