Sort by Takeprofit

Created at 25 Sep 2020, 11:34
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!
VE

velu130486

Joined 08.11.2019 Blocked

Sort by Takeprofit
25 Sep 2020, 11:34


Dear All,

I had downloaded the following Cbot from this site, which is quite useful for me. However I need your assistance to sort the currency pairs by Total Profit and change the text color if it is negative.

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 HISTORY_DashBoard : Robot
    {

        [Parameter("Komenti_1", DefaultValue = "VDB")]
        public string Komenti_1 { get; set; }

        [Parameter("Timer Sec", DefaultValue = 5, MinValue = 0)]
        public int TimerSec { get; set; }

        //      [Parameter("Komenti_2", DefaultValue = "Urithi")]
        //      public string Komenti_2 { get; set; }

        //      [Parameter("Komenti_3", DefaultValue = "Hiena")]
        //      public string Komenti_3 { get; set; }

        [Parameter("Start Year", DefaultValue = 2020, MinValue = 2010, MaxValue = 2025)]
        public int StartYear { get; set; }

        [Parameter("Start Month", DefaultValue = 1, MinValue = 1, MaxValue = 12)]
        public int StartMonth { get; set; }

        [Parameter("Start Day", DefaultValue = 1, MinValue = 1, MaxValue = 31)]
        public int StartDay { get; set; }

        [Parameter("End Year", DefaultValue = 2020, MinValue = 2016, MaxValue = 2025)]
        public int EndYear { get; set; }

        [Parameter("End Month", DefaultValue = 12, MinValue = 1, MaxValue = 12)]
        public int EndMonth { get; set; }

        [Parameter("End Day", DefaultValue = 31, MinValue = 1, MaxValue = 31)]
        public int EndDay { get; set; }


        private int TotalTrades;
        private int BuyTrades;
        private int SellTrades;

        private double TotalLots;
        private double BuyLots;
        private double SellLots;

        private double TotalProfit;
        private double BuyProfit;
        private double SellProfit;

        private double TotalPips;
        private double BuyPips;
        private double SellPips;

        private int TotalTXPeriod;
        private double TotalLotPeriod;
        private double TotalProfitPeriod;
        private double TotalPipsPeriod;

        private DateTime startdate;
        private DateTime stopdate;





        protected override void OnStart()
        {

            Timer.Start(TimerSec);

            startdate = new DateTime(StartYear, StartMonth, StartDay);
            stopdate = new DateTime(EndYear, EndMonth, EndDay);

            if (startdate > Server.Time)
            {
                Print("Vendosni nje date fillimi te rregullt");
                Stop();
            }
            if (stopdate < startdate)
                stopdate = Server.Time;

            Print("Hope you will enjoy this dashboard and use it everyday");
            Print("please visit us @   https://www.bregu.al   and contact me directly form the contact page");
            Print("If want to know more about this dashboard or think that something can be improved, ");



            Vizato_Info(1, 2);
            Vizato_HEADER(3);

            //    Vizato_Dashboard(2, 3, "AUDCHF", Komenti_1);
            //    Vizato_Dashboard(2, 4, "AUDJPY", Komenti_1);
            //    Vizato_Dashboard(2, 5, "AUDUSD", Komenti_1);
            //    Vizato_Dashboard(2, 6, "CADJPY", Komenti_1);
            //    Vizato_Dashboard(2, 7, "CHFJPY", Komenti_1);
            //    Vizato_Dashboard(2, 8, "EURAUD", Komenti_1);
            //    Vizato_Dashboard(2, 9, "EURCAD", Komenti_1);
            //    Vizato_Dashboard(2, 10, "EURGBP", Komenti_1);
            //    Vizato_Dashboard(2, 11, "EURJPY", Komenti_1);
            //    Vizato_Dashboard(2, 12, "EURUSD", Komenti_1);
            //    Vizato_Dashboard(2, 13, "GBPAUD", Komenti_1);
            //    Vizato_Dashboard(2, 14, "GBPCHF", Komenti_1);
            //    Vizato_Dashboard(2, 15, "GBPJPY", Komenti_1);
            //    Vizato_Dashboard(2, 16, "GBPUSD", Komenti_1);
            //    Vizato_Dashboard(2, 17, "NZDJPY", Komenti_1);
            //    Vizato_Dashboard(2, 18, "NZDUSD", Komenti_1);
            //    Vizato_Dashboard(2, 19, "USDCAD", Komenti_1);
            //    Vizato_Dashboard(2, 20, "USDCHF", Komenti_1);
            //    Vizato_Dashboard(2, 21, "USDJPY", Komenti_1);
            //    Vizato_Dashboard(2, 22, "XAUUSD", Komenti_1);



        }


        protected override void OnTimer()
        {
            // Put your core logic here

            TotalTXPeriod = 0;
            TotalLotPeriod = 0;
            TotalProfitPeriod = 0;
            TotalPipsPeriod = 0;

            Vizato_Dashboard(2, 23, "AUDCHF", Komenti_1);

            TotalTXPeriod = TotalTXPeriod + TotalTrades;
            TotalLotPeriod = TotalLotPeriod + TotalLots;
            TotalProfitPeriod = TotalProfitPeriod + TotalProfit;
            TotalPipsPeriod = TotalPipsPeriod + TotalPips;

            Vizato_Dashboard(2, 4, "AUDJPY", Komenti_1);

            TotalTXPeriod = TotalTXPeriod + TotalTrades;
            TotalLotPeriod = TotalLotPeriod + TotalLots;
            TotalProfitPeriod = TotalProfitPeriod + TotalProfit;
            TotalPipsPeriod = TotalPipsPeriod + TotalPips;

            Vizato_Dashboard(2, 5, "AUDUSD", Komenti_1);

            TotalTXPeriod = TotalTXPeriod + TotalTrades;
            TotalLotPeriod = TotalLotPeriod + TotalLots;
            TotalProfitPeriod = TotalProfitPeriod + TotalProfit;
            TotalPipsPeriod = TotalPipsPeriod + TotalPips;

            Vizato_Dashboard(2, 6, "CADJPY", Komenti_1);

            TotalTXPeriod = TotalTXPeriod + TotalTrades;
            TotalLotPeriod = TotalLotPeriod + TotalLots;
            TotalProfitPeriod = TotalProfitPeriod + TotalProfit;
            TotalPipsPeriod = TotalPipsPeriod + TotalPips;

            Vizato_Dashboard(2, 7, "CHFJPY", Komenti_1);

            TotalTXPeriod = TotalTXPeriod + TotalTrades;
            TotalLotPeriod = TotalLotPeriod + TotalLots;
            TotalProfitPeriod = TotalProfitPeriod + TotalProfit;
            TotalPipsPeriod = TotalPipsPeriod + TotalPips;

            Vizato_Dashboard(2, 8, "EURAUD", Komenti_1);

            TotalTXPeriod = TotalTXPeriod + TotalTrades;
            TotalLotPeriod = TotalLotPeriod + TotalLots;
            TotalProfitPeriod = TotalProfitPeriod + TotalProfit;
            TotalPipsPeriod = TotalPipsPeriod + TotalPips;

            Vizato_Dashboard(2, 9, "EURCAD", Komenti_1);

            TotalTXPeriod = TotalTXPeriod + TotalTrades;
            TotalLotPeriod = TotalLotPeriod + TotalLots;
            TotalProfitPeriod = TotalProfitPeriod + TotalProfit;
            TotalPipsPeriod = TotalPipsPeriod + TotalPips;

            Vizato_Dashboard(2, 10, "EURGBP", Komenti_1);

            TotalTXPeriod = TotalTXPeriod + TotalTrades;
            TotalLotPeriod = TotalLotPeriod + TotalLots;
            TotalProfitPeriod = TotalProfitPeriod + TotalProfit;
            TotalPipsPeriod = TotalPipsPeriod + TotalPips;

            Vizato_Dashboard(2, 11, "EURJPY", Komenti_1);

            TotalTXPeriod = TotalTXPeriod + TotalTrades;
            TotalLotPeriod = TotalLotPeriod + TotalLots;
            TotalProfitPeriod = TotalProfitPeriod + TotalProfit;
            TotalPipsPeriod = TotalPipsPeriod + TotalPips;

            Vizato_Dashboard(2, 12, "EURUSD", Komenti_1);

            TotalTXPeriod = TotalTXPeriod + TotalTrades;
            TotalLotPeriod = TotalLotPeriod + TotalLots;
            TotalProfitPeriod = TotalProfitPeriod + TotalProfit;
            TotalPipsPeriod = TotalPipsPeriod + TotalPips;

            Vizato_Dashboard(2, 13, "GBPAUD", Komenti_1);

            TotalTXPeriod = TotalTXPeriod + TotalTrades;
            TotalLotPeriod = TotalLotPeriod + TotalLots;
            TotalProfitPeriod = TotalProfitPeriod + TotalProfit;
            TotalPipsPeriod = TotalPipsPeriod + TotalPips;

            Vizato_Dashboard(2, 14, "GBPCHF", Komenti_1);

            TotalTXPeriod = TotalTXPeriod + TotalTrades;
            TotalLotPeriod = TotalLotPeriod + TotalLots;
            TotalProfitPeriod = TotalProfitPeriod + TotalProfit;
            TotalPipsPeriod = TotalPipsPeriod + TotalPips;

            Vizato_Dashboard(2, 15, "GBPJPY", Komenti_1);

            TotalTXPeriod = TotalTXPeriod + TotalTrades;
            TotalLotPeriod = TotalLotPeriod + TotalLots;
            TotalProfitPeriod = TotalProfitPeriod + TotalProfit;
            TotalPipsPeriod = TotalPipsPeriod + TotalPips;

            Vizato_Dashboard(2, 16, "GBPUSD", Komenti_1);

            TotalTXPeriod = TotalTXPeriod + TotalTrades;
            TotalLotPeriod = TotalLotPeriod + TotalLots;
            TotalProfitPeriod = TotalProfitPeriod + TotalProfit;
            TotalPipsPeriod = TotalPipsPeriod + TotalPips;

            Vizato_Dashboard(2, 17, "NZDJPY", Komenti_1);

            TotalTXPeriod = TotalTXPeriod + TotalTrades;
            TotalLotPeriod = TotalLotPeriod + TotalLots;
            TotalProfitPeriod = TotalProfitPeriod + TotalProfit;
            TotalPipsPeriod = TotalPipsPeriod + TotalPips;

            Vizato_Dashboard(2, 18, "NZDUSD", Komenti_1);

            TotalTXPeriod = TotalTXPeriod + TotalTrades;
            TotalLotPeriod = TotalLotPeriod + TotalLots;
            TotalProfitPeriod = TotalProfitPeriod + TotalProfit;
            TotalPipsPeriod = TotalPipsPeriod + TotalPips;

            Vizato_Dashboard(2, 19, "USDCAD", Komenti_1);

            TotalTXPeriod = TotalTXPeriod + TotalTrades;
            TotalLotPeriod = TotalLotPeriod + TotalLots;
            TotalProfitPeriod = TotalProfitPeriod + TotalProfit;
            TotalPipsPeriod = TotalPipsPeriod + TotalPips;

            Vizato_Dashboard(2, 20, "USDCHF", Komenti_1);

            TotalTXPeriod = TotalTXPeriod + TotalTrades;
            TotalLotPeriod = TotalLotPeriod + TotalLots;
            TotalProfitPeriod = TotalProfitPeriod + TotalProfit;
            TotalPipsPeriod = TotalPipsPeriod + TotalPips;

            Vizato_Dashboard(2, 21, "USDJPY", Komenti_1);

            TotalTXPeriod = TotalTXPeriod + TotalTrades;
            TotalLotPeriod = TotalLotPeriod + TotalLots;
            TotalProfitPeriod = TotalProfitPeriod + TotalProfit;
            TotalPipsPeriod = TotalPipsPeriod + TotalPips;

            Vizato_Dashboard(2, 22, "XAUUSD", Komenti_1);

            TotalTXPeriod = TotalTXPeriod + TotalTrades;
            TotalLotPeriod = TotalLotPeriod + TotalLots;
            TotalProfitPeriod = TotalProfitPeriod + TotalProfit;
            TotalPipsPeriod = TotalPipsPeriod + TotalPips;

            Vizato_Totals(2, 26);


        }


        protected void Llogarit_Vizato_Vlerat(string Komenti, string Monedha)
        {

            var PozHistMonBuy = History.FindAll(Komenti, MarketData.GetSymbol(Monedha), TradeType.Buy);
            var PozHistMonSell = History.FindAll(Komenti, MarketData.GetSymbol(Monedha), TradeType.Sell);

            TotalTrades = 0;
            BuyTrades = 0;
            SellTrades = 0;

            TotalLots = 0;
            BuyLots = 0;
            SellLots = 0;

            TotalProfit = 0;
            BuyProfit = 0;
            SellProfit = 0;

            TotalPips = 0;
            BuyPips = 0;
            SellPips = 0;

            foreach (var histbuy in PozHistMonBuy)
            {
                if (histbuy.ClosingTime > startdate && histbuy.ClosingTime < stopdate)
                {
                    BuyTrades = BuyTrades + 1;
                    BuyLots = BuyLots + histbuy.Quantity;
                    BuyProfit = BuyProfit + histbuy.NetProfit;
                    BuyPips = BuyPips + histbuy.Pips;
                }
            }

            foreach (var histsell in PozHistMonSell)
            {
                if (histsell.ClosingTime > startdate && histsell.ClosingTime < stopdate)
                {
                    SellTrades = SellTrades + 1;
                    SellLots = SellLots + histsell.Quantity;
                    SellProfit = SellProfit + histsell.NetProfit;
                    SellPips = SellPips + histsell.Pips;
                }
            }

            TotalTrades = BuyTrades + SellTrades;
            TotalLots = BuyLots + SellLots;
            TotalProfit = BuyProfit + SellProfit;
            TotalPips = BuyPips + SellPips;

        }

        private void Vizato_HEADER(int NLs)
        {
            var ngjyra = Colors.SteelBlue;

            string String_2 = "Header";

            ChartObjects.DrawText(String_2, my_NL(NLs) + "SYMBOL" + my_Tabs(1) + "B TRX" + my_Tabs(2) + "B Qty" + my_Tabs(2) + "B Net" + my_Tabs(2) + "B Pip" + my_Tabs(2) + "S TRX" + my_Tabs(2) + "S Qty" + my_Tabs(2) + "S Net" + my_Tabs(2) + "S Pip" + my_Tabs(2) + "T TRX" + my_Tabs(2) + "T Qty" + my_Tabs(2) + "T Net" + my_Tabs(2) + "T Pip", StaticPosition.TopLeft, ngjyra);

        }

        private void Vizato_Info(int NLs, int TABS)
        {
            var ngjyra = Colors.White;

            string String_3 = "Info";

            ChartObjects.DrawText(String_3, my_NL(NLs) + "Visit us @  https://www.bregu.al  - History Status Report   - from:  " + startdate + "  to  " + stopdate, StaticPosition.TopLeft, ngjyra);

        }


        private void Vizato_Dashboard(int TABS, int NLs, string Monedha, string Komenti)
        {

            Llogarit_Vizato_Vlerat(Komenti, Monedha);

            var ngjyra = Colors.White;

            string String_4 = "Dashboard_line" + Monedha;
            string String_5 = "Parms" + Monedha;

            ChartObjects.DrawText(String_4, my_NL(NLs) + Monedha, StaticPosition.TopLeft, ngjyra);

            ChartObjects.DrawText(String_5, my_NL(NLs) + my_Tabs(TABS) + BuyTrades + my_Tabs(TABS) + BuyLots + my_Tabs(TABS) + Math.Round(BuyProfit, 2) + my_Tabs(TABS) + Math.Round(BuyPips, 2) + my_Tabs(TABS) + SellTrades + my_Tabs(TABS) + SellLots + my_Tabs(TABS) + Math.Round(SellProfit, 2) + my_Tabs(TABS) + Math.Round(SellPips, 2) + my_Tabs(TABS) + TotalTrades + my_Tabs(TABS) + TotalLots + my_Tabs(TABS) + Math.Round(TotalProfit, 2) + my_Tabs(TABS) + Math.Round(TotalPips, 2), StaticPosition.TopLeft, ngjyra);

        }

        private void Vizato_Totals(int TABS, int NLs)
        {

            var ngjyra = Colors.SteelBlue;

            string String_6 = "Totals";

            ChartObjects.DrawText(String_6, my_NL(NLs) + "Period:  Total TRX = " + TotalTXPeriod + my_Tabs(TABS) + "Total Lots = " + TotalLotPeriod + my_Tabs(TABS) + "Total Profit = " + TotalProfitPeriod + my_Tabs(TABS) + "Total Pips = " + TotalPipsPeriod, StaticPosition.TopLeft, ngjyra);



        }


        static string my_NL(int n)
        {
            return new String('\n', n);
        }

        static string my_Tabs(int n)
        {
            return new String('\t', n);
        }

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

Thanks in Advance

R. Vadivelan