Stopping The cBot

Created at 16 Apr 2019, 14:37
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!
PE

pejman101

Joined 12.04.2019

Stopping The cBot
16 Apr 2019, 14:37


Hello and good day

I'm trying to make an emergency stop function for my cbot in case, equity drops X% of the balance of the account but i can't get it right


[Parameter("X% of Balance", DefaultValue = 50, MinValue = 1)]
        public int TheX { get; set; }



            var p = Positions.FindAll(InstanceName, Symbol);
            if (EmergencyStop)
                if (p.Count() >= 1)
                    if (Account.Equity < Account.Balance *(TheX / 100)
                    {
                        ClosePosition(TradeType.Sell);
                        ClosePosition(TradeType.Buy);
                        Process.GetCurrentProcess().Close();
                        return;
                    }

but when i simply divide it to a number it works perfectly 

var p = Positions.FindAll(InstanceName, Symbol);
            if (EmergencyStop)
                if (p.Count() >= 1)
                    if (Account.Equity < Account.Balance / 2)
                    {
                        ClosePosition(TradeType.Sell);
                        ClosePosition(TradeType.Buy);
                        Process.GetCurrentProcess().Close();
                        return;
                    }

also is there any way to close the positions with the maximum available price?

when it's closing the profiting position it uses the entry price

Best regards, Pezhman


@pejman101
Replies

pejman101
16 Apr 2019, 14:40

RE:

pejman101 said:


                    if (Account.Equity < Account.Balance *(TheX / 100)

 

There is a typo here don't mind it


@pejman101