CBot for closing all position at a predefined equity level?

Created at 06 Dec 2018, 14:44
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!
DI

dim13

Joined 06.12.2018

CBot for closing all position at a predefined equity level?
06 Dec 2018, 14:44


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.


@dim13
Replies

PanagiotisCharalampous
06 Dec 2018, 14:59

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


@PanagiotisCharalampous

tasr1r1
27 Jan 2019, 17:11

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?


@tasr1r1

tasr1r1
27 Jan 2019, 20:10

RE:

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.


@tasr1r1