---
id: "T:cAlgo.API.Indicators.AccumulativeSwingIndex"
kind: "interface"
namespace: "cAlgo.API.Indicators"
url: "https://help.ctrader.com/ctrader-algo/references/Indicators/AccumulativeSwingIndex/"
---

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

# AccumulativeSwingIndex (interface)

A variation on Wilder's swing index which plots an accumulation of the swing index value of each candlestick or bar.

Environments: Desktop supported · CLI supported · Cloud supported.

## Definition

```csharp
public interface AccumulativeSwingIndex
```

## Remarks

The accumulative swing index is used to gain a longer-term picture than the Wilder's swing index. When the accumulative swing index is positive, the long-term trend is up. When the accumulative swing index is negative, it signals a downwards long-term trend.

## Examples

C#:

```csharp
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo
{
    public partial class AccumSwingIndexReferenceExample:Indicator
    {
        private AccumulativeSwingIndex _accumulativeSwingIndex;

        protected override void Initialize()
        {
            _accumulativeSwingIndex = Indicators.AccumulativeSwingIndex(LimitMove);
        }
        public override void Calculate(int index)
        {
            // Display Result of Indicator
            Result[index] = _accumulativeSwingIndex.Result[index];
        }
    }
}
```

Python:

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

from cAlgo.API import *

class Test():
    def initialize(self):
        self.accumulativeSwingIndex = api.Indicators.AccumulativeSwingIndex(api.LimitMove)

    def calculate(self, index):
        api.Result[index] = self.accumulativeSwingIndex.Result[index]
```

config.json:

```json
{
  "Parameters": [
    {
      "Name": "LimitMove",
      "DisplayName": "Limit Move",
      "Type": "Integer",
      "DefaultValue": 12
    }
  ],
  "LineOutputs": [
    {
      "Name": "Result",
      "DisplayName": "Main"
    }
  ]
}
```

C#:

```csharp
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Robots
{
    // This sample cBot shows how to use an Accumulative Swing Index indicator
    public partial class AccumulativeSwingIndexSample : Robot
    {
        private double _volumeInUnits;

        private AccumulativeSwingIndex _accumulativeSwingIndex;

        public Position[] BotPositions
        {
            get
            {
                return Positions.FindAll(Label);
            }
        }

        protected override void OnStart()
        {
            _volumeInUnits = Symbol.QuantityToVolumeInUnits(VolumeInLots);

            _accumulativeSwingIndex = Indicators.AccumulativeSwingIndex(12);
        }

        protected override void OnBar()
        {
            foreach (var position in BotPositions)
            {
                if ((position.TradeType == TradeType.Buy && _accumulativeSwingIndex.Result.Last(1) < _accumulativeSwingIndex.Result.Last(2))
                    || (position.TradeType == TradeType.Sell && _accumulativeSwingIndex.Result.Last(1) > _accumulativeSwingIndex.Result.Last(2)))
                {
                    ClosePosition(position);
                }
            }

            if (_accumulativeSwingIndex.Result.Last(1) > 0 && _accumulativeSwingIndex.Result.Last(2) <= 0)
            {
                ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
            }
            else if (_accumulativeSwingIndex.Result.Last(1) < 0 && _accumulativeSwingIndex.Result.Last(2) >= 0)
            {
                ExecuteMarketOrder(TradeType.Sell, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
            }
        }
    }
}
```

Python:

```python
import clr

clr.AddReference("cAlgo.API")

# Import cAlgo API types
from cAlgo.API import *

# Import trading wrapper functions
from robot_wrapper import *

class AccumulativeSwingIndexSample():
    def on_start(self):
        self.volumeInUnits = api.Symbol.QuantityToVolumeInUnits(api.VolumeInLots)
        self.accumulativeSwingIndex = api.Indicators.AccumulativeSwingIndex(12)

    def on_bar_closed(self):
        for position in self.get_bot_positions():
            if (position.TradeType == TradeType.Buy and self.accumulativeSwingIndex.Result.Last(0) < self.accumulativeSwingIndex.Result.Last(1)) or (position.TradeType == TradeType.Sell and self.accumulativeSwingIndex.Result.Last(0) > self.accumulativeSwingIndex.Result.Last(1)):
                api.ClosePosition(position)

        if self.accumulativeSwingIndex.Result.Last(0) > 0 and self.accumulativeSwingIndex.Result.Last(1) <= 0:
            api.ExecuteMarketOrder(TradeType.Buy, api.SymbolName, self.volumeInUnits, api.Label, api.StopLossInPips, api.TakeProfitInPips)
        elif (self.accumulativeSwingIndex.Result.Last(0) < 0 and self.accumulativeSwingIndex.Result.Last(1) >= 0):
            api.ExecuteMarketOrder(TradeType.Sell, api.SymbolName, self.volumeInUnits, api.Label, api.StopLossInPips, api.TakeProfitInPips)

    def get_bot_positions(self):
        return api.Positions.FindAll(api.Label)
```

config.json:

```json
{
  "AccessRights": "None",
  "TimeZone": "UTC",
  "Parameters": [
    {
      "Name": "VolumeInLots",
      "DisplayName": "Volume (Lots)",
      "Type": "Double",
      "DefaultValue": 0.01
    },
    {
      "Name": "StopLossInPips",
      "DisplayName": "Stop Loss (Pips)",
      "Type": "Double",
      "DefaultValue": 10
    },
    {
      "Name": "TakeProfitInPips",
      "DisplayName": "Take Profit (Pips)",
      "Type": "Double",
      "DefaultValue": 10
    },
    {
      "Name": "Label",
      "Type": "String",
      "DefaultValue": "Sample"
    }
  ]
}
```

## Properties

- `IndicatorDataSeries Result {get;}` — The time series of AccumulativeSwingIndex. [details](https://help.ctrader.com/ctrader-algo/references/Indicators/AccumulativeSwingIndex/Result/index.md)

## Inherited members

- `ChartIndicator AddToChart()` (from StandardIndicator) [details](https://help.ctrader.com/ctrader-algo/references/General/StandardIndicator/AddToChart/index.md)
- `Symbol Symbol {get;}` (from StandardIndicator) [details](https://help.ctrader.com/ctrader-algo/references/General/StandardIndicator/Symbol/index.md)
- `TimeFrame TimeFrame {get;}` (from StandardIndicator) [details](https://help.ctrader.com/ctrader-algo/references/General/StandardIndicator/TimeFrame/index.md)
- `Bars Bars {get;}` (from StandardIndicator) [details](https://help.ctrader.com/ctrader-algo/references/General/StandardIndicator/Bars/index.md)

