Category Other  Published on 11/06/2019

Profit/Loss Indicator on chart

Description

Very Simple indicator to show the current Net Profit/Loss on any open positions in pips and $. Still in development but It works.

.



using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]



    public class profit_indicator : Indicator
    {


        public override void Calculate(int index)
        {
            if (IsLastBar)
                profitOnChart();
        }

        private void profitOnChart()
        {

            var netPips = 0.0;
            var netProfit = 0.0;

            string chartpair = Symbol.Code;

            foreach (var position in Positions)
            {

                string pospair = position.SymbolCode;


                if (pospair == chartpair)
                {

                    netProfit += position.NetProfit;
                    netPips += position.Pips;

                    var pps = string.Format("{0} p", netPips);
                    var nett = string.Format(" / {0: $#,##0.00}", netProfit);

                    var netclr = Colors.SlateGray;
                    if (netProfit < 0)
                    {
                        //negative
                        netclr = Colors.Red;
                    }
                    if (netProfit > 0)
                    {
                        //positive
                        netclr = Colors.Green;
                        pps = "+" + pps;
                    }
                    if (netProfit == 0)
                    {
                        //neither positive or negative,
                        netclr = Colors.SlateGray;
                    }
                    var nets = pps + nett;
                    ChartObjects.DrawText("p1", "\t\t" + nets, StaticPosition.Right, netclr);


                    // ChartObjects.RemoveObject("p1");
                    //  int EntryPrice = position.EntryPrice;
                    //  double EntryTime = position.EntryTime;


                    // int y = Symbol.Ask;
                    // double x = Server.Time;


                    //ChartObjects.("tLine", EntryPrice, EntryTime, x, y, Colors.Gainsboro, 2, LineStyle.Lines)

                }




            }
            if (Positions.Count == 0)
            {
                ChartObjects.RemoveObject("p1");
            }
        }





    }

}











DA
Dagfx

Joined on 04.12.2017

  • Distribution: Free
  • Language: C#
  • Trading platform: cTrader Automate
  • File name: profit_indicator.algo
  • Rating: 5
  • Installs: 3878
  • Modified: 13/10/2021 09:54
Comments
Log in to add a comment.
MU
musicman · 5 years ago

thjis no longer works?  errors on build

MY
MyPipsCount · 5 years ago

Great indicator Dagfx! Is it possible to give the option to show Pips or $ profit as well as to adjust the placement on the chart? 

Thanks again!

DA
Dagfx · 6 years ago

Thanks for the suggestion , I will implement it when I have time.

KO
koala.coffee · 6 years ago

A suggestion to make this even nicer -> take into consideration the current spread, so you can have the exact profit/loss value before closing the position. That would be very good for scalpers that have a thin margin.