How to calculate the all profits in pips when stopping the strategy

Created at 07 Aug 2021, 16: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!
RE

RedSeaBro

Joined 10.04.2021

How to calculate the all profits in pips when stopping the strategy
07 Aug 2021, 16:14


How to calculate the the total profit of all positions in pips when stopping the strategy?


@RedSeaBro
Replies

amusleh
09 Aug 2021, 15:28

Hi,

Try this:

using System;
using System.Linq;
using cAlgo.API;

namespace cAlgo.Robots
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
    public class Test : Robot
    {
        [Parameter(DefaultValue = "Test")]
        public string Label { get; set; }

        protected override void OnStop()
        {
            var openPoisitionPipsSum = Positions.FindAll(Label).Sum(position => position.Pips);
            var historicalTradesPipsSum = History.Where(trade => trade.Label.Equals(Label, StringComparison.OrdinalIgnoreCase)).Sum(trade => trade.Pips);

            Print("Open Positions Pips: {0} | Historical Trades Pips: {1}", openPoisitionPipsSum, historicalTradesPipsSum);
        }
    }
}

 


@amusleh