Lots vs Units

Created at 10 Apr 2025, 12:17
AG

agent.xzxz

Joined 04.04.2020

Lots vs Units
10 Apr 2025, 12:17


Is lot and unit the same?

I tried this

double volumeInLots = 1;
Print(Symbol.QuantityToVolumeInUnits(volumeInLots))

and it shows 1 as well.

If they are the same, why is

Symbol.VolumeInUnitsMin

shows 1 when in fact I can open .5 lots

 

also, when I close partial volume using this

double volume = 0.5;
ModifyVolume(volume)

it says Bad Volume

 


@agent.xzxz
Replies

firemyst
12 Apr 2025, 02:48

Is lot and unit the same?

Not always. Depends on what you're trading.

For forex pairs, 1 lot = 100,000 units.


@firemyst

agent.xzxz
13 Apr 2025, 12:56

RE: Lots vs Units

firemyst said: 

Is lot and unit the same?

Not always. Depends on what you're trading.

For forex pairs, 1 lot = 100,000 units.

Got it!

Now my problem is I bought 1 lot of US100 then I close partial volume using this code

double volume = 0.5;
ModifyVolume(volume)

it says Bad Volume.

But when I close .5 lot using a normal close, I mean not using a bot, it accepted it.


@agent.xzxz

firemyst
13 Apr 2025, 13:02

RE: RE: Lots vs Units

 

Now my problem is I bought 1 lot of US100 then I close partial volume using this code

double volume = 0.5;ModifyVolume(volume)

it says Bad Volume.

But when I close .5 lot using a normal close, I mean not using a bot, it accepted it.

 

Post your code. For all I know, your code could have done something else, or reduced the size already before, or you could be using the wrong position or something else.


@firemyst

agent.xzxz
14 Apr 2025, 15:22

RE: RE: RE: Lots vs Units

firemyst said: 

 

Now my problem is I bought 1 lot of US100 then I close partial volume using this code

double volume = 0.5;ModifyVolume(volume)

it says Bad Volume.

But when I close .5 lot using a normal close, I mean not using a bot, it accepted it.

 

Post your code. For all I know, your code could have done something else, or reduced the size already before, or you could be using the wrong position or something else.

The code is below.
To replicate, you have to buy 1 lot of US100 (Nasdaq).

 

using System;
using System.Linq;
using cAlgo.API;

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None, AddIndicators = true)]
    public class TestModifyOrder : Robot
    {

        protected override void OnStart()
        {
            var position = Positions.FirstOrDefault();

            if (position != null)
            {
                try
                {
                    double volume = 0.5;
                    TradeResult tradeResult = position.ModifyVolume(volume);

                    if (tradeResult.IsSuccessful)
                    {
                        Print("Success!");
                    }
                    else
                    {
                        Print($"Error: {tradeResult.Error}");
                    }
                }
                catch (Exception ex)
                {
                    Print(ex.Message);
                }
            }
        }

        protected override void OnTick()
        {
            // Handle price updates here
        }

        protected override void OnStop()
        {
            // Handle cBot stop here
        }
    }
}

@agent.xzxz

firemyst
15 Apr 2025, 01:58

RE: RE: RE: RE: Lots vs Units

agent.xzxz said: 

firemyst said: 

 

Now my problem is I bought 1 lot of US100 then I close partial volume using this code

double volume = 0.5;ModifyVolume(volume)

it says Bad Volume.

But when I close .5 lot using a normal close, I mean not using a bot, it accepted it.

 

Post your code. For all I know, your code could have done something else, or reduced the size already before, or you could be using the wrong position or something else.

The code is below.
To replicate, you have to buy 1 lot of US100 (Nasdaq).

 

using System;using System.Linq;using cAlgo.API;namespace cAlgo.Robots{    [Robot(AccessRights = AccessRights.None, AddIndicators = true)]    public class TestModifyOrder : Robot    {        protected override void OnStart()        {            var position = Positions.FirstOrDefault();            if (position != null)            {                try                {                    double volume = 0.5;                    TradeResult tradeResult = position.ModifyVolume(volume);                    if (tradeResult.IsSuccessful)                    {                        Print("Success!");                    }                    else                    {                        Print($"Error: {tradeResult.Error}");                    }                }                catch (Exception ex)                {                    Print(ex.Message);                }            }        }        protected override void OnTick()        {            // Handle price updates here        }        protected override void OnStop()        {            // Handle cBot stop here        }    }}

Works perfectly for me.

 

I bought 1 lots of NAS, then started the bot:

 

Your statement “var position = Positions.FirstOrDefault();” might not work as you want if you have other positions open at the time because “.first()” may or may not return NAS as the first position in the open positions you have.


@firemyst

agent.xzxz
15 Apr 2025, 11:37

RE: RE: RE: RE: RE: Lots vs Units

firemyst said: 

agent.xzxz said: 

firemyst said: 

 

Now my problem is I bought 1 lot of US100 then I close partial volume using this code

double volume = 0.5;ModifyVolume(volume)

it says Bad Volume.

But when I close .5 lot using a normal close, I mean not using a bot, it accepted it.

 

Post your code. For all I know, your code could have done something else, or reduced the size already before, or you could be using the wrong position or something else.

The code is below.
To replicate, you have to buy 1 lot of US100 (Nasdaq).

 

using System;using System.Linq;using cAlgo.API;namespace cAlgo.Robots{    [Robot(AccessRights = AccessRights.None, AddIndicators = true)]    public class TestModifyOrder : Robot    {        protected override void OnStart()        {            var position = Positions.FirstOrDefault();            if (position != null)            {                try                {                    double volume = 0.5;                    TradeResult tradeResult = position.ModifyVolume(volume);                    if (tradeResult.IsSuccessful)                    {                        Print("Success!");                    }                    else                    {                        Print($"Error: {tradeResult.Error}");                    }                }                catch (Exception ex)                {                    Print(ex.Message);                }            }        }        protected override void OnTick()        {            // Handle price updates here        }        protected override void OnStop()        {            // Handle cBot stop here        }    }}

Works perfectly for me.

 

I bought 1 lots of NAS, then started the bot:

 

Your statement “var position = Positions.FirstOrDefault();” might not work as you want if you have other positions open at the time because “.first()” may or may not return NAS as the first position in the open positions you have.

I think its a broker related problem then. Im using ICMarkets


@agent.xzxz