SmartQuant Discussion

Automated Quantitative Strategy Development, SmartQuant Product Discussion and Technical Support Forums
It is currently Sun May 28, 2017 11:38 am

All times are UTC + 3 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: Wed May 09, 2012 8:45 pm 
Offline

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

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 http://www.smartquant.com/forums/viewtopic.php?f=44&t=7185&hilit=+hma+indicator+)

Below is the code for my 15-second bars:

Code:
      DateTime startOfTrdDay = new DateTime(2012, 5, 9, 12,0,0);
      Instrument baseInstrHist = InstrumentManager.Instruments["@ESM12"];
      TradeSeries histTrdSeries = GetHistoricalTrades("NFIQFeed", baseInstrHist, startOfTrdDay,
         DateTime.UtcNow.AddSeconds(-1));
      
      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:

Code:
/// <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;
                         
         diffSeries.Add(
            Input.GetDateTime(index),
            value1 - value2,
            value1 - value2,
            value1 - value2,
            value1 - value2,
            0,
            0);
             
         if (diffWma.Count == 0)
            return double.NaN;
         
         hma = diffWma.Last;
       
         return hma;
      }
      else
         return double.NaN;
   }
}



My next line of code following the barseries assignment is:

Code:
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.


Top
 Profile  
 
PostPosted: Wed May 09, 2012 11:16 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6750
Is this about Visual Quant ?


Top
 Profile  
 
PostPosted: Wed May 09, 2012 11:22 pm 
Offline

Joined: Tue Mar 15, 2011 7:15 pm
Posts: 80
no. i am adding a user HMA indicator to a strategy file.


Top
 Profile  
 
PostPosted: Wed May 09, 2012 11:35 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6750
This is VisualQuant -> New Features forum ;)


Top
 Profile  
 
PostPosted: Wed May 09, 2012 11:38 pm 
Offline

Joined: Tue Mar 15, 2011 7:15 pm
Posts: 80
i realize that. i posted this in error and subsequently reposted to the Strategy Programming forum.


Top
 Profile  
 
PostPosted: Wed May 09, 2012 11:42 pm 
Offline

Joined: Tue Mar 15, 2011 7:15 pm
Posts: 80
Could you please advise on this question either here or in the Strategy Programming forum post? Thank you.


Top
 Profile  
 
PostPosted: Wed May 09, 2012 11:42 pm 
Offline

Joined: Tue Aug 05, 2003 3:43 pm
Posts: 6750
ok, Sergey will look into this issue tomorrow in the office.


Top
 Profile  
 
PostPosted: Wed May 09, 2012 11:44 pm 
Offline

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


Top
 Profile  
 
PostPosted: Thu May 10, 2012 10:33 am 
Offline

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

Please try to move ths following line to the end of the constructor code:
Code:
 this.Name = "HMA, Period = " + period;


It seems that the indicator is recalculated when you set the Name property. So it is better to do it after you initialize your indicator completely.

We will think if we need to keep this behaviour in next versions.

Regards,
Sergey.


Top
 Profile  
 
PostPosted: Thu May 10, 2012 5:45 pm 
Offline

Joined: Tue Mar 15, 2011 7:15 pm
Posts: 80
Removing the line corrected the problem. Thank you.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 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