Total profit corresponding to the label.

Created at 07 Mar 2016, 19:26
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!
TR

tradermatrix

Joined 24.07.2012

Total profit corresponding to the label.
07 Mar 2016, 19:26


Hello
can you tell me if it is possible to make a total profit related to the label.?
this would not mix decision-profits with several robots (or positions) that operate on the same account.
in my example the profit taking is on "Account.Equity - Account.Balance".
I would like to improve the method.
thanks in advance.
 

  [Parameter("TotalProfit", DefaultValue = 10)]
        public double TotalProfit { get; set; }

  protected override void OnTick()
        {


            var netProfit = 0.0;
            foreach (var openedPosition in Positions)
            {
                netProfit += openedPosition.NetProfit + openedPosition.Commissions;
            }
            ChartObjects.DrawText("a", netProfit.ToString(), StaticPosition.BottomRight, new Colors?(Colors.Lime));

            {
                if (Account.Equity - Account.Balance > TotalProfit)                {

                    foreach (var openedPosition in Positions)
                    {

                        ClosePosition(openedPosition);


                        foreach (var pendingOrder in PendingOrders)
                        {

                            CancelPendingOrder(pendingOrder);



                        }
                    }
                }
            }
        }
    }
}

thanks in advance.


@tradermatrix
Replies

... Deleted by UFO ...

tradermatrix
07 Mar 2016, 21:27

RE:

lucian said:

 profit = 0;
            foreach (var posi in Positions)
            {

                if (posi.Label.StartsWith(label))
                {
                    profit += posi.NetProfit;
                }
            }

thank you
I will try to adapt your code
cordially


@tradermatrix

steel.export
22 Jan 2021, 09:03 ( Updated at: 22 Jan 2021, 09:07 )

hi


@steel.export