SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Tue Jul 14, 2020 7:57 pm

All times are UTC + 3 hours

Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: TimeSeriesViewer?
PostPosted: Wed Aug 31, 2016 8:18 am 

Joined: Tue Feb 23, 2016 10:43 pm
Posts: 16
2014 does not have series.Draw() method anymore. there is timeseriesviewer class but not sure how to use this

This following code bring up the canvas but no time series was printed.

TimeSeries series = new TimeSeries("My Series");
            series.Add(new DateTime(2001, 01, 01), 10);
            series.Add(new DateTime(2002, 01, 01), 40);
            series.Add(new DateTime(2003, 01, 01), 20);
            series.Add(new DateTime(2004, 01, 01), 50);
            series.Add(new DateTime(2005, 01, 01), 30);
            series.Add(new DateTime(2006, 01, 01), 70);

            Canvas canvas = new Canvas("Canvas demo", 600, 400);
            Pad pad =;

            TimeSeriesViewer tsv = new TimeSeriesViewer();
            tsv.Pad = pad;

            //series.Draw();     //series does not have Draw method anymore in 2014??


 Post subject: Re: TimeSeriesViewer?
PostPosted: Wed Aug 31, 2016 11:00 am 

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6817

you can try to get a hint from this code sample below


I’ve modified Bollinger Bands backtest scenario to run it for two instruments and plot results on a canvas. You would need to add references to SmartQuant.Charting and SmartQuant.Chart.Viewers dlls to run it in OQ.

Actually this scenario will hang in Applicatio.DoEvents infinite loop but you can “stop” it by clicking on the stop button in OQ toolbar.

using System;
using System.Drawing;
using System.Windows.Forms;

using SmartQuant;
using SmartQuant.ChartViewers;

using SmartQuant.Charting;

namespace OpenQuant
public class Backtest : Scenario
private long barSize = 300;

public Backtest(Framework framework)
: base(framework)

public override void Run()
int n = 2;

Instrument[] instruments = new Instrument[n];
TimeSeries[] equity = new TimeSeries[n];
Color[] colors = {Color.Red, Color.Blue};

instruments[0] = InstrumentManager.Instruments["AAPL"];
instruments[1] = InstrumentManager.Instruments["MSFT"];

DateTime dateTime1 = new DateTime(2013, 01, 01);
DateTime dateTime2 = new DateTime(2013, 12, 31);

for(int i=0;i<n;i++)
strategy = new MyStrategy(framework, "BollingerBands");


DataSimulator.DateTime1 = dateTime1;
DataSimulator.DateTime2 = dateTime2;

BarFactory.Add(instruments[i], BarType.Time, barSize);


equity[i] = strategy.Portfolio.Performance.EquitySeries;


Canvas canvas = new Canvas();

canvas.Pad.RegisterViewer(new TimeSeriesViewer());

canvas.Pad.SetRangeX(equity[0].FirstDateTime, equity[0].LastDateTime);

canvas.Pad.AxisBottom.Type = EAxisType.DateTime;
canvas.Pad.AxisBottom.LabelFormat = "d";

Viewer viewer;

for(int i=0;i<n;i++)
viewer = canvas.Pad.Add(equity[i]);

viewer.Set(equity[i], "Color", colors[i]);


 Post subject: Re: TimeSeriesViewer?
PostPosted: Wed Aug 31, 2016 11:27 pm 

Joined: Tue Feb 23, 2016 10:43 pm
Posts: 16
Thank you.

This is super helpful. I wouldn't figure this out by myself. The charting parts aren't updated in the API docs. If you have time, can you update the API doc so that I can learn more thoroughly about charting/viewer classes.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 3 hours

Who is online

Users browsing this forum: No registered users and 1 guest

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group