Stop Loss and Take Profit at Equity Value

Created at 06 Jun 2018, 18:11
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!
QO

qorrog2@utexas.edu

Joined 06.06.2018

Stop Loss and Take Profit at Equity Value
06 Jun 2018, 18:11


I'm trying to find a way to do an equity stop loss and take profit, e.g. close all positions when equity is at a desired value. Can you please tell me how or direct me to a Cbot that does this? Thanks!

@qorrog2@utexas.edu
Replies

PanagiotisCharalampous
07 Jun 2018, 09:30

Dear qorrog2@utexas.edu,

Thanks for posting in our forum. See an example below

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 = 0.0)]
        public double EquityTakeProfit { get; set; }

        [Parameter(DefaultValue = 0.0)]
        public double EquityStopLoss { get; set; }

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

        protected override void OnTick()
        {
            //if account equity is more than equity take profit or less than equity stop loss, we close all positions
            if (Account.Equity > EquityTakeProfit || Account.Equity < EquityStopLoss)
                foreach (var position in Positions)
                    ClosePosition(position);
        }

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

Best Regards,

Panagiotis


@PanagiotisCharalampous

qorrog2@utexas.edu
08 Jun 2018, 01:54

Dear Mr. Charalampous, Can this code be used in Ctrader plateform? If yes how? Thank you!!
@qorrog2@utexas.edu

PanagiotisCharalampous
08 Jun 2018, 09:47

Hi qorrog2@utexas.edu,

This is just an example code on how you could program such a behavior. You could use it if you want but I am not sure if this fits your requirements. You can find out how to create and run a cBot here. If you are not a programmer, I would suggest to consider some professional assistance like hiring a Consultant.

Best Regards,

Panagiotis


@PanagiotisCharalampous