Profit/Loss Indicator on chart

by Dagfx in category Other at 02/03/2018
Description

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

.

Download
579 downloads
How to install
Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader

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");
            }
        }





    }

}









Comments

matheusbianchireis - April 14, 2018 @ 08:36

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.

0