Information

Username: clctrader
Member since: 20 Jan 2018
Last login: 20 Jan 2018
Status: Active

Activity

Where Created Comments
Algorithms 0 1
Forum Topics 0 1
Jobs 0 0

Last Algorithm Comments

CL
clctrader · 2 years ago

Great stuff.

I've updated to meet with the evolution of the API and stop throwing "obsolete" warnings.

 

 

using System;
using System.Linq;
using cAlgo.API;

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

        private void DisplayPLOnChart()
        {
            var symbolPositions = Positions.Where(t => t.SymbolName == Symbol.Name);
            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 = SymbolName + " PnL: " + symbolPnL + "% ";
            Chart.DrawStaticText("Symbol PnL", symbolTextDisplayed, VerticalAlignment.Top, HorizontalAlignment.Right, symbolPnL >= 0 ? Color.Green : Color.Red);

            var accountTextDisplayed = "\nAccount PnL: " + accountPnL + "% ";
            Chart.DrawStaticText("Account PnL", accountTextDisplayed, VerticalAlignment.Top, HorizontalAlignment.Right, accountPnL >= 0 ? Color.Green : Color.Red);
        }
    }
}