---
id: "M:cAlgo.API.LocalStorage.SetString(System.String,System.String)"
kind: "method"
type: "T:cAlgo.API.LocalStorage"
url: "https://help.ctrader.com/ctrader-algo/references/Localstorage/LocalStorage/SetString/"
---

> Documentation index for agents: https://help.ctrader.com/ctrader-algo/llms.txt · machine index: https://help.ctrader.com/ctrader-algo/api.json

# LocalStorage.SetString

Member of [LocalStorage](https://help.ctrader.com/ctrader-algo/references/Localstorage/LocalStorage/index.md).

## SetString(string key, string value)

Saves a string value to local storage. The storage scope is LocalStorageScope.Instance.

Environments: Desktop supported · CLI supported · Cloud works differently.

- Cloud: Values are kept in memory for the current run only; nothing is saved to or read from disk, and auto-flush is off.

C#:

```csharp
void SetString(string key, string value)
```

Python:

```python
api.LocalStorage.SetString(key: str, value: str) -> None
```

### Parameters

- `key` (`string`, Python `str`): The key of the element to add, max length for keys is 50 characters, and only alphanumeric and space characters are allowed, you can only use space in the middle of key not at the start or end
- `value` (`string`, Python `str`): The value of the element to add

### Examples

C#:

```csharp
LocalStorage.SetString("Last Signal", "Buy EURUSD");
Print("Stored signal: {0}", LocalStorage.GetString("Last Signal"));
```

Python:

```python
api.LocalStorage.SetString("Last Signal", "Buy EURUSD")
api.Print(f"Stored signal: {api.LocalStorage.GetString('Last Signal')}")
```

## SetString(string key, string value, LocalStorageScope localStorageScope)

Saves a string value to local storage.

Environments: Desktop supported · CLI supported · Cloud works differently.

- Cloud: Values are kept in memory for the current run only; nothing is saved to or read from disk, and auto-flush is off.

C#:

```csharp
void SetString(string key, string value, LocalStorageScope localStorageScope)
```

Python:

```python
api.LocalStorage.SetString(key: str, value: str, localStorageScope: LocalStorageScope) -> None
```

### Parameters

- `key` (`string`, Python `str`): The key of the element to add, max length for keys is 50 characters, and only alphanumeric and space characters are allowed, you can only use space in the middle of key not at the start or end
- `value` (`string`, Python `str`): The value of the element to add
- `localStorageScope` (`LocalStorageScope`, Python `LocalStorageScope`): The storage scope of the element

### Examples

C#:

```csharp
LocalStorage.SetString("Last Signal", "Buy EURUSD", LocalStorageScope.Type);
Print("Shared with all instances: {0}", LocalStorage.GetString("Last Signal", LocalStorageScope.Type));
```

Python:

```python
api.LocalStorage.SetString("Last Signal", "Buy EURUSD", LocalStorageScope.Type)
api.Print(f"Shared with all instances: {api.LocalStorage.GetString('Last Signal', LocalStorageScope.Type)}")
```

