Skip to content

TickVolume

interface cAlgo.API.Indicators

DesktopCLICloud

The Tick Volume indicator shows number of ticks for each bar.

Definition

public interface TickVolume

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

Remarks

Tick Volume is the number of ticks per bar.

Examples

using cAlgo.API;
using cAlgo.API.Indicators;

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

        private TickVolume _tickVolume;

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

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

            _tickVolume = Indicators.TickVolume();
        }

        protected override void OnBar()
        {
            if (Bars.Last(1).Close > Bars.Last(2).Close)
            {
                ClosePositions(TradeType.Sell);

                if (_tickVolume.Result.Last(1) > _tickVolume.Result.Last(2))
                    ExecuteMarketOrder(TradeType.Buy, SymbolName, _volumeInUnits, Label, StopLossInPips, TakeProfitInPips);
            }
            else if (Bars.Last(1).Close < Bars.Last(2).Close)
            {
                ClosePositions(TradeType.Buy);

                if (_tickVolume.Result.Last(1) > _tickVolume.Result.Last(2))
                    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 Test():
    def on_start(self):
        self.volumeInUnits = api.Symbol.QuantityToVolumeInUnits(api.VolumeInLots)
        self.tickVolume = api.Indicators.TickVolume()

    def on_bar_closed(self):
        if api.Bars.Last(1).Close > api.Bars.Last(2).Close:
            self.close_positions(TradeType.Sell)

            if self.tickVolume.Result.Last(1) > self.tickVolume.Result.Last(2):
                api.ExecuteMarketOrder(TradeType.Buy, api.SymbolName, self.volumeInUnits, api.Label, api.StopLossInPips, api.TakeProfitInPips)
        elif api.Bars.Last(1).Close < api.Bars.Last(2).Close:
            self.close_positions(TradeType.Buy)

            if self.tickVolume.Result.Last(1) > self.tickVolume.Result.Last(2):
                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,
      "Group": "Trade"
    },
    {
      "Name": "StopLossInPips",
      "DisplayName": "Stop Loss (Pips)",
      "Type": "Double",
      "DefaultValue": 10,
      "Group": "Trade"
    },
    {
      "Name": "TakeProfitInPips",
      "DisplayName": "Take Profit (Pips)",
      "Type": "Double",
      "DefaultValue": 10,
      "Group": "Trade"
    },
    {
      "Name": "Label",
      "Type": "String",
      "DefaultValue": "Sample",
      "Group": "Trade"
    }
  ]
}

Properties

Name Description
ResultDesktopCLICloudIndicatorDataSeries The resulting time series of the calculation.

Inherited members

From StandardIndicator: AddToChart, Symbol, TimeFrame, Bars