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

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

# TradeVolumeIndex (interface)

Trade Volume Index measures the amount of money flowing in and out of an asset.

Environments: Desktop supported · CLI supported · Cloud supported.

## Definition

```csharp
public interface TradeVolumeIndex
```

## Remarks

The underlying assumption of this indicator is that there is buying pressure when the price trades near the asking price and selling pressure when it trades near the bid.

## Examples

C#:

```csharp
private TradeVolumeIndex _tradeVolume;

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

Python:

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

from cAlgo.API import *

class Test():
    def initialize(self):
        self.tradeVolume = api.Indicators.TradeVolumeIndex(api.Source)

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

config.json:

```json
{
  "Parameters": [
    {
      "Name": "Source",
      "Type": "DataSeries"
    }
  ],
  "LineOutputs": [
    {
      "Name": "Result",
      "DisplayName": "Main"
    }
  ]
}
```

C#:

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

namespace cAlgo.Robots
{
    // This sample cBot shows how to use the Trade Volume Index indicator
    public partial class TradeVolumeIndexSample : Robot
    {
        private double _volumeInUnits;

        private TradeVolumeIndex _tradeVolumeIndex;

        private SimpleMovingAverage _simpleMovingAverage;

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

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

            _tradeVolumeIndex = Indicators.TradeVolumeIndex(Bars.ClosePrices);

            _simpleMovingAverage = Indicators.SimpleMovingAverage(_tradeVolumeIndex.Result, 14);
        }

        protected override void OnBar()
        {
            if (_tradeVolumeIndex.Result.HasCrossedAbove(_simpleMovingAverage.Result, 0))
            {
                ClosePositions(TradeType.Sell);

                ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
            }
            else if (_tradeVolumeIndex.Result.HasCrossedBelow(_simpleMovingAverage.Result, 0))
            {
                ClosePositions(TradeType.Buy);

                ExecuteMarketOrder(TradeType.Sell, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
            }
        }

        private void ClosePositions(TradeType tradeType)
        {
            foreach (var position in BotPositions)
            {
                if (position.TradeType != tradeType) continue;

                ClosePosition(position);
            }
        }
    }
}
```

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 TradeVolumeIndexSample():
    def on_start(self):
        self.volumeInUnits = api.Symbol.QuantityToVolumeInUnits(api.VolumeInLots)
        self.tradeVolumeIndex = api.Indicators.TradeVolumeIndex(api.Bars.ClosePrices)
        self.simpleMovingAverage = api.Indicators.SimpleMovingAverage(self.tradeVolumeIndex.Result, 14)

    def on_bar_closed(self):
        if Functions.HasCrossedAbove(self.tradeVolumeIndex.Result, self.simpleMovingAverage.Result, 0):
            self.close_positions(TradeType.Sell)
            api.ExecuteMarketOrder(TradeType.Buy, api.SymbolName, self.volumeInUnits, api.Label, api.StopLossInPips, api.TakeProfitInPips)
        elif Functions.HasCrossedBelow(self.tradeVolumeIndex.Result, self.simpleMovingAverage.Result, 0):
            self.close_positions(TradeType.Buy)
            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)

    def close_positions(self, tradeType):
        for position in self.get_bot_positions():
            if position.TradeType != tradeType:
                continue
            api.ClosePosition(position)
```

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; set;}` — Gets the time series of Trade Volume Index indicator. [details](https://help.ctrader.com/ctrader-algo/references/Indicators/TradeVolumeIndex/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)

