14 - TradingView & GoCharting

Overview

OpenAlgo integrates with TradingView and GoCharting platforms to receive trading signals via webhooks. These charting platforms can trigger automated trades when alert conditions are met.

Architecture Diagram

┌──────────────────────────────────────────────────────────────────────────────┐
│                   TradingView / GoCharting Integration                        │
└──────────────────────────────────────────────────────────────────────────────┘

┌─────────────────────────────────────────────────────────────────────────────┐
│                    TradingView / GoCharting                                  │
│                                                                              │
│  ┌─────────────────────────────────────────────────────────────────────┐   │
│  │  Pine Script Strategy / Alert                                        │   │
│  │                                                                      │   │
│  │  strategy.entry() → Webhook trigger                                 │   │
│  │  strategy.exit()  → Webhook trigger                                 │   │
│  │  alert()          → Webhook trigger                                 │   │
│  └─────────────────────────────────────────────────────────────────────┘   │
└─────────────────────────────────────────────────────────────────────────────┘

                              │ HTTP POST (Webhook)

┌─────────────────────────────────────────────────────────────────────────────┐
│                     OpenAlgo REST API                                        │
│                                                                              │
│  POST /api/v1/placeorder      (Simple orders)                               │
│  POST /api/v1/placesmartorder (Position-based orders)                       │
└─────────────────────────────────────────────────────────────────────────────┘

TradingView Webhook Setup

Webhook URL

Alert Message Format

Pine Script Variables

Variable
Description
Example

{{ticker}}

Trading symbol

SBIN

{{strategy.order.action}}

BUY or SELL

BUY

{{strategy.order.contracts}}

Order quantity

100

{{close}}

Closing price

625.50

{{time}}

Alert time

2024-01-15T09:30:00

Symbol Format Examples

Equity

Index Futures (NFO - Expires Tuesday)

Index Options (NFO - Expires Tuesday)

Bank Nifty Options (NFO - Expires Tuesday)

SENSEX Options (BFO - Expires Thursday)

Lot Sizes Reference

Index
Lot Size
Exchange
Expiry

NIFTY

65

NFO

Tuesday

BANKNIFTY

30

NFO

Tuesday

FINNIFTY

25

NFO

Tuesday

MIDCPNIFTY

50

NFO

Monday

SENSEX

20

BFO

Thursday

BANKEX

30

BFO

Monday

Smart Order for Position Management

Webhook URL

Alert Message

Position Size Logic

Current Position
position_size
Result

0

100

BUY 100

100

0

SELL 100 (close)

100

-100

SELL 200 (reverse)

-50

50

BUY 100 (reverse)

GoCharting Webhook Setup

Webhook URL

Alert Message

Same format as TradingView:

JSON Generator Endpoints

OpenAlgo provides JSON generators for easy webhook configuration:

TradingView JSON Generator

Endpoint: /tv-json

Features:

  • Select symbol, exchange, product

  • Generate webhook JSON

  • Copy to clipboard

GoCharting JSON Generator

Endpoint: /gc-json

Features:

  • Select symbol, exchange, product

  • Generate webhook JSON

  • Copy to clipboard

Price Types

Price Type
Description
Required Fields

MARKET

Execute at market price

-

LIMIT

Execute at specific price

price

SL

Stop Loss Limit

price, trigger_price

SL-M

Stop Loss Market

trigger_price

Complete Webhook Examples

Intraday Equity Buy

Delivery Equity Buy

NIFTY Option Buy (Tuesday Expiry)

SENSEX Option Buy (Thursday Expiry)

Key Files Reference

File
Purpose

blueprints/tv_json.py

TradingView JSON generator

blueprints/gc_json.py

GoCharting JSON generator

restx_api/place_order.py

Order placement API

restx_api/place_smart_order.py

Smart order API

templates/tv_json.html

TV JSON generator UI

templates/gc_json.html

GC JSON generator UI

Last updated