Net profit (PnL) shown in percent

by brunoamancio.ti in category Other at 16/12/2016
Description

This is a simple indicator. It shows the PnL in %. I think it makes much more sense than a value, but cTrader hasn't implemented something that simple.

Updated: It now also shows the PnL of the whole account.

Download
363 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 System;
using System.Linq;
using cAlgo.API;

namespace cAlgo
{
    [Indicator(IsOverlay = true, AccessRights = AccessRights.None)]
    public class PLPercentage : Indicator
    {
        public override void Calculate(int index)
        {
            if (IsLastBar)
                DisplayPLOnChart();
        }

        private void DisplayPLOnChart()
        {
            var symbolPositions = Positions.Where(t => t.SymbolCode == Symbol.Code);
            var symbolPnL = Math.Round(100 * symbolPositions.Sum(t => t.NetProfit) / Account.Balance, 2);
            var accountPnL = Math.Round(100 * Positions.Sum(t => t.NetProfit) / Account.Balance, 2);

            var symbolTextDisplayed = Symbol.Code + " PnL: " + symbolPnL + "% ";
            ChartObjects.DrawText(Symbol.Code + "_SymbolPnL", symbolTextDisplayed, StaticPosition.TopRight, symbolPnL >= 0 ? Colors.Green : Colors.Red);

            var accountTextDisplayed = "\nAccount PnL: " + accountPnL + "% ";
            ChartObjects.DrawText(Symbol.Code + "_AccountPnL", accountTextDisplayed, StaticPosition.TopRight, accountPnL >= 0 ? Colors.Green : Colors.Red);
        }
    }
}
Comments
0