The TradeVisualization generator displays trade transactions (buys and sells) directly on the chart. Each transaction is rendered as an info box above the corresponding candle.
Use a Controller object to add the generator to a chart:
const tradeVisualizationGenerator = controller.addGenerator('TradeVisualization');
type BaseTransaction = {
ts: number;
units: number;
quote: number;
currency: string;
};
type BuyTransaction = BaseTransaction & {
direction: 'buy';
};
type SellTransaction = BaseTransaction & {
direction: 'sell';
profitLoss: number;
};
type Transaction = BuyTransaction | SellTransaction;
type Trade = {
id: number;
visualizeQuotes: boolean;
transactions: Transaction[];
};
ts: timestamp of the transactionunits: number of units tradedquote: execution pricecurrency: currency symbol for displaydirection: 'buy' or 'sell'profitLoss: profit or loss amount (sell transactions only)id: unique identifier for the tradevisualizeQuotes: when true, vertical markers are drawn at the quote price for each transactiontransactions: array of individual transactions belonging to the tradeThe generator exposes the following public method.
Type
interface TradeVisualizationGenerator {
addTrade(trade: Trade): boolean;
}
Details
addTrade takes a Trade object and adds it to the chart. Each transaction in the trade will be rendered at its corresponding timestamp position on the chart. The method returns true if the trade was successfully added, or false if chart data is not available.
After adding a trade, the chart will automatically zoom to show all transactions with some padding.
Example
// example usage:
const success = tradeVisualizationGenerator.addTrade({
id: 1,
visualizeQuotes: true,
transactions: [
{
ts: 1700000000000,
units: 100,
quote: 150.25,
currency: '€',
direction: 'buy',
},
{
ts: 1700500000000,
units: 100,
quote: 155.50,
currency: '€',
direction: 'sell',
profitLoss: 525.00,
},
],
});
Transaction info boxes are color-coded based on their type:
Each info box displays:
When visualizeQuotes is set to true, vertical markers are additionally drawn on the price scale at each transaction's quote price.
NONE descriptor flag means it is not listed in the UI generator menu - it is intended to be added programmatically.