ChartObjects.DrawText

Created at 09 Mar 2016, 17:25
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

ChartObjects.DrawText
09 Mar 2016, 17:25


Hello I have created a robot with several labels. each label has its total earnings. I would like to see on the screen the evolution of earnings for each label. for example, by superimposing the text.

Here is an example of profit-taking

    [Parameter(DefaultValue = 10)]
        public double totalgains1 { get; set; }

   [Parameter(DefaultValue = 10)]
        public double totalgains2 { get; set; }

 [Parameter(DefaultValue = 10)]
        public double totalgains3 { get; set; }



   protected override void OnTick()
        {
 gains1();
 gains2();
 gains3();
}

  private void gains1()
        {


            double earn = 0;



            foreach (var pos in Positions)
            {
                if (pos.Label.StartsWith(Label1))
                {
                    earn += pos.NetProfit;
                }

            }


            if (earn > totalgains1)
            {
                foreach (var pos in Positions)


                    if (pos.Label.StartsWith(Label1))
                    {
                        ClosePosition(pos);
                    }
            }
        }



        private void gains2()
        {


            double earn2 = 0;



            foreach (var pos2 in Positions)
            {
                if (pos2.Label.StartsWith(Label2))
                {
                    earn2 += pos2.NetProfit;
                }

            }


            if (earn2 > totalgains2)
            {
                foreach (var pos2 in Positions)


                    if (pos2.Label.StartsWith(Label2))
                    {
                        ClosePosition(pos2);
                    }
            }
        }
   private void gains3()
        {


            double earn3 = 0;



            foreach (var pos3 in Positions)
            {
                if (pos3.Label.StartsWith(Label3))
                {
                    earn3 += pos3.NetProfit;
                }

            }


            if (earn3 > totalgains3)
            {
                foreach (var pos3 in Positions)


                    if (pos3.Label.StartsWith(Label3))
                    {
                        ClosePosition(pos3);
                    }
            }
        }

 


@tradermatrix
Replies

... Deleted by UFO ...

tradermatrix
09 Mar 2016, 21:12

RE:

Lucian thank you
you are great..!!!

Hi, I hope this sample will help.

 

 

 

 

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 NewcBot : Robot
    {
        [Parameter(DefaultValue = 10)]
        public double totalgains1 { get; set; }

        [Parameter(DefaultValue = 10)]
        public double totalgains2 { get; set; }

        [Parameter(DefaultValue = 10)]
        public double totalgains3 { get; set; }
        public string Label1;
        public string Label2;
        public string Label3;
        public double earn1;
        public double earn2;
        public double earn3;

        protected override void OnTick()
        {
            gains1();
            gains2();
            gains3();
            DisplayEarn();
        }

        private void gains1()
        {


            earn1 = 0;



            foreach (var pos in Positions)
            {
                if (pos.Label.StartsWith(Label1))
                {
                    earn1 += pos.NetProfit;
                }

            }


            if (earn1 > totalgains1)
            {
                foreach (var pos in Positions)


                    if (pos.Label.StartsWith(Label1))
                    {
                        ClosePosition(pos);
                    }
            }
        }



        private void gains2()
        {


            earn2 = 0;



            foreach (var pos2 in Positions)
            {
                if (pos2.Label.StartsWith(Label2))
                {
                    earn2 += pos2.NetProfit;
                }

            }


            if (earn2 > totalgains2)
            {
                foreach (var pos2 in Positions)


                    if (pos2.Label.StartsWith(Label2))
                    {
                        ClosePosition(pos2);
                    }
            }
        }
        private void gains3()
        {


            earn3 = 0;



            foreach (var pos3 in Positions)
            {
                if (pos3.Label.StartsWith(Label3))
                {
                    earn3 += pos3.NetProfit;
                }

            }


            if (earn3 > totalgains3)
            {
                foreach (var pos3 in Positions)


                    if (pos3.Label.StartsWith(Label3))
                    {
                        ClosePosition(pos3);
                    }
            }
        }
        private string GenerateText()
        {

            var e1 = "";
            var e2 = "";
            var e3 = "";
            var earnText = "";
            e1 = "\nEarn1 = " + earn1;
            e2 = "\nEarn2 = " + earn2;
            e3 = "\nEarn3 = " + earn3;

            earnText = e1 + e2 + e3;
            return (earnText);
        }

        private void DisplayEarn()
        {

            ChartObjects.DrawText("text", GenerateText(), StaticPosition.TopRight, Colors.Aqua);
        }
    }
}

 


@tradermatrix