Automated trading - Quick start guide

Updated 29.06.2020! This guide explains how to set up Traderelay v.4 to work with Tradingview.com strategies



1. Setting up Tradingview.com

1. Go to website www.tradingview.com and login. (Dont have account yet? Open account here.)
2. Create your own profitable strategy or load someone elses strategy (Our example strategy is below)

Example strategy with alerts

Its written with Pinescript v.4. Just copy-paste it to Tradingview.com


//STRATEGY CODE START
//@version=4
strategy("Traderelay 4 Example Strategy", overlay=true)

sma1 = sma(close, 14)
sma2 = sma(close, 55)
plot(sma1)
plot(sma2)
longCondition = crossover(sma1, sma2)

shortCondition = crossunder(sma1, sma2)

//ENTRIES
qt=100

//long1
if longCondition
    strategy.entry("long1", strategy.long, qt)//, when=strategy.position_size <= 0)

//exit long1
if shortCondition
    strategy.close(id="long1")
   
//short1    
if shortCondition
    strategy.entry("short1", strategy.short, qt)

//exit short1
if longCondition
    strategy.close(id="short1")

//STRATEGY CODE ENDS


2. Set up alerts in Tradingview

After your strategy is running succesfully in tradingview.com chart window. Create alert for it.

1. Go to "Alerts"-section. Create new alert.
2. Condition: choose your strategy from dropdown
3. Fill checkbox webhook. Insert webhook url: http://srv2.traderelay.net
4. Copy paste following command to messagebox (Change xxxx to your private webhook id):
action:{{strategy.order.action}} symbol:{{ticker}} qt:{{strategy.order.contracts}} id:xxxx
5. Press "Create". Thats it! Now your strategy will send alert to traderelay software everytime alert is triggered.

Additional information:
-You dont need to use variables in alert commands, but they are recommended.
-For example you can write alert message without variables like this and it would buy 100 AMD stocks: action:buy symbol:AMD qt:100 id:xxxx
-Sometimes its ok to change "symbol:{{ticker}}" to some hardcoded value if the the ticker name is different than IB symbol name. Or if you use conid.





3. Setting up TradeRelay software

-Install TradeRelay software on your computer

-Login with your email and password
-Go to Settings tab and fill in:

  • Fill in api keys for Binance, Kraken, IB, which ever exchange you want to use.
  • IB: should work on default setting if you just have IB TWS running on same computer
  • IB: Port is 7496 for IB TWS (default) and 4001 if you want to use IB Gateway

-Save settings





4. SETUP instruments to trade

You have to set atleast one instrument to instrument list before you start Traderelay software. Instrument can be paused, but there needs to be atleast one instrument so software can loop the list.

-Add instrument symbol (or its Conid) which you want to trade

-Normal stock symbols in IB are like AMD, NUGT, MCD, FB...

-FOREX symbols in IB are like JPY, CHF, EUR...

When you trade Forex symbols its usually something like USDCHF in tradingview, unfortunately symbol name is not same in IB!
-So in traderelay you need to use symbol CHF(its symbol that IB recognises) and also set your alert to send CHF in alert(see below).
Alert example for trading CHF:
action:{{strategy.order.action}} symbol:CHF qt:{{strategy.order.contracts}} cpos:{{strategy.position_size}} price:{{close}} id:xxxx





5. Select Sectype for new symbol

  • IBSTK - for stock orders to interactive brokers
  • IBCASH - for forex orders to interactive brokers
  • IBCFD - for CFD orders to interactive brokers
  • IBFUT - for Futures orders to interactive brokers
  • Binance - for all that go to Binance exchange
  • Kraken - for all that go to Kraken exchange
-If symbol or conid is for Futures, you have to select exchange for it:

  • Globex (default if nothing is chosen)
  • ECBOT
  • CFE
  • NYBOT
  • NYMEX
  • IBFUT

-Press run+ so new symbol is green on the list, and tradeable!




6. START TRADING

-Press START and TradeRelay begins to loop through your instruments -> checking received alerts -> relaying orders to exchanges.

-PLEASE TEST IT FIRST WITH PAPERTRADING OR SMALL MONEY!!





7. Setup Interactive Brokers TWS or GATEWAY

If you use Interactive brokers to trade Stocks, CFDs or Forex.

Dont have account yet? You can signup here.

-Download and install IB TWS (or IB Gateway) on your computer. It is an application that handles your orders. And its handy to see your portfolio etc.
Download IB TWS here

-Run IB TWS software and check settings: TWS -> Global configuration -> API -> Settings -> Enable Active-X and Socket Clients. (Also check that the Port is same that you use)
See screenshot of settings





Still having problems getting automated strategy running?

Due lot of help requests we now offer paid 'Developer help' for setting up all parts of automated trading (tradingview.com strategy and alerts, Traderelay and IB TWS).
You can check it at our Subscription page.