public BarSpudPane(BarSpud bars, Collectible symbol, BarSpudGraph parent, DispatcherObject dispatchTo) : base(parent, dates(bars)) { this.bars = bars; this.symbol = symbol; parentTyped = parent; this.dispatchTo = dispatchTo; XAxis.Scale.Min = Math.Max(0, bars.count() - 100); XAxis.Scale.Max = bars.count() + 5; XAxis.Scale.IsVisible = false; }
public void addEquity(Simulator simulator) { Bomb.when(Objects.hasContent(equity), () => "equity has content already: " + Objects.toShortString(equity)); equity.AddRange(simulator.equity(symbol)); var points = new PointPairList(); Objects.eachIt(simulator.equity(symbol), (i, value) => points.Add(i + 1, value)); var curve = AddCurve("equity", points, Color.Red); curve.Symbol.IsVisible = false; curve.IsOverrideOrdinal = true; var zero = new LineObj(Color.Gray, 1, 0, bars.count(), 0) { Line = { Style = DashStyle.Dash }, Location = { CoordinateFrame = CoordType.AxisXYScale } }; GraphObjList.Add(zero); AxisChange(); var graphable = new EquityGraphable("equity", simulator.equity(symbol), simulator.dates(symbol)); graphables.Add(graphable); var needsNewPoint = false; bars.pushedDown += () => needsNewPoint = true; bars.valueSet += bar => { var value = simulator.pnl(symbol); var todaysMarketPnl = Objects.sum(Objects.convert(simulator.positions(symbol), position => position.pnl(bars[1].close, bars[0].close))); value += todaysMarketPnl; graphable.add(bar.time, value); QControl.runOnGuiThread(dispatchTo, () => { var lastPoint = curve[curve.Points.Count - 1]; if (needsNewPoint) { curve.AddPoint(lastPoint.X + 1, value); equity.Add(value); } else { lastPoint.Y = value; equity[equity.Count - 1] = value; } BarSpudGraph.addEquityTo(Objects.first(parentTyped.dataTable().Rows), value); needsNewPoint = false; parentTyped.Invalidate(); }); }; }
public void add(PlotDefinition plot) { var spud = plot.spud; var count = spud.count(); var xPoints = new double[count]; var yPoints = new double[count]; Objects.zeroTo(count, i => { if (i >= bars.count()) { return; // spud has more data than bars } xPoints[count - i - 1] = dateParent.index(bars[i].time); yPoints[count - i - 1] = spud[i]; }); var curve = AddCurve(plot.name, xPoints, yPoints, plot.color); curve.Symbol.IsVisible = false; curve.IsOverrideOrdinal = true; spuds.Add(spud); names.Add(plot.name); var needsNewPoint = false; spud.pushedDown += () => needsNewPoint = true; spud.valueSet += value => QControl.runOnGuiThread(dispatchTo, () => { var lastPoint = curve[curve.Points.Count - 1]; if (needsNewPoint) { curve.AddPoint(lastPoint.X + 1, value); } else { lastPoint.Y = value; } BarSpudGraph.addSpudTo(Objects.first(parentTyped.dataTable().Rows), plot.name, value); needsNewPoint = false; parentTyped.Invalidate(); }); graphables.Add(new DoubleSpudGraphable(plot.name, spud, bars)); }
public void addBars() { var spl = new StockPointList(); Objects.each(bars.toArray(), bar => spl.Add(stockPoint(bar))); var myCurve = AddJapaneseCandleStick(symbol.name, spl); myCurve.Stick.IsAutoSize = true; myCurve.Stick.Color = Color.Black; barsOnPlot = true; XAxis.Scale.IsVisible = true; var graphable = new BarSpudGraphable(bars); graphables.Add(graphable); var needsNewBar = false; bars.pushedDown += () => { needsNewBar = true; QControl.runOnGuiThread(dispatchTo, () => parentTyped.dataTable().addAtStart(parentTyped.dataTable().NewRow()) ); }; bars.valueSet += bar => QControl.runOnGuiThread(dispatchTo, () => { if (needsNewBar) { spl.Add(stockPoint(bar)); dateParent.setDate(bar.time, spl.Count); } else { spl[spl.Count - 1] = stockPoint(bar); } BarSpudGraph.addBarTo(Objects.first(parentTyped.dataTable().Rows), bar); needsNewBar = false; parentTyped.Invalidate(); }); }
void addChart(Researcher researcher, Collectible collectible, ItemsControl charts) { var simulator = researcher.simulator; var bars = collectible.barsMaybe(); if (bars == null) { return; } var chartAdded = false; runOnGuiThread(() => { var chart = new BarSpudGraph(bars, collectible, this); Objects.each(researcher.plots.get(collectible), chart.add); chart.add(Objects.accept(researcher.positions, collectible.collects), Objects.accept(researcher.trades, collectible.collects), simulator); chart.addEquity(simulator); chart.moveBarsToBack(); chart.resetYAxis(); var symbolPane = new DockablePane(); charts.Items.Add(new DockableContent { Title = title(collectible.name), Content = symbolPane }); symbolPane.Items.Add(new DockableContent { Title = title(collectible.name + " Plots"), Content = new WindowsFormsHost { Child = chart } }); var dataGrid = new QDataTableGrid(); var dataTable = chart.makeDataTable(); dataGrid.populateFromDataTable(dataTable); symbolPane.Items.Add(new DockableContent { Title = title(collectible.name + " Data"), Content = dataGrid }); chartAdded = true; }); Objects.wait(400, 50, () => chartAdded); }