figure out net profit from starting point of Cbot

Created at 27 Feb 2018, 10:23
itmfar's avatar

itmfar

Joined 08.11.2017

figure out net profit from starting point of Cbot
27 Feb 2018, 10:23


how it is possible to find out the net profit ,the number of winning trades and earning pips from the begining of starting a Cbot till now?

in below example we just find out today profit

        protected override void OnTick()
        {
            double totalprofit = 0;
            foreach (HistoricalTrade trade in History)
            {
                if ((trade.SymbolCode == Symbol.Code) && (trade.ClosingTime.Date.Day == Server.Time.Date.Day) && (trade.ClosingTime.Date.Month == Server.Time.Date.Month))
                {
                    totalprofit += trade.NetProfit;
                }
            }
            Print("Total Profit =  " + totalprofit);
            ChartObjects.DrawText("Firsttext1", "Totsl today profit" + totalprofit.ToString(), StaticPosition.TopLeft, Colors.Gray);
            }

also maybe we can use GetFitnessArgs


@itmfar
Replies

PanagiotisCharalampous
27 Feb 2018, 11:42

Hi itmfar,

A suggestion is to add a label to the trades placed by the cBot and then trace them by label instead by date.

Best Regards,

Panagiotis


@PanagiotisCharalampous

itmfar
27 Feb 2018, 12:33

Hi panagiotis

thanks for your answer
what about gained pips and total winning trades?


@itmfar

PanagiotisCharalampous
27 Feb 2018, 12:45

Hi itmfar,

See below

        protected override void OnTick()
        {
            double totalprofit = 0;
            double gainedPips = 0;
            int winningTrades = 0;
            foreach (HistoricalTrade trade in History)
            {
                if (trade.Label == "Your Label")
                {
                    totalprofit += trade.NetProfit;
                    gainedPips += trade.Pips;
                    if (trade.NetProfit > 0)
                        winningTrades++;
                }
            }
        }

Best Regards,

Panagiotis


@PanagiotisCharalampous