Complete Setup Guide

Follow these step-by-step instructions to connect TradingView alerts with Interactive Brokers through Traderelay for automated trading.

Setup Time: ~30 minutes
Test with paper trading first
No coding required
1

Setup TradingView.com

  1. Go to www.tradingview.com and login. (Need an account? Open account here)
  2. After login, go to chart screen and choose AMD as symbol
  3. Press 'Pine Editor' tab below the chart
  4. Copy-paste the example strategy code below
  5. Press Save, then Add to Chart

Example Strategy Code (Pine Script v4)

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

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

//ENTRIES
qt=1

//entry long
plotshape(longCondition, style=shape.labelup, location=location.belowbar, color=color.new(color.green, 0), size=size.tiny, title='longCondition', text='longCondition', textcolor=color.new(color.white, 0))
alertcondition(longCondition, title='longCondition', message='action:LONG symbol:{{ticker}} qt:1 id:xxxx')

//entry short
plotshape(shortCondition, style=shape.labeldown, location=location.abovebar, color=color.new(color.red, 0), size=size.tiny, title='shortCondition', text='shortCondition', textcolor=color.new(color.white, 0))
alertcondition(shortCondition, title='shortCondition', message='action:SHORT symbol:{{ticker}} qt:1 id:xxxx')

//STRATEGY CODE ENDS
2

Setup Alerts in TradingView

Create alerts that will send LONG or SHORT commands to Traderelay and onwards to real exchanges.

Create Alert

  1. Go to "Alerts" section (upper right navigation)
  2. Condition: Choose your study ("Traderelay 4 Example Study")
  3. Select "Once per bar close"
  4. Check "webhook" checkbox
  5. Insert webhook URL: http://srv3.traderelay.net
  6. Replace xxxx with your personal webhook ID (get this from Traderelay software)
  7. Press "Create"

Available Commands

LONGaction:LONG symbol:AMD qt:1 id:xxxx Opens long position (closes short if exists)
SHORTaction:SHORT symbol:AMD qt:1 id:xxxx Opens short position (closes long if exists)
CLOSEaction:CLOSE symbol:AMD id:xxxx Closes any existing position
3

Setup Traderelay Software

Install and configure TradeRelay software on your computer.

1. Set TWS Port (Optional)

  • Login with your email and password
  • Go to Settings tab and set TWS port: 7497 (IB TWS default)
  • Save settings

2. Setup Instruments

  • Add instrument symbol: AMD
  • Choose AMD from list and click IB (Stock market)
  • This sets the exchange to IB stock market

3. Start Traderelay

  • Press START to begin monitoring
  • TradeRelay will loop through instruments, checking for alerts
  • TEST WITH PAPER TRADING FIRST!
4

Setup Interactive Brokers & TWS

Account Setup

  1. Open Interactive Brokers account: Open IB Account
  2. Download and install TWS software

TWS Configuration

  1. Start TWS software
  2. Go to: File → Global Configuration → API → Settings
  3. Configure the following:
    ✓ Enable ActiveX and Socket Clients
    ✓ Uncheck "Read-Only API"
    ✓ Set port: 7497
    ✓ Press APPLY to save
  4. Allow 'Trader Workstation' through Windows firewall

Testing Connection

  1. Login to TWS paper trading mode
  2. In Traderelay: Add 'AMD' instrument and set to 'IB (Stock market)'
  3. Start Traderelay looping
  4. Press 'Send Test Order' button
  5. Verify AMD stock purchase appears in TWS

Setup Complete

After completing all 4 steps, you should be able to run automated trading during market hours. Remember that market orders only execute when markets are open.

Final Checklist:

TradingView.com is sending alerts with your webhook ID
Traderelay is looping and waiting for alerts
IB account funded and TWS running

Firewall Settings (Optional)

Usually no firewall changes are needed, but if alerts aren't forwarding to TWS:

  1. Allow Traderelay software through Windows firewall (in and out)
  2. Allow TWS software through Windows firewall (in and out)
Note: This allows Traderelay to communicate with TWS and send orders to Interactive Brokers.