When equity reached 10% of profit or 10% of loss then close all position. How to code this please.
When equity reached 10% of profit or 10% of loss then close all position. How to code this please.
21 Sep 2024, 08:58
Hi,
I am trying to code on Algo, When equity reached 10% of profit or 10% of loss then close all position. I have found code below, could you please make example of +10% of equity on code below, Thank you!
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,
Gendenjav
firemyst
25 Sep 2024, 07:01
People would probablyt be more inclined to help you if you used the “insert code block” option and pasted in nicely formatted code instead of what you have.
@firemyst