ClosePositions Error BadVolume

Created at 14 Jul 2022, 07:59
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
M4

m4trader4

Joined 19.09.2021

ClosePositions Error BadVolume
14 Jul 2022, 07:59


Dear Ahmad

I have positions which get closed OnClick, sometimes get error "BadVolume" when closing positions. Does not happen regularly but when its critical postions dont get closed.

Referring to attached log,  Position Quantity is 12.82 and Position Volume is 128.2, but when closing its volume is 128.19

 

 

 

 BeginInvokeOnMainThread(() =>
                    {
                       
                            var positionsCBS = Positions.Where(position => position.SymbolName.Equals(GlobalSymbolName, StringComparison.Ordinal)).ToArray();
                            //  Print(arg2 + " " + "Yes message processed");
                            foreach (var psnCBS in positionsCBS)
                            {
                                if (string.IsNullOrWhiteSpace(psnCBS.Comment) || psnCBS.Comment.Contains("EP:", StringComparison.OrdinalIgnoreCase) || psnCBS.Comment.Contains("Market", StringComparison.OrdinalIgnoreCase)
                                || psnCBS.Comment.Contains("MO", StringComparison.OrdinalIgnoreCase) )
                                {
                                Print("PositionId=" + psnCBS.Id + "=PositionQuantity=" + psnCBS.Quantity.ToString() + "=PositionVolume="+ psnCBS.VolumeInUnits.ToString() );
                                //ClosePositionAsync(psnCBS, null);
                                ClosePositionAsync(psnCBS);
                            }

                            }

                    });

 


@m4trader4
Replies

PanagiotisCharalampous
14 Jul 2022, 10:42

Hi m4trader4,

Any chance you can share the complete cBot code?

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

m4trader4
14 Jul 2022, 11:14

RE:

Dear Panagiotis

Positions get closed but once in a while or when there is high volatility get error "Bad Volume". In the log volume is not matching.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using cAlgo.API;
using cAlgo.API.Collections;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;

namespace cAlgo.Robots
{
    [Robot(AccessRights = AccessRights.None)]
    public class Button : Robot
    {
       cAlgo.API.Button BCLP;
	   private string GlobalSymbolName;

        void buttonCreate(string BName, string BText, string X, String Y, string clr, cAlgo.API.Button TButton)
        {


            TButton.Height = 15;
            TButton.Width = 24;
            TButton.FontSize = 9;
            TButton.HorizontalContentAlignment = 0;
            TButton.Padding = "0 0 0 0";
            //CornerRadius = 2,
            TButton.Text = BText;
            TButton.Margin = X + " " + Y;
            TButton.BackgroundColor = Color.FromHex(clr);
            TButton.HorizontalAlignment = cAlgo.API.HorizontalAlignment.Left;
            TButton.VerticalAlignment = VerticalAlignment.Bottom;
            //Chart.AddControl(TButton);

        }

        void CloseOrder()
        {

            BeginInvokeOnMainThread(() =>
            {
               
                    
					var positionsCBS = Positions.Where(position => position.SymbolName.Equals(GlobalSymbolName, StringComparison.Ordinal)).ToArray();
                    
                    foreach (var psnCBS in positionsCBS)
                    {
					
					 if (string.IsNullOrWhiteSpace(psnCBS.Comment) || psnCBS.Comment.Contains("EP:", StringComparison.OrdinalIgnoreCase) || psnCBS.Comment.Contains("Market", StringComparison.OrdinalIgnoreCase)
                                || psnCBS.Comment.Contains("MO", StringComparison.OrdinalIgnoreCase) )
                                {
                                Print("PositionId=" + psnCBS.Id + "=PositionQuantity=" + psnCBS.Quantity.ToString() + "=PositionVolume="+ psnCBS.VolumeInUnits.ToString() );
                                //ClosePositionAsync(psnCBS, null);
                                ClosePositionAsync(psnCBS);
								}
                    }

            });
        }


        protected override void OnStart()
        {
			GlobalSymbolName = Symbol.Name;
            BCLP = new cAlgo.API.Button();
            buttonCreate("CLP", "CLP", "1", "85", "#009345", BCLP);
            Chart.AddControl(BCLP);
            BCLP.Click += args => CloseOrder();
         
        }

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

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

 


@m4trader4

PanagiotisCharalampous
14 Jul 2022, 11:19

Hi m4trader4,

Thanks, we will investigate this.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

m4trader4
14 Jul 2022, 11:19

RE: RE:

In the setting my "default Assets trading units" is Lots


@m4trader4

PanagiotisCharalampous
14 Jul 2022, 11:22

Hi again,

The next time this happens, please send us some troubleshooting information. Post a link to this discussion inside the text box of the troubleshooting form.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

m4trader4
14 Jul 2022, 11:51 ( Updated at: 21 Dec 2023, 09:22 )

RE:

Automate Log
14/07/2022 10:46:46.477 | → Closing position PID6830660 (Volume: 78.09) FAILED with error "BadVolume"
14/07/2022 10:46:46.320 | Closing position PID6830660 (Volume: 78.09)
14/07/2022 10:46:46.305    Info    PositionId=6830660=PositionQuantity=7.81=PositionVolume=78.1    

Journal Log
14/07/2022 10:46:46.477 | → Failed to close position PID6830660 with error "Order closeVolume 78.09 is not multiple of volumeStep=78.10."
14/07/2022 10:46:46.320 | Request to close position PID6830660 is sent to server

 


@m4trader4

m4trader4
14 Jul 2022, 12:11

RE:

Submitted with link 

 


@m4trader4

m4trader4
14 Jul 2022, 12:16

RE: RE:

To reproduce the issue. Place a trade of US30.cash(ftmo) with 7.81 Lots and close using cBot


@m4trader4

m4trader4
18 Jul 2022, 08:56

RE: RE: RE:

Dear Support

Update Please

Regards

Ahmed

 


@m4trader4

PanagiotisCharalampous
18 Jul 2022, 09:09

Hi Ahmed,

The team has identified the problem and it will be fixed in an upcoming update.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

m4trader4
18 Jul 2022, 09:11

RE:

Dear Panagiotis

What is the ETA

Regards

Ahmed

 


@m4trader4

m4trader4
20 Jul 2022, 07:38

RE: RE:

Dear Panagiotis

What is the ETA could not close trade

Regards

Ahmed


@m4trader4

PanagiotisCharalampous
21 Jul 2022, 10:16

Hi Ahmed,

It will be fixed in the next update of your platform but there is no specific ETA.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

m4trader4
22 Jul 2022, 09:32

RE:

Dear Panagiotis

Got an update on 21/07/2022 (4.2.15.7209) does this consist the fix?

Where can i get the release notes for the updates not major releases

Suggestion: If customers can get access to filtered defect/issue management.

Regards

Ahmed

 


@m4trader4

PanagiotisCharalampous
25 Jul 2022, 12:19

Hi Ahmed,

Was the problem solved? We do not provide release notes for minor updates.

Best Regards,

Panagiotis 

Join us on Telegram and Facebook


@PanagiotisCharalampous

m4trader4
29 Jul 2022, 10:31

RE:

Dear Panagiotis

Have not faced any issue as of last update. Will do a manual check this weekend

Regards

Ahmed


@m4trader4