Help: show daily percent profit on chart
Created at 22 Jun 2021, 19:03
Help: show daily percent profit on chart
22 Jun 2021, 19:03
i got 2 error here.
1: i want when user change timezone in ctrader indicator timezone changed.actully i want to get Net profit,history profit and starting balance based on user time zone
2: when i have no history trade for today, indicaotr show nothing and after 1 position closed it start and work perfectly.
actully a want to get Net profit,history profit and starting balance based on user time zone
//khoshroomahdi Create thid indicator for AcademyWave
using System;
using System.Linq;
using cAlgo.API;
using cAlgo.API.Internals;
using cAlgo.API.Indicators;
using cAlgo.Indicators;
namespace cAlgo
{
// This sample indicator shows how to add a text block control on your chart
[Indicator(IsOverlay = true, TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)]
public class AWMultiData : Indicator
{
double StartingBalance;
TextBlock tb = new TextBlock();
//User Parameter
[Parameter("FontSize", DefaultValue = 12)]
public int FontSize { get; set; }
[Parameter("Space to Corner", DefaultValue = 10)]
public int Margin { get; set; }
[Parameter("Horizental Alignment", DefaultValue = HorizontalAlignment.Right)]
public HorizontalAlignment HAlignment { get; set; }
[Parameter("Vertical Alignment", DefaultValue = VerticalAlignment.Bottom)]
public VerticalAlignment VAlignment { get; set; }
[Parameter("Color", DefaultValue = "Red")]
public string Color1 { get; set; }
[Parameter("Opacity", DefaultValue = 0.7, MinValue = 0.1, MaxValue = 1)]
public double Opacity { get; set; }
[Parameter("Text Alignment", DefaultValue = TextAlignment.Center)]
public TextAlignment Alignment { get; set; }
protected override void Initialize()
{
}
public override void Calculate(int index)
{
if (IsLastBar)
DisplaySpreadOnChart();
}
public void DisplaySpreadOnChart()
{
// Calc Spread
var spread = Math.Round(Symbol.Spread / Symbol.PipSize, 2);
string sp = string.Format("{0}", spread);
//Calc daily Net Profit
double DailyNet1 = Positions.Sum(p => p.NetProfit);
double DailyNet2 = History.Where(x => x.ClosingTime.Date == Time.Date).Sum(x => x.NetProfit);
double DailyNet = DailyNet1 + DailyNet2;
// get Starting Balance
StartingBalance = History.Where(x => x.ClosingTime.Date.Day == Server.Time.Date.Day).OrderByDescending(x => x.EntryTime).Last().Balance;
//calc Daily Percent Profit
string DailyPercent = Math.Round(DailyNet / StartingBalance * 100, 2).ToString();
//text property
tb.Text = Symbol.Name + ", " + TimeFrame.ShortName + "\n" + DailyPercent + " %" + "\n" + DailyNet + " $" + "\n" + sp;
tb.FontSize = FontSize;
tb.ForegroundColor = Color1.TrimEnd();
tb.HorizontalAlignment = HAlignment;
tb.VerticalAlignment = VAlignment;
tb.TextAlignment = Alignment;
tb.Margin = Margin;
tb.Opacity = Opacity;
//add text to chart
Chart.AddControl(tb);
}
}
}
IRCtrader
23 Jun 2021, 17:45
I solved the second Problem
get yesterbalance code has problem and i find to solve it. for that value i used below code
@IRCtrader