# Plots

## Introduction

In the Automated Trading System (ATS), you can monitor your trading activities through visual plots—currently, only time-series data is supported. These plots are consistent across both live-trading and back-testing modes.

The `BaseExchange` class manages plot data using the `PlotData` class. If you wish to configure custom plots, such as technical indicators, you can do so by utilizing the `PlotData` object within your exchange class (which extends `BaseExchange`). Adding custom plots to your strategy is straightforward because the exchange object is injected into the strategy object. You can access the `PlotData` object by calling `get_plot_data()` on the exchange object.

However, ATS also provides a default set of preconfigured plots at the `BaseExchange` level. This means you can generate basic plots immediately without any additional customization. The following is a list of available default plots:

<table><thead><tr><th width="302">Plot Name</th><th>Description</th></tr></thead><tbody><tr><td>Candle Close Price</td><td>Time series of candle close price.</td></tr><tr><td>LIMIT Order Placed: Buy</td><td>A time series containing the locations of LIMIT Buy order placements.</td></tr><tr><td>LIMIT Order Placed: Sell</td><td>A time series containing the locations of LIMIT Sell order placements.</td></tr><tr><td>LIMIT Order Completed: Buy</td><td>A time series containing the locations of LIMIT Buy order fulfilments.</td></tr><tr><td>LIMIT Order Completed: Sell</td><td>A time series containing the locations of LIMIT Sell order fulfilments.</td></tr><tr><td>MARKET Order Completed: Buy</td><td>A time series containing the locations of MARKET Buy order placements.</td></tr><tr><td>MARKET Order Completed: Sell</td><td>A time series containing the locations of MARKET Sell order placements.</td></tr><tr><td>Order Canceled: Buy</td><td>A time series containing the locations of Buy order cancellations.</td></tr><tr><td>Order Canceled: Sell</td><td> time series containing the locations of Sell order cancellations.</td></tr><tr><td>Order Rejected: Buy</td><td>A time series containing the locations of Buy order rejections.</td></tr><tr><td>Order Rejected: Sell</td><td>A time series containing the locations of Sell order rejections.</td></tr></tbody></table>

***

## Time Series Data Types

The `PlotData` class currently supports two types of time series data:

1. **Markers**: Used for generating scatter plots. Each marker data point includes the following parameters:
   * **topic**: The topic associated with the marker.
   * **time**: The timestamp of the marker.
   * **num**: The numerical value of the marker.
   * **label**: A string label for the marker, such as an order ID or whether it is a buy or sell order. When hovering over the data point in the scatter plot, this label will be displayed.
2. **Lines**: Used for creating continuous line chart time series plots. Each data point for a line plot includes the following parameters:
   * **topic**: The topic associated with the line.
   * **time**: The timestamp of the data point.
   * **num**: The numerical value of the data point within the line.

***

## Plot Data Config Structure

The [quickstart-5](../apis/quickstart-5 "mention") API allows you to configure the plots you wish to view and provides guidelines on how these plots are arranged. For example, you can define specific plots to be layered on top of one another or create subplots arranged in a grid view.&#x20;

A plot configuration consists of an array of JSON objects that define the layout and details of each plot. The structure of a **plot layout configuration** JSON object is outlined below. Please note that these objects are wrapped within an array, allowing for multiple layout configurations. Even if there is only one element, it will still be contained within an array.

```
{
  "cols": 1,
  "rows": 2,
  "length": -1,
  "name": "Price Chart",
  "plot_compressed": true,
  "plot_compressed_size": 10000,
  "plots": [{...}, {...}]
}
```

<table><thead><tr><th width="216">Property</th><th>Description</th></tr></thead><tbody><tr><td>cols</td><td>Number of columns in the layout</td></tr><tr><td>rows</td><td>Number of rows in the layout</td></tr><tr><td>length</td><td>Length of data to be plotted (last n time series data). Use -1 for plotting everything.</td></tr><tr><td>name</td><td>This is the plot name. It is <strong>just a title</strong> and is <strong>not</strong> related to plot names configured in the PlotData object within the Exchange or the Strategy objects.</td></tr><tr><td>plot_compressed</td><td>Boolean variable.<br>If set to <code>true</code>, the plot is compressed into <code>plot_compressed_size</code> number of bins. As an example assume that you have a time series with 1000000 data. But due to your browsers memory requirements, you need to represent the plot in just 10000 points (low resolution plot). In that case, you can set this flag to <code>true</code> and compressed the plot data passed to the front end.</td></tr><tr><td>plots</td><td><code>plots</code> parameter contains an array of plots. In each object, a plot is referred by its name and it also has a column number and a row number indicating where to place the plot. See the following examples to understand more about the configuration.</td></tr></tbody></table>

Below are some examples of different plot configurations (You will find the entire config in the JSON config file provided in [sample-trading-configs](../getting-started/sample-trading-configs "mention")):

### Creating a Price Chart Based on Closed Price&#x20;

In this example, the plot configuration defines a plot arranged in a 1-column by 1-row layout, displaying all data points in the time series (with the `length` set to 1). The plot is titled "My Cool Price Chart" and is configured to be compressed into 10,000 bins. The layout places one plot in column 1, row 1, which represents the "Candle Close Price" time series.

```json
[
  {
    "cols": 1,
    "rows": 1,
    "length": -1,
    "name": "My Cool Price Chart",
    "plot_compressed": true,
    "plot_compressed_size": 10000,
    "plots": [
      {
        "col": 1,
        "row": 1,
        "topic": "Candle Close Price"
      }
    ]
  }
]
```

This produces a chart similar to the following.

<figure><img src="https://2746252044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA2awBtq48tyAooIk6oKT%2Fuploads%2FABq8yhtOG5YKJzFk0bV7%2Fimage.png?alt=media&#x26;token=92633083-fc52-4574-8292-c0ce5806e7b5" alt=""><figcaption><p>Sample Plot 1: Price chart</p></figcaption></figure>

### Plotting Order Locations on a Price Chart

In the following example, we are extending the plots in the same 1-column by 1-row layout but with scatter plots to show order locations, order fulfilments, order cancellations and order rejections.&#x20;

To understand scatter plot marker shape and color configurations, please refer to [adding-a-new-plot](../customizations/adding-a-new-plot "mention") section.

```json
[
  {
    "cols": 1,
    "rows": 1,
    "length": -1,
    "name": "My Cool Price Chart",
    "plot_compressed": true,
    "plot_compressed_size": 10000,
    "plots": [
      {
        "col": 1,
        "row": 1,
        "topic": "Candle Close Price"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "LIMIT Order Placed: Buy"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "LIMIT Order Placed: Sell"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "LIMIT Order Completed: Buy"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "LIMIT Order Completed: Sell"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "MARKET Order Completed: Buy"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "MARKET Order Completed: Sell"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "Order Canceled: Buy"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "Order Canceled: Sell"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "Order Rejected: Buy"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "Order Rejected: Sell"
      }
    ]
  }
]
```

This configuration creates a plot similar to the following.

<figure><img src="https://2746252044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA2awBtq48tyAooIk6oKT%2Fuploads%2Fc9qW04kLFBdQ5EVp15Vc%2Fimage.png?alt=media&#x26;token=41f778f9-e605-454f-b2bc-fd2c1f027db7" alt=""><figcaption><p>Sample Plot 1: Price chart with order locations</p></figcaption></figure>

### Plotting an Indicator on Below the Price Chart

In this example, we are expanding the previous configuration by create a 1-column by 2-row layout and placing the RSI indicator plot just below the price chart.

Note that the rows is set to 2 and at the end of the configuration, we have added the RSI index plot and placed it in column number 1 and row number 2.

```json
[
  {
    "cols": 1,
    "rows": 2,
    "length": -1,
    "name": "Price Chart",
    "plot_compressed": true,
    "plot_compressed_size": 10000,
    "plots": [
      {
        "col": 1,
        "row": 1,
        "topic": "Candle Close Price"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "LIMIT Order Placed: Buy"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "LIMIT Order Placed: Sell"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "LIMIT Order Completed: Buy"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "LIMIT Order Completed: Sell"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "MARKET Order Completed: Buy"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "MARKET Order Completed: Sell"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "Order Canceled: Buy"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "Order Canceled: Sell"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "Order Rejected: Buy"
      },
      {
        "col": 1,
        "row": 1,
        "topic": "Order Rejected: Sell"
      },
      {
        "col": 1,
        "row": 2,
        "topic": "RSI"
      }
    ]
  }
]
```

This is a sample plot layout generated by the above configuration.

<figure><img src="https://2746252044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA2awBtq48tyAooIk6oKT%2Fuploads%2F1MiASwLKpkJLmv5qb0Fn%2Fimage.png?alt=media&#x26;token=fa53c597-3c13-4c4b-9b8d-ad5bb7f83797" alt=""><figcaption><p>Sample Plot 1: Price chart with RSI index</p></figcaption></figure>

### Configuring Multiple Plot Layouts

In earlier sections, we covered how to configure a single layout. However, it's also possible to include multiple layout configurations within the same plot configuration JSON.

Refer to the plot configuration example provided in the [sample-trading-configs](../getting-started/sample-trading-configs "mention") section to understand how to set up multiple plot configurations.

When multiple plot layouts are configured, the resulting plot view will appear as shown below.



<figure><img src="https://2746252044-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FA2awBtq48tyAooIk6oKT%2Fuploads%2FJXvNPeMB7sm9HU8PJGf3%2Fimage.png?alt=media&#x26;token=600a1ad5-70cb-47b6-a218-8c8d25bd8485" alt="" width="563"><figcaption></figcaption></figure>
