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: 2since: 06 Dec 2018

Hi,

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: 2112since: 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)
                {
                    position.Close();
                }
            }
        }

        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,

Panagiotis


Head of Community Management at cTrader
27 Jan 2019, 17:11#3
tasr1r1posts: 28since: 25 Dec 2012

hi

 

im interested with similar ideas, how about a bot what would close all opened positions for that pair (regardless of buy or sell) once net / gross profit (not pips) is reach which is set by user.

is this possible in ctrader automate?

27 Jan 2019, 20:10RE:#4
tasr1r1posts: 28since: 25 Dec 2012

tasr1r1 said:

hi

 

im interested with similar ideas, how about a bot what would close all opened positions for that pair (regardless of buy or sell) once net / gross profit (not pips) is reach which is set by user.

is this possible in ctrader automate?

kindly ignore this.. as i cannot delete this comment, item considered closed.