Description
Show live trading profit, profit percentage and pip amount
Show daily profit net and daily percentage
Show equity and balance
You can also choose to have the indicator displayed on the main Chart or in the bottom windows
using System;
using System.Linq;
using cAlgo.API;
namespace cAlgo.Indicators
{
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class TodayProfit : Indicator
{
[Parameter("SubWindows", DefaultValue = 0, MinValue = 0, Group = "Panel")]
public int SubWindows { get; set; }
[Parameter("Horizental Alignment", DefaultValue = HorizontalAlignment.Right, Group = "Panel")]
public HorizontalAlignment HAlignment { get; set; }
[Parameter("Vertical Alignment", DefaultValue = VerticalAlignment.Bottom, Group = "Panel")]
public VerticalAlignment VAlignment { get; set; }
[Parameter("Shift", DefaultValue = "0 0 30 15", Group = "Panel")]
public string ShiftPanel { get; set; }
[Parameter("Font Size", DefaultValue = 12, Group = "Text")]
public int FontSize { get; set; }
[Parameter("Font Weight", DefaultValue = 11, Group = "Text")]
public FontWeight FontWeight1 { get; set; }
[Parameter("Shift", DefaultValue = "0 3 0 0", Group = "Text")]
public string ShiftText { get; set; }
[Parameter("Text Alignment", DefaultValue = TextAlignment.Center, Group = "Text")]
public TextAlignment Alignment { get; set; }
[Parameter("Today", DefaultValue = "White", Group = "Text Color")]
public string TodayColor { get; set; }
[Parameter("Positive Live", DefaultValue = "Green", Group = "Text Color")]
public string PositiveColor { get; set; }
[Parameter("Negative Live", DefaultValue = "Red", Group = "Text Color")]
public string NegativeColor { get; set; }
[Parameter("Backgroun", DefaultValue = "Gray", Group = "Button Color")]
public string Colorb { get; set; }
[Parameter("Foreground", DefaultValue = "White", Group = "Button Color")]
public string Colorf { get; set; }
private TextBlock[] textblock = new TextBlock[4];
static bool Hide;
private StackPanel ProfitPanel;
protected override void Initialize()
{
ProfitPanel = new StackPanel
{
Margin = ShiftPanel,
VerticalAlignment = VAlignment,
HorizontalAlignment = HAlignment
};
for (int i = 0; i < 4; i++)
{
textblock[i] = new TextBlock
{
FontSize = FontSize,
FontWeight = FontWeight1,
TextAlignment = Alignment,
Margin = ShiftText
};
ProfitPanel.AddChild(textblock[i]);
}
textblock[3].ForegroundColor = TodayColor;
DailyProfit();
if (Positions.Count > 0)
LiveProfit();
if (Hide == true)
ProfitPanel.IsVisible = false;
var button = new Button
{
Text = "☰",
FontSize = 13,
Width = 21,
Height = 21,
VerticalAlignment = VAlignment,
HorizontalAlignment = HAlignment,
Margin = 5,
Padding = 1,
BackgroundColor = Colorb,
ForegroundColor = Colorf,
BorderColor = Colorf
};
button.Click += Button_Click;
if (SubWindows > Chart.IndicatorAreas.Count)
SubWindows = Chart.IndicatorAreas.Count;
if (SubWindows > 0)
{
Chart.IndicatorAreas[SubWindows - 1].AddControl(ProfitPanel);
Chart.IndicatorAreas[SubWindows - 1].AddControl(button);
}
else
{
Chart.AddControl(ProfitPanel);
Chart.AddControl(button);
}
}
private void Button_Click(ButtonClickEventArgs obj)
{
if (Hide == true)
{
Hide = false;
ProfitPanel.IsVisible = true;
}
else
{
Hide = true;
ProfitPanel.IsVisible = false;
}
}
public override void Calculate(int index)
{
if (IsLastBar && Positions.Count > 0 && Hide == false)
{
LiveProfit();
DailyProfit();
}
}
private void DailyProfit()
{
//Calc daily Net Profit
double DailyNet1 = Positions.Sum(p => p.NetProfit);
double DailyNet2;
if (History.Count > 0)
DailyNet2 = History.Where(x => x.ClosingTime.Date == Time.Date).Sum(x => x.NetProfit);
else
DailyNet2 = 0;
var DailyNet = Math.Round(DailyNet1 + DailyNet2, 2);
// get Starting Balance
double StartingBalance;
if (History.Count > 0)
StartingBalance = History.Where(x => x.ClosingTime.Date != Time.Date).OrderBy(x => x.ClosingTime).Last().Balance;
else
StartingBalance = Account.Balance;
//calc Daily Percent Profit
var DailyPercent = Math.Round(DailyNet / StartingBalance * 100, 2);
var Space = "";
if (DailyNet >= 0)
Space = " ";
textblock[3].Text = string.Format("Today: $ {0}{1:#,##0.00}/ {0}{2:#,##0.00}%", Space, DailyNet, DailyPercent);
}
private void LiveProfit()
{
var netProfit = Math.Round(Positions.Sum(p => p.NetProfit), 2);
var PipProfit = Math.Round(Positions.Sum(p => p.Pips), 1);
var PercentProfit = Math.Round(netProfit / Account.Balance * 100, 2);
var Space = "";
var SpacePip = "";
var netclr = TodayColor;
//negative
if (netProfit < 0)
{
netclr = NegativeColor;
if (PipProfit >= 0)
SpacePip = " ";
}
//positive
else if (netProfit >= 0)
{
netclr = PositiveColor;
Space = " ";
SpacePip = " ";
}
textblock[0].Text = "Profit";
textblock[0].ForegroundColor = netclr;
textblock[1].Text = string.Format("Live: {0}{1:#,#0.0} p/ $ {2}{3:#,##0.00}/ {2}{4:#,##0.00}%", SpacePip, PipProfit, Space, netProfit, PercentProfit);
textblock[1].ForegroundColor = netclr;
textblock[2].Text = string.Format("Ba/ Eq: $ {0:#,##0.00}/ $ {1:#,##0.00}", Account.Balance, Account.Equity);
textblock[2].ForegroundColor = netclr;
}
}
}
AM
Amin.fx
Joined on 02.08.2021
- Distribution: Free
- Language: C#
- Trading platform: cTrader Automate
- File name: Today Profit.algo
- Rating: 0
- Installs: 2072
- Modified: 13/10/2021 09:54
Note that publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section, please use the Copyright Infringement Notification form to submit a claim.
Comments
Log in to add a comment.
AM
Hello
This allows you to see the amount of profit and its percentage when the position is closed.
When you change the time frame, that position is hidden from the indicator
LO
love it, thank you
LO
love it, thank you
LO
love it, thank you
Thankful for giving all mixes of LoopWorx in a particular stage. Visit http://www.sentencecorrection.org/correct-my-grammar-find-somebody-to-help/ for getting obvious assessments. Starting now, I can have an ideal blend that I really need to use.