Closing all positions in different instruments when a certain profit is reached
Created at 30 Apr 2018, 19:16
CT
Closing all positions in different instruments when a certain profit is reached
30 Apr 2018, 19:16
Hi,
Is there a feature/indicator for cTrader that I can install to have ctrader close all my positions at once in different instruments when a certain profit is reached?
Thanks
Replies
PanagiotisCharalampous
07 May 2018, 14:34
Hi ctid449222,
Thanks for posting in our forum. You can create a cBot to do that. 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 = 0.0)] public double ProfitLevel { get; set; } protected override void OnStart() { // Put your initialization logic here } protected override void OnTick() { var profit = 0.0; foreach (var position in Positions) { profit += position.NetProfit; } if (profit >= ProfitLevel) { foreach (var position in Positions) { ClosePosition(position); } } } protected override void OnStop() { // Put your deinitialization logic here } } }
Let me know if this helps.
Best Regards,
Panagiotis
@PanagiotisCharalampous
ctid449222
03 May 2018, 11:18
anyone? i hope i have made myself clear with my question
@ctid449222