SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Wed Oct 28, 2020 11:30 am

All times are UTC + 3 hours

Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Wed May 09, 2012 8:50 pm 

Joined: Tue Mar 15, 2011 7:15 pm
Posts: 80

I am trying to preload historical data from a provider into a barseries to which live bars will be added as they come in. Note that I will have multiple time frames and want to use >1 bar series. For my 15-second series, I want to pass the barseries to the HMA user indicator (as posted by Sergey in

Below is the code for my 15-second bars:

DateTime startOfTrdDay = new DateTime(2012, 5, 9, 12,0,0);
      Instrument baseInstrHist = InstrumentManager.Instruments["@ESM12"];
      TradeSeries histTrdSeries = GetHistoricalTrades("NFIQFeed", baseInstrHist, startOfTrdDay,
      BarSeries histBarSeries = DataManager.CompressBars(histTrdSeries, BarType.Time, 15);
      BarSeries bs_15sec = GetBars(myInstr, BarType.Time, 15);
      foreach (Bar bar in histBarSeries) bs_15sec.Add(bar);

This is working without problem.

Sergey's HMA indicator code is:

/// <summary>
   /// HMA conversion.
   /// </summary>
public class HMA: UserIndicator
   private int period;
   private BarData barData;
   WMA wma1;
   WMA wma2;
   WMA diffWma;
   BarSeries diffSeries;
   public int Period
      get { return period; }
      set { period = value; }
   public BarData BarData
      get { return barData; }
      set { barData = value; }
   public HMA(ISeries series, int period, BarData barData) : base (series)
      this.period = period;
      this.barData = barData;
      this.Name = "HMA, Period = " + period;
      wma1 = new WMA((BarSeries)Input, (int)(period / 2) * 2);
      wma2 = new WMA((BarSeries)Input , period);
      diffSeries = new BarSeries();
      diffWma = new WMA(diffSeries, (int)Math.Sqrt(period));
   public HMA(ISeries series, int period)
      : this(series, period, BarData.Close)
   public override double Calculate(int index)
      if (wma1.Count == 0 || wma2.Count == 0)
         return double.NaN;
      double hma = double.NaN;       
      if (index > period - 1)
         double value1 = 2 * wma1.Last;
         double value2 = wma2.Last;
            value1 - value2,
            value1 - value2,
            value1 - value2,
            value1 - value2,
         if (diffWma.Count == 0)
            return double.NaN;
         hma = diffWma.Last;
         return hma;
         return double.NaN;

My next line of code following the barseries assignment is:

userInd.HMA hma = new userInd.HMA(bs_15sec, 4, BarData.Close);

When the code enters this line, it correctly enter the constructor: HMA(ISeries series, int period, BarData barData). However, it executes the first 3 lines of code and then exits (entering into the Calculate method). I do not know why this is occurring and cannot resolve it.

If I call the HMA indicator on a barseries to which I have not appended historical bars (i.e. using GetBars methods without including any preloaded bars), the HMA code works properly and without incident. I gather from this that I must be doing something incorrect in my assignment of historical bars to the barseries. Can someone please advise what mistake I am making?

Thank you.

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

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