Failed to close position PID3688901 with error "POSITION_LOCKED"

Created at 10 Dec 2013, 16:31
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!
ST

stoko

Joined 05.07.2013

Failed to close position PID3688901 with error "POSITION_LOCKED"
10 Dec 2013, 16:31


Why do I get this error? My bot cannt continue working now..

How do I close the position?! I tried manually and I get the same error:

10/12/2013 14:30:13.587 | → Failed to close position PID3688901 with error "POSITION_LOCKED"


@stoko
Replies

Spotware
10 Dec 2013, 17:40

We will investigate this.


@Spotware

stoko
10 Dec 2013, 22:10

RE:

Spotware said:

We will investigate this.

thanks


@stoko

stoko
12 Dec 2013, 02:13

any news? is it bad?


@stoko

Spotware
12 Dec 2013, 17:12

This issue has been fixed. 


@Spotware

stoko
12 Dec 2013, 17:33

its not I am getting now

 12/12/2013 15:30:50.604→ Failed to close position PID3688901 with error "TRADING_BAD_VOLUME"

 

please please let me know how to get rid off it as my bot cannt continue!! what if it was for real money!?!?

why does it happen?!?


@stoko

Spotware
12 Dec 2013, 17:55

We will investigate again. We apologize for this. If you could  send us troubleshooting information by pressing Ctrl+Shift+Alt+T it will be helpful.


@Spotware

stoko
12 Dec 2013, 18:05

I did it 2 times and it asked if I want to submit troubleshooting to the support and that's all.. hopefully you got something

 

thank you


@stoko

stoko
13 Dec 2013, 21:08

I guess no news :(

 

Can I trust cAlgo?


@stoko

Spotware
16 Dec 2013, 14:08

This problem was only affecting demo accounts and it has been fixed. Thank you for your patience.


@Spotware

dt0301
01 Feb 2018, 10:49

Error: "POSITION_LOCKED"

This problem still exists, I get this error:
Failed to close position PID13491126 with error "POSITION_LOCKED"


@dt0301

PanagiotisCharalampous
01 Feb 2018, 10:56

Dear Trader,

Thanks for posting in our forum. Can you please send all the necessary information to feedback@spotware.com (PID, account number, cTID, broker) so that they can investigate this?

Best Regards,

Panagiotis


@PanagiotisCharalampous

.ics
22 Feb 2018, 22:20

I encounter this message also on some moments when trying to close a position on a demo account. The behavior is that the client is sending the closing request. I think the server receives the request but needs to process it. When a new tick arrives and and a new closing request is sent while the server is still busy closing the previous closing request, it replies the POSITION_LOCKED. That's the impression that i have during this situation.


@.ics

acrigney
03 Jul 2020, 17:04

RE:

.ics said: I get this error but retrying the close seems to work.

I encounter this message also on some moments when trying to close a position on a demo account. The behavior is that the client is sending the closing request. I think the server receives the request but needs to process it. When a new tick arrives and and a new closing request is sent while the server is still busy closing the previous closing request, it replies the POSITION_LOCKED. That's the impression that i have during this situation.

 


@acrigney

vtx101
09 Mar 2021, 14:09

RE:

Spotware said:

This issue has been fixed. 

now i'm getting this problem with my robot!! i'm guessing ya'll or the brokers want to keep trading difficult. The robot is designed to close the trade immediately. Ever since using my robot am getting this error!

 

2021.03.08 20:01:24.836 | → Failed to close position PID71524136 with error "POSITION_LOCKED"

 

it's making my copy trading account look bad. i suffered my first major loss today!!!


@vtx101

PanagiotisCharalampous
09 Mar 2021, 15:35

Hi arunsub321,

POSITION_LOCKED means that the server is trying to close the position i.e. sent the order to LP and waiting a response. Make sure you are not trying to modify/close a position after you have already sent an order to close it.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

vtx101
09 Mar 2021, 18:06

RE:

PanagiotisCharalampous said:

Hi arunsub321,

POSITION_LOCKED means that the server is trying to close the position i.e. sent the order to LP and waiting a response. Make sure you are not trying to modify/close a position after you have already sent an order to close it.

Best Regards,

Panagiotis 

Join us on Telegram

 

Ridiculous, this only happens when my robot is activated. it's a simple code to immediately close the position once a certain level is reached. If i was to manually close the trade myself i wont get the error.


@vtx101

vtx101
10 Mar 2021, 16:05 ( Updated at: 10 Mar 2021, 16:10 )

RE: RE:

arunsub321 said:

PanagiotisCharalampous said:

Hi arunsub321,

POSITION_LOCKED means that the server is trying to close the position i.e. sent the order to LP and waiting a response. Make sure you are not trying to modify/close a position after you have already sent an order to close it.

Best Regards,

Panagiotis 

Join us on Telegram

 

Ridiculous, this only happens when my robot is activated. it's a simple code to immediately close the position once a certain level is reached. If i was to manually close the trade myself i wont get the error.

 

This problem is continuously happening when using a robot....what is going on ?? it's a simple code Does my broker have a delay on cTrader robots ??

 

2021.03.10 14:01:41.349 | Request to close position PID71780050 is sent to server
2021.03.10 14:01:41.349 | Request to close position PID71780050 is sent to server
2021.03.10 14:01:41.349 | Request to close position PID71780050 is sent to server
2021.03.10 14:01:41.521 | → Request to close position PID71780050 is ACCEPTED, order OID131242881 created (10/03/2021 14:01:41.429 UTC+0)
2021.03.10 14:01:41.709 | → Failed to close position PID71780050 with error "POSITION_LOCKED"
2021.03.10 14:01:41.709 | → Failed to close position PID71780050 with error "POSITION_LOCKED"
2021.03.10 14:01:41.927 | → Order OID131242881 is FILLED at 2132.15, position PID71780050 closed (10/03/2021 14:01:41.805 UTC+0)
2021.03.10 14:01:42.240 | cBot "Money Break Even" was stopped for SE30, h8.
2021.03.10 14:01:42.256 | cBot "Money Break Even" was stopped for SE30, h8.
2021.03.10 14:01:42.271 | cBot "Money Break Even" was stopped for SE30, h8.
2021.03.10 14:01:42.287 | cBot "Money Break Even" was stopped for SE30, h8.
2021.03.10 14:01:42.302 | cBot "Money Break Even" was stopped for SE30, h8.
2021.03.10 14:01:41.916 | → Order OID131242881 is FILLED at 2132.15, position PID71780050 closed (10/03/2021 14:01:41.805 UTC+0)


@vtx101

PanagiotisCharalampous
10 Mar 2021, 16:10 ( Updated at: 10 Mar 2021, 16:33 )

Hi arunsub321,

I have explained to you why this happens. As per the log, you are sending three orders to close the same position at the same time

2021.03.10 14:01:41.349 | Request to close position PID71780050 is sent to server
2021.03.10 14:01:41.349 | Request to close position PID71780050 is sent to server
2021.03.10 14:01:41.349 | Request to close position PID71780050 is sent to server

 If you cannot spot the problem in your code, please share the source code and we will try to find the problem for you.

Best Regards,

Panagiotis 

Join us on Telegram


@PanagiotisCharalampous

vtx101
10 Mar 2021, 16:19 ( Updated at: 10 Mar 2021, 16:22 )

RE:

PanagiotisCharalampous said:

Hi arunsub321,

I have explained to you why this happens. As per the log, you are sending three orders to close the same position at the same time

2021.03.10 14:01:41.349 | Request to close position PID71780050 is sent to server
2021.03.10 14:01:41.349 | Request to close position PID71780050 is sent to server
2021.03.10 14:01:41.349 | Request to close position PID71780050 is sent to server

 If you cannot stop the problem in your code, please share the source code and we will try to find the problem for you.

Best Regards,

Panagiotis 

Join us on Telegram

 

 

Well there were times where the request was sent once to close and the error occurred:

2021.03.04 08:52:12.314 | → Order OID312026614 is FILLED at 0.77961, position PID213032943 (04/03/2021 08:52:12.193 UTC+0)
2021.03.04 08:52:14.455 | Request to close position PID213032943 is sent to server
2021.03.04 08:52:14.767 | → Failed to close position PID213032943 with error "POSITION_LOCKED"
2021.03.04 08:52:14.939 | → Order OID312026619 is FILLED at 0.77967, position PID213032943 closed (04/03/2021 08:52:14.773 UTC+0)
2021.03.04 08:52:56.752 | Request to Buy 2.50 Lots GBPUSD (TP: 0.2) is sent to server

i'll have to get in contact with a programmer to provide the source code...


@vtx101

vtx101
10 Mar 2021, 17:10 ( Updated at: 21 Dec 2023, 09:22 )

RE:

PanagiotisCharalampous said:

Hi arunsub321,

I have explained to you why this happens. As per the log, you are sending three orders to close the same position at the same time

2021.03.10 14:01:41.349 | Request to close position PID71780050 is sent to server
2021.03.10 14:01:41.349 | Request to close position PID71780050 is sent to server
2021.03.10 14:01:41.349 | Request to close position PID71780050 is sent to server

 If you cannot spot the problem in your code, please share the source code and we will try to find the problem for you.

Best Regards,

Panagiotis 

Join us on Telegram

here's the source code and screenshot of the program:

using System;
using cAlgo.API;
using System.Linq;
using System.Net;
using System.Text;
using System.Text.RegularExpressions;


namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MoneyBreakEven : Robot
    {

        #region Enums

        public enum MyColors
        {

            AliceBlue,
            AntiqueWhite,
            Aqua,
            Aquamarine,
            Azure,
            Beige,
            Bisque,
            Black,
            BlanchedAlmond,
            Blue,
            BlueViolet,
            Brown,
            BurlyWood,
            CadetBlue,
            Chartreuse,
            Chocolate,
            Coral,
            CornflowerBlue,
            Cornsilk,
            Crimson,
            Cyan,
            DarkBlue,
            DarkCyan,
            DarkGoldenrod,
            DarkGray,
            DarkGreen,
            DarkKhaki,
            DarkMagenta,
            DarkOliveGreen,
            DarkOrange,
            DarkOrchid,
            DarkRed,
            DarkSalmon,
            DarkSeaGreen,
            DarkSlateBlue,
            DarkSlateGray,
            DarkTurquoise,
            DarkViolet,
            DeepPink,
            DeepSkyBlue,
            DimGray,
            DodgerBlue,
            Firebrick,
            FloralWhite,
            ForestGreen,
            Fuchsia,
            Gainsboro,
            GhostWhite,
            Gold,
            Goldenrod,
            Gray,
            Green,
            GreenYellow,
            Honeydew,
            HotPink,
            IndianRed,
            Indigo,
            Ivory,
            Khaki,
            Lavender,
            LavenderBlush,
            LawnGreen,
            LemonChiffon,
            LightBlue,
            LightCoral,
            LightCyan,
            LightGoldenrodYellow,
            LightGray,
            LightGreen,
            LightPink,
            LightSalmon,
            LightSeaGreen,
            LightSkyBlue,
            LightSlateGray,
            LightSteelBlue,
            LightYellow,
            Lime,
            LimeGreen,
            Linen,
            Magenta,
            Maroon,
            MediumAquamarine,
            MediumBlue,
            MediumOrchid,
            MediumPurple,
            MediumSeaGreen,
            MediumSlateBlue,
            MediumSpringGreen,
            MediumTurquoise,
            MediumVioletRed,
            MidnightBlue,
            MintCream,
            MistyRose,
            Moccasin,
            NavajoWhite,
            Navy,
            OldLace,
            Olive,
            OliveDrab,
            Orange,
            OrangeRed,
            Orchid,
            PaleGoldenrod,
            PaleGreen,
            PaleTurquoise,
            PaleVioletRed,
            PapayaWhip,
            PeachPuff,
            Peru,
            Pink,
            Plum,
            PowderBlue,
            Purple,
            Red,
            RosyBrown,
            RoyalBlue,
            SaddleBrown,
            Salmon,
            SandyBrown,
            SeaGreen,
            SeaShell,
            Sienna,
            Silver,
            SkyBlue,
            SlateBlue,
            SlateGray,
            Snow,
            SpringGreen,
            SteelBlue,
            Tan,
            Teal,
            Thistle,
            Tomato,
            Transparent,
            Turquoise,
            Violet,
            Wheat,
            White,
            WhiteSmoke,
            Yellow,
            YellowGreen

        }

        public enum CalcMode
        {

            Money,
            Percentage

        }

        #endregion

        #region Identity

        /// <summary>
        /// Nome del prodotto, identificativo, da modificare con il nome della propria creazione 
        /// </summary>
        public const string NAME = "Money Break Even";

        /// <summary>
        /// La versione del prodotto, progressivo, utilie per controllare gli aggiornamenti se viene reso disponibile sul sito ctrader.guru
        /// </summary>
        public const string VERSION = "1.0.8";

        #endregion

        #region Params

        [Parameter(NAME + " " + VERSION, Group = "Identity", DefaultValue = "https://ctrader.guru/product/money-break-even/")]
        public string ProductInfo { get; set; }

        [Parameter("Mode", Group = "Params", DefaultValue = CalcMode.Percentage)]
        public CalcMode MyCalcMode { get; set; }

        [Parameter("Net Profit Activation ( $ | % )", Group = "Params", DefaultValue = 10.0)]
        public double BEfrom { get; set; }

        [Parameter("Net Profit Target ( $ | % )", Group = "Params", DefaultValue = 3.0)]
        public double BE { get; set; }

        [Parameter("All Cross ?", Group = "Options", DefaultValue = false)]
        public bool GlobalTarget { get; set; }

        [Parameter("Auto Stop ?", Group = "Options", DefaultValue = true)]
        public bool AutoStop { get; set; }

        [Parameter("Remove Pending Orders ?", Group = "Options", DefaultValue = true)]
        public bool RemovePO { get; set; }

        [Parameter("Color Target Logic", Group = "Styles", DefaultValue = MyColors.Magenta)]
        public MyColors Boxcolortarget { get; set; }

        [Parameter("Color Positive Logic", Group = "Styles", DefaultValue = MyColors.DodgerBlue)]
        public MyColors Boxcolorpositive { get; set; }

        [Parameter("Color Negative Logic", Group = "Styles", DefaultValue = MyColors.Orange)]
        public MyColors Boxcolornegative { get; set; }

        [Parameter("Color Activated", Group = "Styles", DefaultValue = MyColors.DarkViolet)]
        public MyColors Boxcoloractive { get; set; }

        /// <summary>
        /// Opzione per la posizione del box info in verticale
        /// </summary>
        [Parameter("Vertical Position", Group = "Styles", DefaultValue = VerticalAlignment.Top)]
        public VerticalAlignment VAlign { get; set; }

        /// <summary>
        /// Opzione per la posizione del box info in orizontale
        /// </summary>
        [Parameter("Horizontal Position", Group = "Styles", DefaultValue = HorizontalAlignment.Left)]
        public HorizontalAlignment HAlign { get; set; }


        #endregion

        #region Property

        private bool Activated;

        private double FixedBEfrom = 0;
        private double FixedBE = 0;
        private double FixedBalance = 0;

        #endregion

        #region cBot Events

        protected override void OnStart()
        {

            // --> Stampo nei log la versione corrente
            Print("{0} : {1}", NAME, VERSION);

            FixedBEfrom = BEfrom;
            FixedBE = BE;
            FixedBalance = Account.Balance;

            Activated = false;

            OnTick();

        }

        protected override void OnTick()
        {

            _monitoring();

        }

        #endregion

        #region Private Methods

        void _monitoring()
        {

            // --> Controllo se calcolare la percentuale sul bilancio
            if (MyCalcMode == CalcMode.Percentage)
            {

                BEfrom = Math.Round((FixedBalance / 100) * FixedBEfrom, 2);
                BE = Math.Round((FixedBalance / 100) * FixedBE, 2);

            }

            // --> Raccolgo tutte le operazioni su questo simbolo
            int nPositions = 0;

            double ttnp = 0.0;

            foreach (var Position in Positions)
            {

                if (!GlobalTarget && Position.SymbolName != SymbolName)
                    continue;

                ttnp += Position.NetProfit;
                nPositions++;

            }

            // --> Se non ci sono trade da monitorare deattivo e basta
            if (nPositions < 1)
            {

                // --> Disattivo
                Activated = false;

                // --> Resetto il nuovo bilancio
                FixedBalance = Account.Balance;

            }

            // --> Se selezionato e se non ci sono trade, fermo il cBot
            if (AutoStop && nPositions < 1)
                Stop();

            // --> Valorizzo l'attivazione se raggiunto
            if (!Activated && ((BEfrom > BE && ttnp >= BEfrom) || (BEfrom < BE && ttnp <= BEfrom)))
                Activated = true;

            // --> Stampo a video alcune informazioni
            string scope = (GlobalTarget) ? "all cross" : "the current cross";
            string logica = (BEfrom == BE) ? "target" : (BEfrom > BE) ? "positive" : "negative";
            string direction = (BEfrom > BE) ? "less" : "greater";
            string netpt = String.Format("{0:0.00}", ttnp);

            string phrase = (Activated) ? string.Format("Activated, I will close all trades for\r\n{0} if net profit is {1} or equal {2}", scope, direction, BE) : string.Format("Relax, I'm monitoring {0} for\r\n{1} logic and waiting net profit reaches {2}", scope, logica, BEfrom);

            string[] items = 
            {

                "MONEY BREAK EVEN\r\n",
                phrase,
                "\r\nNET PROFIT\r\n{0}"

            };
            string info = string.Join("\r\n", items);

            info = string.Format(info, netpt);

            MyColors mycolor = (BEfrom == BE) ? Boxcolortarget : (BEfrom > BE) ? Boxcolorpositive : Boxcolornegative;

            if (Activated)
                mycolor = Boxcoloractive;

            Chart.DrawStaticText("BoxMBE", info, VAlign, HAlign, Color.FromName(mycolor.ToString("G")));

            // --> Se attivato e se sono la soglia di BE chiudo tutto
            if ((Activated && ((BEfrom > BE && ttnp <= BE) || (BEfrom < BE && ttnp >= BE))) || (BEfrom == BE && ((BE >= 0 && ttnp >= BE) || (BE < 0 && ttnp <= BE))))
            {

                // --> Chiudo tutti i trade

                foreach (var Position in Positions)
                {

                    if (!GlobalTarget && Position.SymbolName != SymbolName)
                        continue;

                    ClosePositionAsync(Position);

                }

                // --> Chiudo tutti gli ordini pendenti se richiesto
                if (RemovePO)
                {

                    foreach (var order in PendingOrders)
                    {

                        if (!GlobalTarget && order.SymbolName != SymbolName)
                            continue;

                        CancelPendingOrderAsync(order);

                    }

                }

                // --> Resetto il flag
                Activated = false;

            }

        }

        #endregion

    }

}
 

 

 

 

the program can be downloaded and tested here: https://ctrader.guru/product/money-break-even/


@vtx101