Python and TradingView alerts

nuu

Neophyte
Joined
Mar 15, 2019
Messages
5
Reaction score
1
Location
Singapore
Does anyone have an example OR ideas on how to get signals/alerts from TradingView? Or what would be the best/most reliable way to get it? A long winded way seems to be getting the signal sent to my email and then have python comb through my email and find the signal.

Thanks.
 

nuu

Neophyte
Joined
Mar 15, 2019
Messages
5
Reaction score
1
Location
Singapore
Below is my TradingView screen. Just a simple BNBBTC chart with the "KISS with Heiken Arrows with Alerts" indicator. I am very new to this. So I assume that the TradingView will generate the alert (with the right plan) when the Arrows (and alerts) are triggered and it will be sent to email/sms?. What I am trying to do is find a way to read this signal and then trigger my python bot to buy/sell etc. So I envision a loop that wakes every x secs and checks if there is a signal e.g. email or sms. If there are sample codes or tutorial, it would be much appreciated.

82

Thank you.
 

Entelechy

Stadivm Owner
Staff member
Joined
Jul 8, 2018
Messages
161
Reaction score
30
Location
Stadivm.com
Right, I get you. Have you considered pulling the data directly from Binance API and then building the indicators into an algo that connects directly to your trading module (for buys/sells)?

If you're new to it (but obviously can code in Python from what you've said in the last msg), you could use/modify the Binance API script I've put up here: https://stadivm.com/threads/binance-api-data-gathering-script-download-stadivm-guides-and-walkthroughs.155/

I'd say that if you just want to focus on these indicators, you could use the parts of the script that pull the raw data from Binance, and then create your own indicators based on that data.

I''m not familiar with "KISS with Heiken Arrows with Alerts", but what exactly do those indicators show?
 

nuu

Neophyte
Joined
Mar 15, 2019
Messages
5
Reaction score
1
Location
Singapore
Yep, I had read your scripts. It's very well done, clean and readable. That is my next step should this fail.

I would guess the indicator is based on the Heiken Ashi chart (trying to detect trend change). https://tradingstrategyguides.com/heiken-ashi-strategy/

On a different note, one of the features of the tradingview custom indicator is that the author of the script could craft a signal/alert based on a bunch of basic/other custom indicators. The source of the script is in Pine language which is a custom tradingview language. It is hidden unless the author choose to share. As a general user, we can use the indicator and get alerts but won't be able to view the indicator source. Hence the search for a way to pull the alerts programmatically.

Ideally, the alerts would trigger a set of signal validation (using codes sample from your script) to confirm the buy and then enter the market. That's where I am trying to go with this :).
 

Entelechy

Stadivm Owner
Staff member
Joined
Jul 8, 2018
Messages
161
Reaction score
30
Location
Stadivm.com
The strat in Heiken Ashi is a nice (the specific steps they describe) + I haven't heard of it before. I'd say your original point to feed email alerts to an execution script sounds like the most direct way to do it. Do you have to sign up for a TV plan in order to be able to receive those signals/alerts?

From a completely different angle, I wonder if there's anyway to web scrape the alerts. It's more complicated than email alerts but maybe with a combination of using Selenium to log into your account and then a loop to scrape the chart and send your own alert to the execution module would work without needing to directly access the Tradingview system.
 

adamng

Neophyte
Joined
May 1, 2019
Messages
3
Reaction score
3
Location
Malaysia
Another way is to create a Chrome extension to listen to TV alerts. It's complicated and you probably have to update the extension code whenever TV decides to change their web page source code or HTML ids. So far processing email alerts from TV seems like to be the most sensible method.

Below is a snippet from "TradingView Alerts" extension.

JavaScript:
    start: function (privateChannel) {
        if (this.status !== NOT_STARTED) {
            return;
        }
        console.info("ProfitRobots: Starting alert listener");
        this.status = STARTED;
        this.privateChannel = privateChannel;
        const lastEventId = window.localStorage.getItem("last_event_id") || "";
        const url = "https://pushstream.tradingview.com"
            + "/message-pipe-es/public/"
            + "private_" + this.privateChannel
            + "?_=" + Math.floor(Date.now() / 1000)
            + "&tag="
            + "&time="
            + "&eventid=" + lastEventId

        this.eventSource = new EventSource(url)
        this.eventSource.onerror = (e) => {
            console.info("ProfitRobots: Error", e);
            if (e.target.readyState === EventSource.CLOSED) {
                this.status = NOT_STARTED;
            }
        }
        this.eventSource.onmessage = (e) => {
            try {
                const data = JSON.parse(e.data);
                if (typeof data !== "object" || data === null) {
                    return;
                }
                if (data.channel !== "private_" + this.privateChannel) {
                    return;
                }
                const response = JSON.parse(data.text.content);
                if (typeof response !== "object" || response === null) {
                    return;
                }
                if (response.m !== "event") {
                    return;
                }
                window.localStorage.setItem("last_event_id", response.p.id);
                console.info("ProfitRobots: Message detected", response.p.desc);
                this.sendAlert(response.p.desc, response.p.sym, this.parseResolution(response.p.res));
            }
            catch(e) {
            }
        }
        this.eventSource.onopen = () => {
        }
    },