Average Account Equity

Created at 18 Jan 2018, 06:27
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!
SU

suradi

Joined 14.10.2016 Blocked

Average Account Equity
18 Jan 2018, 06:27


Hi,

Would anyone be able to help with code that will calculate the Account's Equity (Account.Equity) amount over X periods ? 

E.g. Average equity over 1 hour, 24hours, etc.

Thanks!

 


Replies

PanagiotisCharalampous
18 Jan 2018, 10:05

Hi Surady,

See below a very simple example on how to calculate your average equity with samples taken on each bar change.

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AverageEquity : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        private double _equity;
        private double _periodCount;

        protected override void OnStart()
        {
            ExecuteMarketOrder(TradeType.Buy, Symbol, 10000);
        }

        protected override void OnBar()
        {
            _equity += Account.Equity;
            _periodCount++;
            Print("Average Equity:" + (_equity / _periodCount));
        }

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

If you need something more complicated or any professional help in developing your cBot, you can post a Job or contact a professional Consultant.

Best Regards,

Panagiotis


@PanagiotisCharalampous

suradi
21 Jan 2018, 13:17

RE:

Thank you! This should get me started

 

Panagiotis Charalampous said:

Hi Surady,

See below a very simple example on how to calculate your average equity with samples taken on each bar change.

using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class AverageEquity : Robot
    {
        [Parameter(DefaultValue = 0.0)]
        public double Parameter { get; set; }

        private double _equity;
        private double _periodCount;

        protected override void OnStart()
        {
            ExecuteMarketOrder(TradeType.Buy, Symbol, 10000);
        }

        protected override void OnBar()
        {
            _equity += Account.Equity;
            _periodCount++;
            Print("Average Equity:" + (_equity / _periodCount));
        }

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

If you need something more complicated or any professional help in developing your cBot, you can post a Job or contact a professional Consultant.

Best Regards,

Panagiotis