---
id: "T:cAlgo.API.MonteCarloSettings"
kind: "record"
namespace: "cAlgo.API"
url: "https://help.ctrader.com/ctrader-algo/references/Plugin/Backtesting/MonteCarloSettings/"
---

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

# MonteCarloSettings (record)

Represents the optional Monte Carlo simulation that is attached to a backtest. A backtest produces a single equity curve, the one historical ordering of its trades. A Monte Carlo simulation re-runs that result many times, each time resampling or perturbing it, and reports the distribution of the outcomes instead of the single historical path.

Environments: Desktop supported · CLI not supported · Cloud not supported.

- CLI: Available to plugins only, and plugins cannot run in the CLI.
- Cloud: Available to plugins only, and plugins cannot run in the cloud.

## Definition

```csharp
public class MonteCarloSettings
```

Available since cAlgo.API 5.10.

## Examples

C#:

```csharp
using cAlgo.API;
using cAlgo.API.Internals;
using System;

namespace cAlgo.Plugins
{
    public partial class MonteCarloTest : Plugin
    {
        private BacktestingProcess _backtestingProcess;

        protected override void OnStart()
        {
            if (AlgoRegistry.Get(RobotName, AlgoKind.Robot) is not RobotType robotType)
            {
                Print($"Robot type {RobotName} not found");
                return;
            }

            var backtestingSettings = new BacktestingSettings
            {
                StartTimeUtc = StartTime,
                EndTimeUtc = EndTime,
                Balance = AccountBalance,
                DataMode = BacktestingDataMode.M1,
                SpreadPips = 1,
                MonteCarlo = new MonteCarloSettings(MonteCarloMethod.BlockBootstrap, MonteCarloOutputPath)
                {
                    Iterations = 5000,
                    Seed = 42,
                    StartingEquity = AccountBalance,
                    RuinFloor = 0,
                    BlockSize = 10
                }
            };

            _backtestingProcess = Backtesting.Start(robotType, Symbol.Name, TimeFrame, backtestingSettings);

            _backtestingProcess.Completed += args => Print($"Monte Carlo result: {_backtestingProcess.MonteCarloJsonReport}");
        }

        protected override void OnStop()
        {
            _backtestingProcess?.Terminate();
        }
    }
}
```

Python:

```python
import clr
clr.AddReference("cAlgo.API")

from cAlgo.API import *

class MonteCarloTest():
    def on_start(self):
        algoType = api.AlgoRegistry.Get(api.RobotName, AlgoKind.Robot)
        if algoType is None:
            print(f"Robot type {api.RobotName} not found")
            return

        robotType = RobotType(algoType)

        backtestingSettings = BacktestingSettings()
        backtestingSettings.StartTimeUtc = api.StartTime
        backtestingSettings.EndTimeUtc = api.EndTime
        backtestingSettings.Balance = api.AccountBalance
        backtestingSettings.DataMode = BacktestingDataMode.M1
        backtestingSettings.SpreadPips = 1

        monteCarlo = MonteCarloSettings(MonteCarloMethod.BlockBootstrap, api.MonteCarloOutputPath)
        monteCarlo.Iterations = 5000
        monteCarlo.Seed = 42
        monteCarlo.StartingEquity = api.AccountBalance
        monteCarlo.RuinFloor = 0
        monteCarlo.BlockSize = 10
        backtestingSettings.MonteCarlo = monteCarlo

        self.backtestingProcess = api.Backtesting.Start(robotType, api.Symbol.Name, api.TimeFrame, backtestingSettings)
        self.backtestingProcess.Completed += lambda args: print(f"Monte Carlo result: {self.backtestingProcess.MonteCarloJsonReport}")

    def on_stop(self):
        if hasattr(self, "backtestingProcess") and self.backtestingProcess is not None:
            self.backtestingProcess.Terminate()
```

config.json:

```json
{
  "AccessRights": "FullAccess",
  "Parameters": [
    {
      "Name": "RobotName",
      "Type": "String",
      "DefaultValue": "Sample Breakout"
    },
    {
      "Name": "Symbol",
      "Type": "Symbol",
      "DefaultValue": "EURUSD"
    },
    {
      "Name": "TimeFrame",
      "Type": "TimeFrame",
      "DefaultValue": "Daily"
    },
    {
      "Name": "StartTime",
      "Type": "DateTime",
      "DefaultValue": "2023-09-01T06:30:00"
    },
    {
      "Name": "EndTime",
      "Type": "DateTime",
      "DefaultValue": "2025-09-01T06:30:00"
    },
    {
      "Name": "AccountBalance",
      "Type": "Double",
      "DefaultValue": 10000
    },
    {
      "Name": "MonteCarloOutputPath",
      "Type": "String",
      "DefaultValue": "C:\\Temp\\montecarlo-result.json"
    }
  ]
}
```

## Constructors

- `public MonteCarloSettings(MonteCarloMethod method, string outputFilePath)` — Initializes a new instance of the MonteCarloSettings record. The method and the output file path are required, every other setting is optional. [details](https://help.ctrader.com/ctrader-algo/references/Plugin/Backtesting/MonteCarloSettings/Constructor/index.md)
- `public MonteCarloSettings(MonteCarloSettings original)` —  [details](https://help.ctrader.com/ctrader-algo/references/Plugin/Backtesting/MonteCarloSettings/Constructor/index.md)

## Properties

- `public int BlockSize {get; set;}` — Gets the number of consecutive trades that are kept together when resampling. It is used only by the BlockBootstrap and StationaryBootstrap methods and is ignored by the others. It must be greater than or equal to 1 and the default value is 5. [details](https://help.ctrader.com/ctrader-algo/references/Plugin/Backtesting/MonteCarloSettings/BlockSize/index.md)
- `public int Iterations {get; set;}` — Gets the number of simulated iterations. When it is 0, the default, the method default is used, which is 1000 for the resampling methods and 100 for SyntheticPricePath. Any other value outside the range of the method, which is 100 to 100000 for the resampling methods and 100 to 1000 for SyntheticPricePath, is reported as an invalid settings error instead of being clamped. [details](https://help.ctrader.com/ctrader-algo/references/Plugin/Backtesting/MonteCarloSettings/Iterations/index.md)
- `public MonteCarloMethod Method {get;}` — Gets the Monte Carlo simulation method. [details](https://help.ctrader.com/ctrader-algo/references/Plugin/Backtesting/MonteCarloSettings/Method/index.md)
- `public string OutputFilePath {get;}` — Gets the destination file path for the Monte Carlo result JSON. The file uses the same snapshot format the desktop Monte Carlo tab saves, so it can be loaded back by the desktop application. [details](https://help.ctrader.com/ctrader-algo/references/Plugin/Backtesting/MonteCarloSettings/OutputFilePath/index.md)
- `public double RuinFloor {get; set;}` — Gets the equity level that is treated as account ruin. The risk of ruin is the share of the simulations whose equity drops to or below this level. It must be greater than or equal to 0 and the default value is 0. [details](https://help.ctrader.com/ctrader-algo/references/Plugin/Backtesting/MonteCarloSettings/RuinFloor/index.md)
- `public int Seed {get; set;}` — Gets the random seed that makes the simulation reproducible. The same seed with the same inputs produces the same result, even across application restarts. The default value is 0. [details](https://help.ctrader.com/ctrader-algo/references/Plugin/Backtesting/MonteCarloSettings/Seed/index.md)
- `public double StartingEquity {get; set;}` — Gets the starting equity used as the additive base for the simulated equity curves. When it is 0, the default, the initial balance of the backtest is used. [details](https://help.ctrader.com/ctrader-algo/references/Plugin/Backtesting/MonteCarloSettings/StartingEquity/index.md)

