Tag Archive for: Cryptocurrencies

Tradingview strategy vs study markers2

Tradingview made a big step ahead in 2019 by introducing webhooks, which can be used finally to automate Tradingview scripts. Clearly this approach still has its limits due to the missing feedback channel back to the Tradingview script; it’s still submitting orders into a black hole and hope they get executed as intended.

The following steps describe how a Tradingview Pine script can be connected to Alertatron. For details how Alertatron works and how the overall command-set looks like, please take a look here.

I hope that the following steps do explain how to automate a Tradingview script via Alertatron. If you have questions, or want to automate another script, please contact me.

Setting up Alertatron

If you don’t have a login at Alertatron, please create one.

Then create a new set of API keys bby clicking on “Configure API Keys”.

Setup Alertatron 1

In the now appearing dialog select the exchange you want to submit your orders to, a unique name for the key (only characters, no numbers), the “Key” and the “Secret”. Click on “Add API keys and restart service”.

Setup Alertatron 2

Setting up the Tradingview Pine script

Tradingview “study” scripts can be automated by using the built-in function alertcondition. Via the alertcondition message attribute a static/const message can be predefined, which can be used as a preset for the next step in Tradingview to connect the alertcondition to an alert, which is hosted in the Tradingview server-side. Please keep in mind that until today, the message attribute is a const string, that means it can not be assembled dynamically at the runtime of the script!

The example below shows two messages: one for entering a long and one for entering a short position. The tag “#bot” is required to connect the following instruction to a trading bot at Alertatron; Alertatron also supports Telegram messages for instance. The term “BitmexKeyOne(XBTUSD)” defines the name of the keys you have entered at Alertatron, and XBTUSD defines the instrument you want to trade at the exchange. Everything else within the curly brackets is the command set defined by Alertatron, to:

  1. cancel all open orders
  2. create a long/short market order wit the targeted position size of 25
  3. create a OCO profit-target and stop-loss order, when the previous long/short market order has been executed

All these sets could also be separated, and the Tradingview Pine script could manage the profit and stop-loss orders. But, Alertatron provides the mechanism to take care of complex orders, and it can submit these follow-up orders faster w/o any delay, while the executing of the Pine script depends on the used settings. Also, Crypto-APIs, like Bitmex REST API, are notorious for being not accessible when the market is going strongly up or down; that would mean that profit and stop-loss orders will be executed with a delay or not at all.

alertcondition(condEnterLong, title='Enter Long', 
   message='Enter Long 
      #bot BitmexKeyOne(XBTUSD) { 
         cancel(which=all); 
         managed(side=buy, 
            position=25, 
            entry=market, 
            takeProfit=1.0%, 
            stopLoss=2.0%) }')
alertcondition(condEnterShort, title='Enter Short', 
   message='Enter Short 
      #bot BitmexKeyOne(XBTUSD) { 
         cancel(which=all); 
         managed(side=sell, 
            position=-25, 
            entry=market, 
            takeProfit=1.0%, 
            stopLoss=2.0%) }')

Enabling the Alert(s) in Tradingview

alertconditions by itself cannot trigger any email or popup or webhook. They need to be manually enabled in the Tradingview environment to generate a real alert.

1. Please select the “study” script for which you want to enable an alert, click on the 3 dots, and select “Add Alert on …”

Tradingview enable alerts 1

2. In the Alert pop-up dialog select

  • how often the alert shall be triggered – recommended setting here is “Once Per Bar” or “Once Per Bar Close”
  • the alert actions; check the box for “Webhook URL” (provided by Alertatron)
  • modify the predefined message with the Alertatron instructions
  • click on “Create”. This creates an alert which is hosted on the Tradingview server-side; the number of alerts someone can create depends on the Tradingview subscription type. The alerts are hosted off you local machine, so you don’t need to keep your PC and browser running!

Tradingview enable alerts 2

In the past I was typically developing strategies and indicators for automated Forex and Futures trading, using Ninjatrader, Tradingview and Metatrader. But since some time I get more and more requests for trading cryptocurrencies. There are clearly a lot of tools out there for Crypto-trading, however there are in my opinion very basic, typically using Python scripts and missing all nice features you got used to, like backtesting and optimization.

Therefore I want to focus here on options which do exists to my knowledge, automatically trading Cryptocurrencies while using a sophisticated trading environment/tool. With automatically trading I mean using a bot or tool which runs a strategy 24/7 unobserved.

The options listed below are just a quick overview, for detailed description of installation and usage please shoot us an email.

Ninjatrader 8

While NinjaTrader 8 is great in automation and scripting, it does not support trading cryptocurrencies out of the box. But there are now options out there which add Cryptocurrency support to NinjaTrader 8. Clearly the advantage of this solution is the rich and complete scripting (C# .NET language support), backtesting and optimization features of NinjaTrader.

NinjaTrader 8 is free for backtesting w/o any limitation, but must be leased or bought for trading live accounts, however for the Add-Ons listed below, this requirement does not exist.

Coinbase NinjaTrader Integration

The latest NinjaTrader 8 version supports Coinbase API natively. However, it only implements the market data API; it does not allow live-trading.

BitMEX NinjaTrader Integration

Link: see here

This integration allows access to the BitMEX market data, which allows leverages Cryptocurrency trading.

Unfortunately the API only integrates market data, but does not come with trading support. So it can be leveraged for backtesting e.g. XBTUSD in NinjaTrader 8, but for live-trading someone has to look for another solution.

Poloniex, Binance, Bitfinex, Deribit, BinancePlus Add-Ons

Link: see here

The Add-Ons are typically in the $150 to $250 area. If added to NinjaTrader they allow to access market data, but also enable trading of Cryptocurrencies.

I personally use the Binance adapter for some time, and didn’t find any bigger issues. One minor issue seems to be the fact that NinjaTrader’s internal performance handler can’t deal with split order executions, where one split has the size 0; this seems to happen only at certain Crypto-exchanges.

However, these Add-Ons don’t have the official NinjaTrader blessing, so you can’t expect any support from the NinjaTrader. 

Tradingview and Autoview Chrome extension

Tradingview is a great tool in regard to charting, quick implementation of ideas, it supports a zillion of Crypto-exchanges, but lacks automation. Latter is clearly a big minus. However, even if supported the question would remain how useful it would be running a strategy 24/7 in a Chrome browser environment.

That being said, there is a Chrome extension out there, called Autoview, which uses Tradingview Pine script alerts to trigger orders. Bit disadvantage of this solution is that there is no feedback about the trades, it’s basically submitting orders blindly into the dark 

The Chrome extension costs $5 per month, or $50 per year and can be found here: https://autoview.with.pink/. Tradingview is free, but also provides subscriptions, which do enable more features.

The built-in Pine script feature allows to add own strategies and indicators. But the features of Pine are clearly limited and can hardly be compared with the scripting capability of NinjaTrader for instance.

Please shoot us an email for any detailed question about the NinjaTrader and Tradingview features and support.