Skip to content

RoundingMode

Summary

The rounding mode for normalizing trade volume.

Signature

1
public enum RoundingMode

Namespace

cAlgo.API

Fields

Name Description
ToNearest Round value to the nearest tradable volume.
Down Round value down to tradable volume.
Up Round value up to tradable volume.

Examples

1
 volume = Symbol.NormalizeVolume(volume, RoundingMode.Down);
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
 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
     }
 }

Last update: June 26, 2022

Comments