Skip to content

TradeVolumeIndex

interface cAlgo.API.Indicators

DesktopCLICloud

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

Definition

public interface TradeVolumeIndex

Namespace: cAlgo.API.Indicators · Group: Indicators · Implements: StandardIndicator

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

Example 1

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];
}
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]
{
  "Parameters": [
    {
      "Name": "Source",
      "Type": "DataSeries"
    }
  ],
  "LineOutputs": [
    {
      "Name": "Result",
      "DisplayName": "Main"
    }
  ]
}

Example 2

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);
            }
        }
    }
}
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)
{
  "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

Name Description
ResultDesktopCLICloudIndicatorDataSeries Gets the time series of Trade Volume Index indicator.

Inherited members

From StandardIndicator: AddToChart, Symbol, TimeFrame, Bars