# Save user settings

## Overview

User settings are settings that remain regardless of the applied [chart layout].
They are stored separately from chart layouts to ensure that users have control over their specific preferences.
For example, the *Instant orders placement* setting in [Trading Platform] allows users to place orders without confirmation.
This setting is a part of user settings and is not saved when users save the chart layouts.
Saving this setting within a chart layout could lead to unexpected user experiences and is considered a bad practice.

### Settings list

User settings include:

- [Resolution]
- Order type and quantity in the [Order Ticket]
- *Chart settings → Trading*
  - *Buy/Sell buttons*
  - *Instant orders placement*
  - *Play sound for executions*
  - *Notifications*
- *Summary row* in the [Account Manager]
- Right and bottom widget bars view
- Chart style
- [Watchlist]

### How to store

There are two options for storing user settings:

- Using the browser's [`localStorage`], which is enabled by default.
    To disable this option, include the [`use_localstorage_for_settings`] featureset in the [`disabled_features`] array.
- Implementing your preferred storage method, including the server-side one.
    For this, use the [`settings_adapter`](#settings-adapter) property of the [Widget Constructor].

## Settings adapter

You can save user settings using the [`settings_adapter`] property of the [Widget Constructor].
This property allows not only storing settings in the preferred storage but also applying them to the chart.

:::info

The library provides multiple approaches to modify the chart's appearance and behavior, and `settings_adapter` is one of them.
These approaches have a specific application order, meaning they may override any styles or settings applied by other approaches lower on the list.
Refer to [Customization precedence] for more information.

:::

The `settings_adapter` property accepts an object implementing the [`ISettingsAdapter`] interface.
Use the [`initialSettings`] property to specify the settings the chart should be initiated with.
Also, implement the [`setValue`] and [`removeValue`] methods.
These methods are **required** for the adapter to function correctly, even if you don't plan to modify settings dynamically.

Consider the code sample below that does the following:

- Sets a watermark on the chart when the chart is initialized.
- Sets settings (10 units of shares and the *limit* order type) for the Order Ticket when the chart is initialized.
- Logs actions in the console when settings are set or removed.

```js
new TradingView.widget({
    /* Other properties */

    settings_adapter: {
        initialSettings: {
            "symbolWatermark": '{ "visibility": "true", "color": "rgba(244, 67, 54, 0.25)" }',
            "trading.Broker": '{"qty": {"AAPL": 10, "NasdaqNM:AAPL": 10}, "orderType": {"NasdaqNM:AAPL": 3}}',
        },
        setValue: function (key, value) {
            console.log(`set value: ${key} ${value}`);
        },
        removeValue: function (key) {
            console.log(`remove value: ${key}`);
        },
    }
})
```

[Account Manager]: https://charting-library-docs.xstaging.tv/latest/trading_terminal/account-manager.md
[chart layout]: https://charting-library-docs.xstaging.tv/latest/saving_loading.md#chart-layouts
[Customization precedence]: https://charting-library-docs.xstaging.tv/latest/customization/customization-precedence.md
[`disabled_features`]: https://charting-library-docs.xstaging.tv/latest/api/interfaces/Charting_Library.ChartingLibraryWidgetOptions#disabled_features
[`initialSettings`]: https://charting-library-docs.xstaging.tv/latest/api/interfaces/Charting_Library.ISettingsAdapter#initialsettings
[`ISettingsAdapter`]: https://charting-library-docs.xstaging.tv/latest/api/interfaces/Charting_Library.ISettingsAdapter
[`localStorage`]: https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
[Order Ticket]: https://charting-library-docs.xstaging.tv/latest/trading_terminal/order-ticket.md
[`removeValue`]: https://charting-library-docs.xstaging.tv/latest/api/interfaces/Charting_Library.ISettingsAdapter#removevalue
[Resolution]: https://charting-library-docs.xstaging.tv/latest/ui_elements/Resolution.md
[`settings_adapter`]: https://charting-library-docs.xstaging.tv/latest/api/interfaces/Charting_Library.ChartingLibraryWidgetOptions#settings_adapter
[`setValue`]: https://charting-library-docs.xstaging.tv/latest/api/interfaces/Charting_Library.ISettingsAdapter#setvalue
[Trading Platform]: https://charting-library-docs.xstaging.tv/latest/trading_terminal.md
[`use_localstorage_for_settings`]: https://charting-library-docs.xstaging.tv/latest/customization/Featuresets.md#use_localstorage_for_settings
[Watchlist]: https://charting-library-docs.xstaging.tv/latest/trading_terminal/Watch-List.md
[Widget Constructor]: https://charting-library-docs.xstaging.tv/latest/configuration/Widget-Constructor.md

---

## Sitemap

- [All documentation pages](https://charting-library-docs.xstaging.tv/llms.txt)
- [Full page map with headings](https://charting-library-docs.xstaging.tv/docs_map.md)
