Help with Equity collection bot

Created at 30 Jul 2017, 00:14
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!
TH

theonlinemick

Joined 23.07.2017

Help with Equity collection bot
30 Jul 2017, 00:14


At the moment I have it closing all positions when "ProfitTarget" is reached. You Input the "StartingBalance" so it closes positions with a true nominated profit amount, as opposed to the difference between balance drawdown and equity acting as "ProfitTarget".

What I'd like to do, is after closing all positions on "ProfitTarget", I need it to then update the "StartingBalance" parameter value without needing to stop the bot and manually change it.

 

[Parameter("Starting Balance ($)", DefaultValue = 5000)]
        public int StartingBalance { get; set; }
[Parameter("Profit Target ($)", DefaultValue = 500)]
        public int ProfitTarget { get; set; }

double _myEquity;

protected override void OnStart()
        {
            _myEquity = Account.Equity;
        }

Protected override void OnTick()
        {
            if (Account.Equity > (StartingBalance + ProfitTarget))
            {
                foreach (var position in Positions)
                {
                    ClosePosition(position); 
                }
            }
        }
    

Thanks for your time and any help you can offer :)


@theonlinemick
Replies

croucrou
30 Jul 2017, 14:12

Like this?

[Parameter("Initial Starting Balance ($)", DefaultValue = 5000)]
        public double Initial StartingBalance { get; set; }
[Parameter("Profit Target ($)", DefaultValue = 500)]
        public double ProfitTarget { get; set; }
 
double _myEquity;
double StartingBalance;
 
protected override void OnStart()
        {
            _myEquity = Account.Equity;
            StartingBalance = InitialStartingBalance;
        }
 
Protected override void OnTick()
        {
            if (Account.Equity >= (StartingBalance + ProfitTarget))
            {
                foreach (var position in Positions)
                {
                    ClosePosition(position); 
                }
                StartingBalance = StartingBalance + ProfitTarget;
            }
        }

 


@croucrou