Multiple Systems and Total Displayed in One Chart

I’m trying to get a single chart to plot each system’s results in my brokerage account and the total of all systems (like the

Portfolio Builder chart). I’ve come close but this only displays the first system and doesn’t iterate the results for the others or the total of all systems. Here is what I’m doing:

// Create a query, activate it and write your code here…
// Your systems selection
Int64[] systems = new Int64[]
{
92190352, // Drunk Uncle
102238099, // Nordic C2/ES Swing
98996797, // W Oversold
84372841, // XLN Swing Trading
102283423, // HFX 10 Stock Blue Chip
100008908, // ETF Capital Builder

};

// Your EMA period
int emaPeriod = 30;

foreach (var systemId in systems)
{
// Get a system (for its Name)
var c2System = GetC2SYSTEM(systemId);

        // Daily equity data with commissions and fees
        ITimeSheet timeSheet = TimeSheetFactory(systemId, TimeInterval.Day);

        // Let TimeSheet run
        timeSheet.EquitiesSheet();

        // Extract equity data. 
        var equity = timeSheet.GetColumn(systemId, EquityType.Equity);

        // Your Technical analysis data
        var taData = C2TALib.EMA(equity, emaPeriod);

        // Create a chart object
        ITimeSeriesChart chart = new TimeSeriesChart();
        chart.Name = c2System.Name;

        // Add equity to the chart
        chart.Add(equity, "Equity", Color.Blue);

        // Add Technical analysis to the chart
        chart.Add(taData, "EMA_" + emaPeriod.ToString(), Color.Red);
        
        // Show the chart
        CHART = chart;

}
Help!

Try this:


// Your systems selection
Int64[] systems = new Int64[]
{
92190352, // Drunk Uncle
102238099, // Nordic C2/ES Swing
98996797, // W Oversold
84372841, // XLN Swing Trading
102283423, // HFX 10 Stock Blue Chip
100008908, // ETF Capital Builder
};

// Your EMA period
int emaPeriod = 10;

// Create a systems timesheet with default arguments (= monthly bars)
ITimeSheet timeSheet = TimeSheetFactory(systems);

// Let the timeSheet run
timeSheet.EquitiesSheet();

// See what we have
TABLE = timeSheet.GetEquitiesSheet();

// Declare an equities accumulator variable
Series<DateTime, double> equitiesSum;
// Equities accumulator initialized by the first equity
equitiesSum = timeSheet.GetColumnAsDouble(systems[0], EquityType.Equity);

// Sum remaining equities
for (int i=1;i<systems.Count();i++)
{
  equitiesSum = equitiesSum + timeSheet.GetColumnAsDouble(systems[i], EquityType.Equity);
}

// Create a chart object for summed equities
ITimeSeriesChart chart = new TimeSeriesChart();
chart.Name = "My Systems Sum";
chart.Add(equitiesSum, "Equities Sum", Color.Blue);
CHART = chart;

// All equities chart
ITimeSeriesChart commonChart = new TimeSeriesChart();
commonChart.Name = "My systems";
commonChart.Add(GetEquities(systems));

// Do something with equitiesSum for fun
// Average and ema
var eqAvg = equitiesSum / systems.Count();
var emaAvg = C2TALib.EMA(eqAvg, emaPeriod);
commonChart.Add(emaAvg, "Equities Average EMA", Color.Gold );

CHART = commonChart;

I tried this and I get a daily price table but no chart. Am I doing something wrong?

Probably the same problem like this: EMA code does not work anymore

Ok, I fixed this. You’ll need to force your browser to reload javascript and css. On windows, this is ctrl-f5, on mac it is cmd-shift-R.

Thanks! That did it.

Is this built into the c2 site somewhere? If not can you please add it on the dashboard. Thanks

Can we also have scaling of the returns chart so that the return of each system can be compared relative to each other

Ron can you make your chart code available for everyone and show us how to implement this.

I’d love to but I can’t. This is a feature that i’d like to implement but don’t know how to do it either…

A ROC example is here:
https://collective2.com/c2explorer_help/html/df8cc3aa-b216-486e-90d7-81705cc14fe6.htm#timeseries_sec_02

I’ve taken Bob Svan’s excellent suggestions and modified them to show percentage gains for a number of systems on one chart they really help me see visually how each system is doing relative to the others even when different amounts are invested in each one. I still have a couple of issues.

  1. How do I increase the chart size? I’ve looked in the Seeu instructions and can only find SetChart but that function doesn’t appear to be supported.
  2. the code I’ve reproduced below starts the chart of each system at the date it started at C2 rather than a common start date for all systems which is what I need (i.e., the date I started trading them) . Thus the charts are off because of the differing start dates for each system.

// Systems we want to see in the chart
Tuple<int, String, Color>[] systemsIds = { Tuple.Create(84372841,“XLN Swingtrading”, Color.Blue),
Tuple.Create(107057042,“Xiv Daily strategy”, Color.Red),
Tuple.Create(98996797,“W Oversold”, Color.Green),
Tuple.Create(102283423,“Hfx10 Stock Blue chip”, Color.LightBlue),
Tuple.Create(100008908,“ETF Capital builder”, Color.Violet),
Tuple.Create(92190352,“Drunk Uncle”, Color.Pink),
Tuple.Create(101359777,“All Cap Equity Long”, Color.Yellow)};

// Create a chart object
ITimeSeriesChart timeSeriesChart = new TimeSeriesChart();
timeSeriesChart.Name = “Relative Gains”;

// Add systems items to the chart
foreach (var id in systemsIds)
{
IChartTimeSeries chartSeries = new ChartTimeSeries();
chartSeries.Type = ChartTypes.Line;

// Get starting capital
Decimal startingCash = (from s in C2SYSTEMS
                        where s.SystemId == id.Item1
                        select s.StartingCash).First();

// ROC as a collection of TimeSeriesPoint 
chartSeries.Data = from eq in C2EQUITY
                   where eq.SystemId == id.Item1
                   select new TimeSeriesPoint()
                   {
                       DateTime = eq.DateTime,
                       Value = 100 * (Double)(eq.Value / startingCash)
                   };

chartSeries.Name = id.Item2;
chartSeries.Color = id.Item3;

timeSeriesChart.Add(chartSeries);

}

CHART = timeSeriesChart;

Help, please.

Ron Compton

Hi Ron, in regards to #2, the following should adjust the start date to the graph to line up with the start date of the newest system. I don’t know that there is currently a way to change the chart size. This would be a nice option, but I’m curious to know why you want to change the size?

// Systems we want to see in the chart
Tuple<int, String, Color>[] systemsIds = { Tuple.Create(84372841,“XLN Swingtrading”, Color.Blue),
Tuple.Create(107057042,“Xiv Daily strategy”, Color.Red),
Tuple.Create(98996797,“W Oversold”, Color.Green),
Tuple.Create(102283423,“Hfx10 Stock Blue chip”, Color.LightBlue),
Tuple.Create(100008908,“ETF Capital builder”, Color.Violet),
Tuple.Create(92190352,“Drunk Uncle”, Color.Pink),
Tuple.Create(101359777,“All Cap Equity Long”, Color.Yellow)};

// Create a chart object
ITimeSeriesChart timeSeriesChart = new TimeSeriesChart();
timeSeriesChart.Name = “Relative Gains”;

// Set date filters
DateTime StartDate = DateTime.Today.AddYears(-100);
DateTime EndDate = DateTime.Today.AddDays(-1 * DateTime.Today.Day + 1);

// Bump the start date forward if any systems started later than the start date
foreach (long system in systemsIds.Select(sys => sys.Item1)) {
DateTime systemStart = GetC2SYSTEM(system).Started;
if (systemStart> StartDate) {StartDate = systemStart.AddDays(-1 * systemStart.Day).AddMonths(1);}
}

// Add systems items to the chart
foreach (var id in systemsIds)
{
IChartTimeSeries chartSeries = new ChartTimeSeries();
chartSeries.Type = ChartTypes.Line;

// Get starting capital
Decimal startingCash = (from eq in C2EQUITY
where (eq.SystemId == id.Item1 && eq.DateTime >= StartDate && eq.DateTime < StartDate.AddDays(1))
select eq.Value).First();

// ROC as a collection of TimeSeriesPoint
chartSeries.Data = from eq in C2EQUITY
where (eq.SystemId == id.Item1 && eq.DateTime >= StartDate)
select new TimeSeriesPoint()
{
DateTime = eq.DateTime,
Value = 100 * (Double)(eq.Value / startingCash)
};

chartSeries.Name = id.Item2;
chartSeries.Color = id.Item3;

timeSeriesChart.Add(chartSeries);

}

CHART = timeSeriesChart;

Thank you so much for the code. I’m having difficulty running it as I get
"9:59:10 AM: *** Error: Error CS1525: 100:1 Invalid expression term '/'
Error CS1002: 100:3 ; expected
Error CS1002: 100:14 ; expected
Error CS1002: 100:22 ; expected
Error CS1002: 100:26 ; expected
Error CS1525: 100:26 Invalid expression term 'in’
Error CS1002: 100:29 ; expected
Error CS1002: 100:38 ; expected
9:59:10 AM: Query not saved!

when I try to run it.
The code I have in Explorer is:

/ Systems we want to see in the chart
Tuple[] systemsIds = { Tuple.Create(84372841,“XLN Swingtrading”,
Color.Blue),
Tuple.Create(107057042,“Xiv Daily strategy”, Color.Red),
Tuple.Create(98996797,“W Oversold”, Color.Green),
Tuple.Create(102283423,“Hfx10 Stock Blue chip”, Color.LightBlue),
Tuple.Create(100008908,“ETF Capital builder”, Color.Violet),
Tuple.Create(92190352,“Drunk Uncle”, Color.Pink),
Tuple.Create(101359777,“All Cap Equity Long”, Color.Yellow)};

// Create a chart object
ITimeSeriesChart timeSeriesChart = new TimeSeriesChart();
timeSeriesChart.Name = “Relative Gains”;

// Set date filters
DateTime StartDate = DateTime.Today.AddYears(-100);
DateTime EndDate = DateTime.Today.AddDays(-1 * DateTime.Today.Day + 1);

// Bump the start date forward if any systems started later than the start
date
foreach (long system in systemsIds.Select(sys => sys.Item1)) {
DateTime systemStart = GetC2SYSTEM(system).Started;
if (systemStart> StartDate) {StartDate = systemStart.AddDays(-1 *
systemStart.Day).AddMonths(1);}
}

// Add systems items to the chart
foreach (var id in systemsIds)
{
IChartTimeSeries chartSeries = new ChartTimeSeries();
chartSeries.Type = ChartTypes.Line;

// Get starting capital
Decimal startingCash = (from eq in C2EQUITY
where (eq.SystemId == id.Item1 && eq.DateTime >= StartDate && eq.DateTime <
StartDate.AddDays(1))
select eq.Value).First();

// ROC as a collection of TimeSeriesPoint
chartSeries.Data = from eq in C2EQUITY
where (eq.SystemId == id.Item1 && eq.DateTime >= StartDate)
select new TimeSeriesPoint()
{
DateTime = eq.DateTime,
Value = 100 * (Double)(eq.Value / startingCash)
};

chartSeries.Name = id.Item2;
chartSeries.Color = id.Item3;

timeSeriesChart.Add(chartSeries);

}

CHART = timeSeriesChart;

Thanks again,

Ron Compton

Looks like the code doesn’t copy paste cleanly due to the special characters unless you use the preformatted text option. This should work better:

// Systems we want to see in the chart
Tuple<int, String, Color>[] systemsIds = { Tuple.Create(84372841,"XLN Swingtrading", Color.Blue),
Tuple.Create(107057042,"Xiv Daily strategy", Color.Red),
Tuple.Create(98996797,"W Oversold", Color.Green),
Tuple.Create(102283423,"Hfx10 Stock Blue chip", Color.LightBlue),
Tuple.Create(100008908,"ETF Capital builder", Color.Violet),
Tuple.Create(92190352,"Drunk Uncle", Color.Pink),
Tuple.Create(101359777,"All Cap Equity Long", Color.Yellow)};

// Create a chart object
ITimeSeriesChart timeSeriesChart = new TimeSeriesChart();
timeSeriesChart.Name = "Relative Gains";

// Set date filters
DateTime StartDate = DateTime.Today.AddYears(-100);

// Bump the start date forward if any systems started later than the start date
foreach (long system in systemsIds.Select(sys => sys.Item1)) {
  DateTime systemStart = GetC2SYSTEM(system).Started;
  if (systemStart> StartDate) {StartDate = systemStart.AddDays(-1 * systemStart.Day).AddMonths(1);}
}

// Add systems items to the chart
foreach (var id in systemsIds)
{
  IChartTimeSeries chartSeries = new ChartTimeSeries();
  chartSeries.Type = ChartTypes.Line;

  // Get starting capital
  Decimal startingCash = (from eq in C2EQUITY
                     where (eq.SystemId == id.Item1 && eq.DateTime >= StartDate && eq.DateTime < StartDate.AddDays(1))
                     select eq.Value).First();
  

  // ROC as a collection of TimeSeriesPoint 
  chartSeries.Data = from eq in C2EQUITY
                     where (eq.SystemId == id.Item1 && eq.DateTime >= StartDate)
                     select new TimeSeriesPoint()
                     {
                         DateTime = eq.DateTime,
                         Value = 100 * (Double)(eq.Value / startingCash)
                     };

  chartSeries.Name = id.Item2;
  chartSeries.Color = id.Item3;

  timeSeriesChart.Add(chartSeries);

}

CHART = timeSeriesChart;

Chart sizes:

var chart = GetC2SYSTEM(83833839).SystemChart(EquityChartType.C2Full);
chart.Height = 600;
chart.Width = 800;
CHART = chart;

Thanks Bob, couldn’t find that in the docs.

Now it runs and Explorer shows

10:56:36 PM: Running #296
10:56:37 PM: Data arrived. Working in your browser now.

No matter how long I wait no browser with results appears.

Is this a cache issue? How do I fix it.

It works fine for me.
I am using Chrome and the chart is visible immediately,

Bob,

I use Chrome Canary, maybe I should use the 32 bit version.
On another issue, I use Interactive Brokers. It has a value called Net
Liquidation Value which is the total value of the account - cash and
positions. Can this be charted in Explorer?

Thanks.

Ron