PineTrader Library Tutorial
Watch our video tutorial for a visual guide.
Overview
The PineTrader library automates order ticket generation for TradingView strategies, eliminating the need for manual JSON payload creation.
Implementation Steps
Import Library
import pinetraderinc/PineTraderLibrary/1 as [VARIABLE]
Create Order Tickets
var LongOT = [VARIABLE].GenerateOT(**Params)
var ShortOT = [VARIABLE].GenerateOT(**Params)
var CloseOT = [VARIABLE].GenerateOT(**Params)
Configure Trade Execution
Choose your preferred method:
Method 1: Strategy Integration
// Entry Trades
strategy.entry(**Params, alert_message=LongOT)
strategy.entry(**Params, alert_message=ShortOT)
// Exit Trade
strategy.exit(**Params, alert_message=CloseOT)
Method 2: Custom Alert Control
Use alert()
function for more granular control over trade execution.
Webhook Configuration
⚠️
Configure your TradingView webhook settings correctly for proper execution.
- Enable webhook in alert settings
- Set message field to:
{{strategy.order.alert_message}}
- If you add a
alert()
in your pinescript strategy, you will see a dropdown menu prompting you when to send the alerts:- A) Order fills and
alert()
function calls - B) Order fills only
- C)
alert()
function calls only
- A) Order fills and
Resources
Common Implementation Patterns
Strategy Integration
//@version=5
strategy("My Strategy", overlay=true)
// Import library
import pinetraderinc/PineTraderLibrary/1 as pt
// Generate order tickets
if (longCondition)
var ticket = pt.GenerateOT(
license_id="your_license",
symbol=syminfo.ticker,
action="MRKT",
order_type="BUY",
trade_type="SINGLE"
)
strategy.entry("Long", strategy.long, alert_message=ticket)
Alert-Based Execution
//@version=5
indicator("My Indicator", overlay=true)
// Import library
import pinetraderinc/PineTraderLibrary/1 as pt
// Generate and send order ticket
if (alertCondition)
var ticket = pt.GenerateOT(**Params)
alert(ticket, alert.freq_once_per_bar)