RoundingMode


Summary

The rounding mode for normalizing trade volume.

Syntax

public sealed enum RoundingMode

Members

NameTypeSummary
Down FieldRound value down to tradable volume.
ToNearest FieldRound value to the nearest tradable volume.
Up FieldRound value up to tradable volume.

Example 1

volume = Symbol.NormalizeVolume(volume, RoundingMode.Down);

Example 2

using cAlgo.API;
namespace cAlgo
{
    // This sample shows how to normalize volume based on different rounding modes
    [Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NormalizingVolumeSample : Indicator
    {
        [Parameter("Volume Unit", DefaultValue = VolumeUnit.Units)]
        public VolumeUnit VolumeUnit { get; set; }
        [Parameter("Volume Amount", DefaultValue = 0.01)]
        public double VolumeAmount { get; set; }
        [Parameter("Rounding Mode", DefaultValue = RoundingMode.ToNearest)]
        public RoundingMode RoundingMode { get; set; }
        protected override void Initialize()
        {
            double volumeInUnits = VolumeUnit == VolumeUnit.Units ? VolumeAmount : Symbol.QuantityToVolumeInUnits(VolumeAmount);
            double normalizedVolume = Symbol.NormalizeVolumeInUnits(volumeInUnits, RoundingMode);
            Print(normalizedVolume);
        }
        public override void Calculate(int index)
        {
        }
    }
    public enum VolumeUnit
    {
        Units,
        Lots
    }
}
Reference