---
id: "M:cAlgo.API.TimeFrame.TryParse(System.String,cAlgo.API.TimeFrame@)"
kind: "method"
type: "T:cAlgo.API.TimeFrame"
url: "https://help.ctrader.com/ctrader-algo/references/Period/TimeFrame/TryParse/"
---

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

# TimeFrame.TryParse

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

## TryParse(string value, TimeFrame& timeFrame)

It parses a string and if it matched to a timeframe name it sets it to the passed timeFrame parameter

Environments: Desktop supported · CLI supported · Cloud supported.

C#:

```csharp
public static bool TryParse(string value, TimeFrame& timeFrame)
```

Python:

```python
TimeFrame.TryParse(value: str, timeFrame: TimeFrame) -> bool
```

### Parameters

- `value` (`string`, Python `str`): The timeframe name
- `timeFrame` (`TimeFrame&`, Python `TimeFrame`): The storage variable for the matching timeframe

### Returns

`bool` — True if a matching timeframe found otherwise False

### Examples

C#:

```csharp
if (TimeFrame.TryParse("h1", out var timeFrame))
    Print("Parsed time frame: {0}", timeFrame.Name);
else
    Print("Unknown time frame name");
```

Python:

```python
success, timeFrame = TimeFrame.TryParse("h1", None)
if success:
    api.Print(f"Parsed time frame: {timeFrame.Name}")
else:
    api.Print("Unknown time frame name")
```

