SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Tue Nov 30, 2021 2:13 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Tue Oct 16, 2007 9:36 am 
Offline

Joined: Fri Feb 02, 2007 8:00 pm
Posts: 61
Location: USA
I'm trying to draw quote info such as the highest Quote.Ask for each bar on each bar-size/chart in a strategy (without knowing the number or size of bars ahead of time).

I built a 1 second BarSeries to hold the Open, High, Low, Close for quoteAsk. I used BarSeries.Compress in OnBar to make the larger barseries for the charts. An SMA of length 1 is drawn on the charts. It's very slow.

I'm having a hard time synchronizing my quotes-barseries to the charts. Values from the larger barsize chart keep appearing on the smaller barsize chart. There's no way to issue separate Draw commands for each bar size so I'm kind of stuck.

How do you create a BarSeries that can be used to draw on each bar-size chart in the strategy? I must be doing something wrong because it shouldn't be this hard.

[Update]
The issue where data from the larger bar size was showing up on the smaller bar size chart went away. It must have been the way I was adding values to the series.

The main issue still remaining is that the Draw command draws on the chart of every barsize. There seems to be no way to restrict the Draw to a single barsize chart. This is a big limitation for me.

Please confirm if this is a bug or a design limitation. Any chance this will be improved soon?

Charting and analyzing multiple timeframes would also be easier if the number of bar sizes was available in OnStrategyStart.

Why doesn't each bar size have it's own instance of strategy class? I find myself working extra hard to keep any variables or series separate by barsize.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 17, 2007 1:28 am 
Offline

Joined: Fri Feb 02, 2007 8:00 pm
Posts: 61
Location: USA
Here's my code to draw the high ask and low bid on the charts. The problem is the 1 minute lines are useless on the 6 second chart and the 6 second lines are useless on the 1 minute chart. How do you get it to draw just one set of lines per chart at the right bar size?



Code:

//Add 6 second bars and 1 minute bars to the strategy

using System;
using System.Drawing;
using OpenQuant.API;
using OpenQuant.API.Indicators;

public class MyStrategy : Strategy
{
   BarSeries bidBars;
   BarSeries askBars;
    TimeSeries chartBid6;
    TimeSeries chartAsk6;
    TimeSeries chartBid60;
    TimeSeries chartAsk60;
   
   public override void OnStrategyStart()
   {

        askBars = new BarSeries("askBars");
        bidBars = new BarSeries("bidBars");

        chartAsk6 = new TimeSeries("askBars", Color.Cyan);
        chartBid6 = new TimeSeries("bidBars", Color.Pink);
        chartAsk60 = new TimeSeries("askBars", Color.Cyan);
        chartBid60 = new TimeSeries("bidBars", Color.Pink);

      Draw(chartAsk6, 0);
      Draw(chartBid6, 0);
      Draw(chartAsk60, 0);
      Draw(chartBid60, 0);

    }
    public override void OnBar(Bar bar)
    {
        if (askBars.Count > 0)
        {
            if (bar.Size == 6)
            {
                chartAsk6.Add(bar.BeginTime, askBars.HighestHigh(bar.BeginTime, bar.EndTime));
            }
            else
            {
                chartAsk60.Add(bar.BeginTime, askBars.HighestHigh(bar.BeginTime, bar.EndTime));
            }
        }
        if (bidBars.Count > 0)
        {
            if (bar.Size == 6)
            {
                chartBid6.Add(bar.BeginTime, bidBars.LowestLow(bar.BeginTime, bar.EndTime));
            }
            else
            {
                chartBid60.Add(bar.BeginTime, bidBars.LowestLow(bar.BeginTime, bar.EndTime));
            }

        }
    }
   public override void OnQuote(Quote quote)
   {
        if (Bars.Count > 0)
        {
            BuildTimeBars(1, quote.DateTime, quote.Ask, quote.AskSize, askBars);
            BuildTimeBars(1, quote.DateTime, quote.Bid, quote.BidSize, bidBars);
        }
    }


    public static void BuildTimeBars(long barSize, DateTime time, double price, long volume, BarSeries bars)
    {
        if (barSize < 1)
        {
            throw (new Exception("barSize must be > 0"));
        }

        DateTime nextBarEndTime = new DateTime();
        if (bars.Count > 0)
        {   //calculate the end time of the last bar
            long lastBarEndInSeconds = bars.Last.EndTime.Ticks / 10000000;
            long nextBarEndInSeconds = ((lastBarEndInSeconds + barSize) / barSize) * barSize;
            nextBarEndTime = nextBarEndTime.AddSeconds(nextBarEndInSeconds);
        }
        if (time < nextBarEndTime)
        {    //merge bar into previous bar
            bars.Add(BarType.Time, barSize, bars.Last.BeginTime, time,
                bars.Last.Open,
                Math.Max(bars.Last.High, price),
                Math.Min(bars.Last.Low, price),
                price,
                volume,
                0);  //Replaces the last bar
        }
        else
        {
            //Add new bar
            bars.Add(BarType.Time, barSize,
                time, time,
                price, price, price, price,
                volume, 0);
            //OnBarOpen(bars.Last);
        }
    }



}


Attachments:
1min.jpg
1min.jpg [ 56.98 KiB | Viewed 3863 times ]
6sec.jpg
6sec.jpg [ 50.94 KiB | Viewed 3863 times ]
Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 17, 2007 4:37 pm 
Offline

Joined: Wed Oct 08, 2003 1:06 pm
Posts: 833
Hi,

It is not possible to do it in the current version. It is a useful feature so we will add in a next version.

Regards,
Sergey.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 17, 2007 5:23 pm 
Offline

Joined: Fri Feb 02, 2007 8:00 pm
Posts: 61
Location: USA
Baraz Sergey wrote:
Hi,

It is not possible to do it in the current version. It is a useful feature so we will add in a next version.

Regards,
Sergey.


Thanks Sergey.

Please see my feature request if you havn't already seen it:
http://www.smartquant.com/forums/viewtopic.php?t=5996

-Jeremy


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC + 3 hours


Who is online

Users browsing this forum: No registered users and 3 guests


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:  
cron
Powered by phpBB® Forum Software © phpBB Group