Type/to search
Getting Started
Platform Basics
Exchange
Docker
Strategy Library
Live Trading
Trading Terminal
Plugin Principle and Development
Plugin Examples
Account and Billing
Writing Strategies
Development Tools
Backtesting System
Advanced Topics
Data and Research
Extended API Interface

A plugin runs code for a limited time to do simple jobs such as iceberg orders, placing and cancelling orders, or calculations. It returns its result with return; a returned table or chart object is displayed as a table or chart. Two examples follow; more can be found in the Strategy Square, e.g. buying or selling in small slices.

Order book snapshot

Show the top 15 levels of the current order book as a table:

javascript
// Return an order book snapshot function main() { var tbl = { type: 'table', title: 'Depth snapshot @ ' + _D(), cols: ['#', 'Amount', 'Ask', 'Bid', 'Amount'], rows: [] } var d = exchange.GetDepth() if (!d) { return 'failed to get the order book' } var n = Math.min(d.Asks.length, d.Bids.length, 15) for (var i = 0; i < n; i++) { tbl.rows.push([i, d.Asks[i].Amount, d.Asks[i].Price + '#ff0000', d.Bids[i].Price + '#0000ff', d.Bids[i].Amount]) } return tbl }
Calendar spread chart

On a futures exchange object, take 5-minute K-lines of the quarterly and the weekly contract and chart the difference of their closes:

javascript
// Chart the calendar spread var chart = { __isStock: true, title: {text: 'Spread analysis'}, xAxis: {type: 'datetime'}, yAxis: { title: {text: 'Spread'}, opposite: false }, series: [ {name: "diff", data: []} ] } function main() { exchange.SetContractType('quarter') var recordsA = exchange.GetRecords(PERIOD_M5) exchange.SetContractType('this_week') var recordsB = exchange.GetRecords(PERIOD_M5) if (!recordsA || !recordsB) { return 'failed to get K-lines' } var n = Math.min(recordsA.length, recordsB.length) for (var i = 0; i < n; i++) { var a = recordsA[recordsA.length - n + i] var b = recordsB[recordsB.length - n + i] chart.series[0].data.push([a.Time, a.Close - b.Close]) } return chart }