Skip to main content
Version: v27

Low-level API for saving and loading

Overview

The low-level API is recommended when you want to use save/load UI elements that are not part of the TradingView UI. With the low-level API, you can save and load chart layouts and indicator templates.

info

This approach does not support saving chart templates. Consider implementing the API handlers instead.

How to implement

To access the chart layout content directly, use the save and load methods. These methods are defined in the IChartingLibraryWidget interface and allow controlling the widget object.

// Function to store the chart layout
function storeChartLayout(layout) {
// Implement your logic here
};

const widget = new TradingView.widget(/* Widget properties */);
widget.save((layout) => { storeChartLayout(layout) }); // Save the layout using the save() method

widget.load(storedLayout); // Later in your code, you can load the stored layout

To access the indicator templates, use the createStudyTemplate and applyStudyTemplate methods. Note that you can access these methods through the chart or activeChart widget methods.

widget.onChartReady(() => {
const options = { saveSymbol: true, saveInterval: true };
const template = widget.activeChart().createStudyTemplate(options);

widget.activeChart().applyStudyTemplate(template);
});

The content is saved as a JSON object which you can save where you wish. For example, you can embed it in your saved pages or in the user's working area.

Hide save/load layout buttons

You can disable the header_saveload featureset to hide the built-in Save layout and Load layout buttons from the header toolbar.