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!
Replies
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

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