CBot for closing all position at a predefined equity level?

06 Dec 2018, 14:44CBot for closing all position at a predefined equity level?#1
Dim13 posts: 1since: 06 Dec 2018


Is there a cBot available for closing all positions when reaching a predefined equity level? Assume you start with equity level at 5k and reach 7K, but want to protect your initial investment regardless of individual SL levels of each position. That cBot would take priority in protecting initial equity vs individual positions when X equity level is reached.


Any suggestions anyone?


Thank you.

06 Dec 2018, 14:59#2
Panagiotis Charalampousposts: 1818since: 13 Jan 2017

Hi Dim13,

Thank you for posting in our forum. See below an example. 

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo.Robots
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class NewcBot : Robot
        [Parameter(DefaultValue = 20000)]
        public double EquityLevel { get; set; }

        protected override void OnStart()
            // Put your initialization logic here

        protected override void OnTick()
            if (EquityLevel > Account.Equity)
                foreach (var position in Positions)

        protected override void OnStop()
            // Put your deinitialization logic here

This cBot will close all positions as soon as the equity drops below the level set in the predefined parameter.

Best Regards,


Head of Community Management at cTrader