Close all positions

Created at 26 Sep 2021, 13:50
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!
SS

sskemil

Joined 26.09.2021

Close all positions
26 Sep 2021, 13:50


Is it possible to get a robot to close all positions when the equity shows a certain amount?

@sskemil
Replies

amusleh
27 Sep 2021, 10:38

Hi,

Yes, its possible:

using cAlgo.API;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class MinEquityBot : Robot
    {
        [Parameter("Min Equity", DefaultValue = 1000)]
        public int MinEquity { get; set; }

        protected override void OnTick()
        {
            if (Account.Equity <= MinEquity)
            {
                foreach (var position in Positions)
                {
                    ClosePosition(position);
                }
            }
        }
    }
}

 


@amusleh