My primary data chart is 15 min, and from the code you can see i have 3 more Bars in progress settings. One of which is 15 min as well, to match the On bars update. When taking the SMA of the same time (1 min bars) the values printed from OnBarUpdate() can be different from those within BarsInProgress = 15 minute. Which seems to make no sense if the primary bar (whats on your chart) is the same as adding a new periodtype of 15 minutes.
One thing i have noticed: Printing the close within the OnBarUpdate() Method on a 15 minute chart will print every minute but sometimes with multiple print statements of the exact time (in this case 1 min increments) with the same price. - This is what i am guessing is throwing off the SMA values. Although when there is no tick data present as 1 minute is the smallest increment, how is this happening?
protected override void Initialize()
{
Add(PeriodType.Minute,15); //1
Add(PeriodType.Minute,5); //2
Add(PeriodType.Minute,1); //3
}//initialize
protected override void OnBarUpdate() // primary bar series - Timing is linked to the Smallest Period Value Initialized. In This Case == 1 minute.
{
PrintWithTimeStamp("OBU-----" + Close.ToString());
PrintWithTimeStamp("SMA of OBU-----" + SMA(Close,5)[0]);
// Prints Close value every minute
// bip == 0??? Which would be the primary bar series which in this case is set to a 15 min bar on the chart.
// Why When running this segment of code within onbarupdate() does the Close Print multiple times with the same time and the same price on historical data?
// cont from above...it appears this will cause calculations to be off if figuring SMA's etc...As it will overly smooth out the price depending on how many times the
// same price is evaluated within 1 time period, i.e. 1 minute yet 3 print statements at time 3:00 with 3 exact prices of 700.1 ??? /* */
if (BarsInProgress ==2) // 5 minute bars
{
PrintWithTimeStamp("BIP==2---------" + Close.ToString()); //
// prints trailing stop value every 5 minutes,
// bip==1 = period type 1 , secondary bar series
}
if ( BarsInProgress ==3) // 1 minute bars
{
PrintWithTimeStamp("SMA of BIP 3-----" + SMA(Close,5)[0]);
PrintWithTimeStamp("BIP==3---------" + Close.ToString());
// prints trailing stop value every 1 minutes,
// bip ==2 = period type 2, third bar series.
}
if (BarsInProgress == 1) // 15 min bars, Added because onbarupdate syncs up with the smallest period type specified within the initialize() method.
{
PrintWithTimeStamp("BIP==1-------------" + Close.ToString());
PrintWithTimeStamp("SMA of BIP 1-----" + SMA(Close,5)[0]);
// prints trailing stop value every 15 minutes
// bip==3, period type2, fourth bar series
}
/****************************************** If Method is located within a barsinprogress {} then it will only update per the bars in progress index setting*********************************/
// Notes. Calculations onbarupdate() with multitimeframes may not be accurate, run calculations within intended BIP Time window. BIP=DataSeries.
} // onbarupdate
2/3/2011 3:15:00 PM SMA of OBU-----796.840000000003
2/3/2011 3:15:00 PM BIP==2---------796.2
2/3/2011 3:15:00 PM OBU-----796.2
2/3/2011 3:15:00 PM SMA of OBU-----796.400000000009
2/3/2011 3:15:00 PM SMA of BIP 3-----796.400000000009
2/3/2011 3:15:00 PM BIP==3---------796.2

Comment