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(); }); }; }
void withGuiRow(ROW row, Action <DataGridRow> onGuiRow) { if (!rows.ContainsKey(row)) { LogC.verbose(() => "discarding action on original thread for non-showing " + row); return; } QControl.runOnGuiThread(this, () => { DataGridRow guiRow; rows.TryGetValue(row, out guiRow); if (guiRow != null) { onGuiRow(guiRow); } else { LogC.verbose(() => "discarding action on gui thread for non showing" + row); } }); }
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(); }); }