Display Pips

Created at 27 May 2016, 22:43
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!
HE

hedgehog

Joined 24.04.2016

Display Pips
27 May 2016, 22:43


Hello,

I'm not programmer and I would like to build simple text indicator, which displays some statistic attributes on my chart.

So, I want to put on the chart, for example chart EURJPY:

1. Balance +/- of my current trade/s/ in pips for pair on chart /EURJPY/, if there is no trade of this pair, there will be simply 0

2. Balance +/- of trades of this pair /EURJPY/ during all day, if there is no trades of this pair, there will be simply zero

3. Balance +/- of trades of all pairs during one day /EURJPY, AUDUSD, EURUSD.../, if no one there will be zero

Is it possible to code something like this for ctrader? Could someone help me, I dont know how to start.

Thank you very much 


@hedgehog
Replies

... Deleted by UFO ...

hedgehog
28 May 2016, 18:24

Thank you man, next week I will test it.


@hedgehog

... Deleted by UFO ...

davidbtosh
29 May 2016, 08:34

RE:

lucian said:

cBot something like this:

 

using System;
using System.Linq;
using cAlgo.API;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class msforex : Robot
    {



        protected override void OnStart()
        {

        }
        protected override void OnTick()
        {

            if (!this.IsBacktesting)
                DisplayStatusOnChart();
        }



        protected override void OnBar()
        {



        }



        private string GenerateStatusText()
        {
            var statusText = "";
            var simbol_code = "";
            var simbol_profit = "";
            var simbol_positions = "";
            var simbol_day_profit = "";
            var day_profit = "";
            simbol_code = Symbol.Code;
            simbol_positions = "\nSymbol Positions" + simbol_code + "  =  " + CountOfTrades();
            simbol_profit = "\nSymbol Profit = " + profit_symbol();
            simbol_day_profit = "\nSymbol Day Profi = " + day_profit_symbol();
            day_profit = "\nDay Profit = " + daily_profit();
            statusText = simbol_positions + simbol_profit + simbol_day_profit + day_profit;
            return (statusText);
        }
        private int CountOfTrades()
        {
            var tradeCount = 0;

            foreach (var position in Positions)
            {
                if (position.SymbolCode == Symbol.Code)
                {

                    tradeCount++;
                }

            }


            return tradeCount;
        }
        private double profit_symbol()
        {
            double profit = 0;

            foreach (var position in Positions)
            {
                if (position.SymbolCode == Symbol.Code)
                {

                    profit += position.NetProfit;
                }

            }


            return profit;
        }
        private double day_profit_symbol()
        {
            double profit = 0;

            foreach (HistoricalTrade trade in History)
            {
                if ((trade.SymbolCode == Symbol.Code) && (trade.ClosingTime.Date == Server.Time.Date))
                {

                    profit += trade.NetProfit;
                }

            }


            return profit;
        }
        private double daily_profit()
        {
            double profit = 0;

            foreach (HistoricalTrade trade in History)
            {
                if (trade.ClosingTime.Date == Server.Time.Date)
                {

                    profit += trade.NetProfit;
                }

            }


            return profit;
        }

        private void DisplayStatusOnChart()
        {

            ChartObjects.DrawText("pan", GenerateStatusText(), StaticPosition.TopRight, Colors.Aqua);
        }


    }
}

You can also use the LINQ library to reduce the amount of code to maintain by doing something like this:

var simbol_profit = string.Format("\nSymbol Profit = {0}", Positions.Where(pos => pos.SymbolCode == Symbol.Code).Sum(s => s.NetProfit));

This uses the LINQ where and Sum extension methods to do exactly the same thing as the custom method. 

 


@davidbtosh

davidbtosh
29 May 2016, 08:35

RE: RE:

ctid201011 said:

lucian said:

cBot something like this:

 

using System;
using System.Linq;
using cAlgo.API;
using System.IO;
using System.Collections;
using System.Collections.Generic;
using cAlgo.API.Indicators;
using cAlgo.API.Internals;
using cAlgo.Indicators;

namespace cAlgo
{
    [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.FullAccess)]
    public class msforex : Robot
    {



        protected override void OnStart()
        {

        }
        protected override void OnTick()
        {

            if (!this.IsBacktesting)
                DisplayStatusOnChart();
        }



        protected override void OnBar()
        {



        }



        private string GenerateStatusText()
        {
            var statusText = "";
            var simbol_code = "";
            var simbol_profit = "";
            var simbol_positions = "";
            var simbol_day_profit = "";
            var day_profit = "";
            simbol_code = Symbol.Code;
            simbol_positions = "\nSymbol Positions" + simbol_code + "  =  " + CountOfTrades();
            simbol_profit = "\nSymbol Profit = " + profit_symbol();
            simbol_day_profit = "\nSymbol Day Profi = " + day_profit_symbol();
            day_profit = "\nDay Profit = " + daily_profit();
            statusText = simbol_positions + simbol_profit + simbol_day_profit + day_profit;
            return (statusText);
        }
        private int CountOfTrades()
        {
            var tradeCount = 0;

            foreach (var position in Positions)
            {
                if (position.SymbolCode == Symbol.Code)
                {

                    tradeCount++;
                }

            }


            return tradeCount;
        }
        private double profit_symbol()
        {
            double profit = 0;

            foreach (var position in Positions)
            {
                if (position.SymbolCode == Symbol.Code)
                {

                    profit += position.NetProfit;
                }

            }


            return profit;
        }
        private double day_profit_symbol()
        {
            double profit = 0;

            foreach (HistoricalTrade trade in History)
            {
                if ((trade.SymbolCode == Symbol.Code) && (trade.ClosingTime.Date == Server.Time.Date))
                {

                    profit += trade.NetProfit;
                }

            }


            return profit;
        }
        private double daily_profit()
        {
            double profit = 0;

            foreach (HistoricalTrade trade in History)
            {
                if (trade.ClosingTime.Date == Server.Time.Date)
                {

                    profit += trade.NetProfit;
                }

            }


            return profit;
        }

        private void DisplayStatusOnChart()
        {

            ChartObjects.DrawText("pan", GenerateStatusText(), StaticPosition.TopRight, Colors.Aqua);
        }


    }
}

You can also use the LINQ library to reduce the amount of code to maintain by doing something like this:

var simbol_profit = string.Format("\nSymbol Profit = {0}", Positions.Where(pos => pos.SymbolCode == Symbol.Code).Sum(s => s.NetProfit));

This uses the LINQ where and Sum extension methods to do exactly the same thing as the custom method. 

 

 


@davidbtosh